Hi,
in this error recovery regression we ICE when we end-up in an
inconsistent state after meaningful diagnostic emitted by
ensure_literal_type_for_constexpr_object and then some redundant /
slightly misleading one emitted by check_static_variable_definition. I
think we can just return early from cp_finish_decl and solve the primary
and the secondary issue. I also checked that clang too doesn't emit an
error for line #28 of constexpr-diag3.C, after the hard error for co1
itself at line #27. Tested x86_64-linux.
Thanks, Paolo.
//////////////////////
/cp
2018-01-61 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/81054
* decl.c (cp_finish_decl): Early return when the
ensure_literal_type_for_constexpr_object fails.
/testsuite
2018-01-61 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/81054
* g++.dg/cpp0x/constexpr-ice19.C: New.
* g++.dg/cpp0x/constexpr-diag3.C: Adjust.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 256728)
+++ cp/decl.c (working copy)
@@ -6811,7 +6811,11 @@ cp_finish_decl (tree decl, tree init, bool init_co
}
if (!ensure_literal_type_for_constexpr_object (decl))
- DECL_DECLARED_CONSTEXPR_P (decl) = 0;
+ {
+ DECL_DECLARED_CONSTEXPR_P (decl) = 0;
+ TREE_TYPE (decl) = error_mark_node;
+ return;
+ }
if (VAR_P (decl)
&& DECL_CLASS_SCOPE_P (decl)
Index: testsuite/g++.dg/cpp0x/constexpr-diag3.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-diag3.C (revision 256728)
+++ testsuite/g++.dg/cpp0x/constexpr-diag3.C (working copy)
@@ -25,7 +25,7 @@ struct complex // { dg-message "no
.constexpr.
};
constexpr complex co1(0, 1); // { dg-error "not literal" }
-constexpr double dd2 = co1.real(); // { dg-error "|in .constexpr. expansion of
" }
+constexpr double dd2 = co1.real();
// --------------------
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" }
+};