Hi again,
thus I figured out what was badly wrong in my first try: I misread
ensure_literal_type_for_constexpr_object and missed that it can return
NULL_TREE without emitting an hard error. Thus my first try even caused
miscompilations :( Anyway, when DECL_DECLARED_CONSTEXPR_P is true we are
safe and indeed we want to clear it as matter of error recovery. Then,
in this safe case the only change in the below is returning early, thus
avoiding any internal inconsistencies later and also the redundant /
misleading diagnostic which I already mentioned. Testing on x86_64-linux
is still in progress - in libstdc++ - but I separately checked that all
the regressions are gone.
Thanks! Paolo.
/////////////////////
/cp
2018-01-16 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/81054
* decl.c (cp_finish_decl): Early return when
ensure_literal_type_for_constexpr_object returns NULL_TREE
and DECL_DECLARED_CONSTEXPR_P is true.
/testsuite
2018-01-16 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/81054
* g++.dg/cpp0x/constexpr-ice19.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 256753)
+++ cp/decl.c (working copy)
@@ -6810,8 +6810,12 @@ cp_finish_decl (tree decl, tree init, bool init_co
cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
}
- if (!ensure_literal_type_for_constexpr_object (decl))
- DECL_DECLARED_CONSTEXPR_P (decl) = 0;
+ if (!ensure_literal_type_for_constexpr_object (decl)
+ && DECL_DECLARED_CONSTEXPR_P (decl))
+ {
+ DECL_DECLARED_CONSTEXPR_P (decl) = 0;
+ return;
+ }
if (VAR_P (decl)
&& DECL_CLASS_SCOPE_P (decl)
Index: testsuite/g++.dg/cpp0x/constexpr-ice19.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-ice19.C (nonexistent)
+++ testsuite/g++.dg/cpp0x/constexpr-ice19.C (working copy)
@@ -0,0 +1,13 @@
+// PR c++/81054
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+ volatile int i;
+ constexpr A() : i() {}
+};
+
+struct B
+{
+ static constexpr A a {}; // { dg-error "not literal" }
+};