This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] PR 50837


Hi,

I'm trying to make progress on this issue which I find rather embarrassing in terms of simple uses of constexpr functions and static_assert. We reject, at instantiation time:

template<class T>
struct z
{
static constexpr bool test_constexpr()
{
return true;
}

static void test()
{
static_assert(test_constexpr(), "test1"); //error here
}
};

‘static constexpr bool z<T>::test_constexpr() [with T = int]’ cannot appear in a constant-expression

The same snippet is accepted if struct z isn't a template. The error comes from:

/* Only certain kinds of names are allowed in constant
expression. Enumerators and template parameters have already
been handled above. */
if (! error_operand_p (decl)
&& integral_constant_expression_p
&& ! decl_constant_var_p (decl)
&& ! builtin_valid_in_constant_expr_p (decl))
{
if (!allow_non_integral_constant_expression_p)
{
error ("%qD cannot appear in a constant-expression", decl);
return error_mark_node;
}

in finish_id_expression, which is called by tsubst_copy_and_build, case IDENTIFIER_NODE, with a false allow_non_integral_constant_expression_p. What is puzzling me, is that, in the non-template struct z case, finish_id_expression is called from cp_parser_primary_expression with a true allow_non_integral_constant_expression_p and the error doesn't occur. As a matter of fact, naively hacking the tsubst_copy_and_build call to also pass true, mostly passes the testsuite, modulo a diagnostic regression of template/nontype13.C.

Jason, basing on these few debugging notes, can you already see in which direction I should further investigate?

Thanks,
Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]