Hi,
in C++11 mode after erroring out for an undeclared name we can easily
end up calling cxx_eval_constant_expression on a CAST_EXPR etc, which
has error_mark_node as argument.
The latter trees are currently completely unhandled by
cxx_eval_constant_expression, thus in order to avoid such ICEs on
invalid it seems safe setting *non_constant_p = true and returning back
t, as we do when t itself is error_mark_node, and asserting errorcount.
The resulting diagnostics is pretty terse.
Tested x86_64-linux.
Thanks,
Paolo.
////////////////
/cp
2012-01-13 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51225
* semantics.c (cxx_eval_constant_expression): Handle CAST_EXPR,
CONST_CAST_EXPR, STATIC_CAST_EXPR, REINTERPRET_CAST_EXPR,
IMPLICIT_CONV_EXPR.
/testsuite
2012-01-13 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51225
* g++.dg/cpp0x/pr51225.C: New.
Index: testsuite/g++.dg/cpp0x/pr51225.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr51225.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr51225.C (revision 0)
@@ -0,0 +1,14 @@
+// PR c++/51225
+// { dg-options "-std=c++0x" }
+
+template<int> struct A {};
+
+template<typename> void foo()
+{
+ A<int(x)> a; // { dg-error "not declared|invalid type" }
+}
+
+template<typename> struct bar
+{
+ static constexpr A<1> a = A<1>(x); // { dg-error "not declared" }
+};
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 183153)
+++ cp/semantics.c (working copy)
@@ -7769,6 +7769,15 @@ cxx_eval_constant_expression (const constexpr_call
used, and they can't do anything with it, so just return it. */
return t;
+ case CAST_EXPR:
+ case CONST_CAST_EXPR:
+ case STATIC_CAST_EXPR:
+ case REINTERPRET_CAST_EXPR:
+ case IMPLICIT_CONV_EXPR:
+ gcc_assert (errorcount);
+ *non_constant_p = true;
+ return t;
+
case LAMBDA_EXPR:
case PREINCREMENT_EXPR:
case POSTINCREMENT_EXPR: