diff mbox

C++ PATCH for c++/48212 (ICE after error on invalid constant initializer)

Message ID 4D9392E0.8090808@redhat.com
State New
Headers show

Commit Message

Jason Merrill March 30, 2011, 8:30 p.m. UTC
non_const_var_error wasn't considering the possibility that the variable 
is unsuitable for a constant expression because its initializer is 
erroneous.

Tested x86_64-pc-linux-gnu, applied to trunk and 4.6.
commit 95a1f4128e0d9fb5480f0ae83240a6d339cf012e
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 30 16:05:52 2011 -0400

    	PR c++/48212
    	* semantics.c (non_const_var_error): Just return if DECL_INITIAL
    	is error_mark_node.
diff mbox

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 3300c3f..e444d91 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -6753,6 +6753,9 @@  non_const_var_error (tree r)
   tree type = TREE_TYPE (r);
   error ("the value of %qD is not usable in a constant "
 	 "expression", r);
+  /* Avoid error cascade.  */
+  if (DECL_INITIAL (r) == error_mark_node)
+    return;
   if (DECL_DECLARED_CONSTEXPR_P (r))
     inform (DECL_SOURCE_LOCATION (r),
 	    "%qD used in its own initializer", r);
diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/error-recovery1.C b/gcc/testsuite/g++.dg/cpp0x/regress/error-recovery1.C
new file mode 100644
index 0000000..2094d3e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/regress/error-recovery1.C
@@ -0,0 +1,9 @@ 
+// PR c++/48212
+// { dg-options -std=c++0x }
+
+template < bool > void
+foo ()
+{
+  const bool b =;		// { dg-error "" }
+  foo < b > ();			// { dg-error "constant expression" }
+};