This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC] PR 50837
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>
- Date: Wed, 09 Nov 2011 23:45:17 +0100
- Subject: [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.