diff mbox series

[C++] PR 81054 ("[7/8 Regression] ICE with volatile variable in constexpr function")

Message ID 7c9190ae-8852-2bfa-99b4-f3dcee89198d@oracle.com
State New
Headers show
Series [C++] PR 81054 ("[7/8 Regression] ICE with volatile variable in constexpr function") | expand

Commit Message

Paolo Carlini Jan. 16, 2018, 10:37 a.m. UTC
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.carlini@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.carlini@oracle.com>

	PR c++/81054
	* g++.dg/cpp0x/constexpr-ice19.C: New.
	* g++.dg/cpp0x/constexpr-diag3.C: Adjust.

Comments

Paolo Carlini Jan. 16, 2018, 1:18 p.m. UTC | #1
.. nevermind, this requires more work: my simple patchlet would cause a 
few regression in the libstdc++-v3 testsuite (the assert at the 
beginning of finish_expr_stmt triggers)

Paolo.
diff mbox series

Patch

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" }
+};