On 3/7/19 2:29 PM, Jakub Jelinek wrote:
Hi!
The last testcase in the patch diagnoses invalid constexpr in the
ptr case, but doesn't for arr.
The array is constexpr, so we do:
value = fold_non_dependent_expr (value);
if (DECL_DECLARED_CONSTEXPR_P (decl)
|| (DECL_IN_AGGR_P (decl)
&& DECL_INITIALIZED_IN_CLASS_P (decl)))
{
/* Diagnose a non-constant initializer for constexpr variable or
non-inline in-class-initialized static data member. */
if (!require_constant_expression (value))
value = error_mark_node;
else if (processing_template_decl)
/* In a template we might not have done the necessary
transformations to make value actually constant,
e.g. extend_ref_init_temps. */
value = maybe_constant_init (value, decl, true);
else
value = cxx_constant_init (value, decl);
}
but require_constant_expression returned true even when there are
REINTERPRET_CAST_Ps in the CONSTRUCTOR, and then cxx_constant_init
doesn't reject it, because:
case CONSTRUCTOR:
if (TREE_CONSTANT (t) && reduced_constant_expression_p (t))
{
/* Don't re-process a constant CONSTRUCTOR, but do fold it to
VECTOR_CST if applicable. */
verify_constructor_flags (t);
if (TREE_CONSTANT (t))
return fold (t);
}
r = cxx_eval_bare_aggregate (ctx, t, lval,
non_constant_p, overflow_p);
break;
and reduced_constant_expression_p is true on it, so we never try to evaluate
it.
The following patch changes potential_constant_expression_1 to reject the
REINTERPRET_CAST_P, not really sure if that is the best way though.
That seems right to me. The patch is OK.
Jason