Hi,
today I have been analyzing this issue - not terribly urgent, it's a
regression but the ICE is on *invalid*. It happens only in C++11 mode
and the test is the following, very simple:
template<int> struct A {};
template<typename> void foo()
{
A<int(x)> a;
}
This is what happens. First we build anyway a CAST_EXPR even if the
argument in this case is obviously error_mark_node, because in general,
per the comment in cp_parser_parenthesized_expression_list, this leads
to better diagnostics.
Then, in C++98 mode the CAST_EXPR is folded by fold_non_dependent_expr
(called by cp_parser_template_argument immediately after
cp_parser_constant_expression), because in that mode, the
potential_constant_expression call which gates the tsubst_copy_and_build
call returns true unconditionally. Instead, in C++11 mode it recurses
until error_mark_node and returns false. This means that the CAST_EXPR
is not simplified and can reach cxx_eval_constant_expression which
doesn't know how to handle it and ICEs.
Thus, what to do? Definitely adding CAST_EXPR to the switch works, but
I'm wondering if we could do something else... but doesn't seem easy to
me given the above. For example, I suppose changing
potential_constant_expression to return true for error_mark_node would
be catastrophic, even if error_mark_node is definitely constant ;)
Seriously, ideas?
Thanks!
Paolo.