Comments
Patch
@@ -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);
new file mode 100644
@@ -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" }
+};
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.