From a23219ff59b0be9eb72e8323850a9e8c0bc31c62 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 21 May 2020 10:27:11 -0400 Subject: c++: Constant expression parsing and parameters. The difference between a "potential" constant-expression and a regular constant-expression is the treatment of parameters; in a constexpr function, a parameter is potentially constant when evaluating a call to that function, but it is not constant during parsing of the function. cp_parser_constant_expression should check the latter rather than the former. gcc/cp/ChangeLog: * cp-tree.h (is_rvalue_constant_expression): Declare. * constexpr.c (is_rvalue_constant_expression): New. * parser.c (cp_parser_constant_expression): Use it. * decl.c (cp_finish_decl): Try to treat a constexpr initializer in a template as constant. --- gcc/cp/constexpr.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gcc/cp/constexpr.c') diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index c1ab928..98c974e 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -8359,6 +8359,14 @@ is_constant_expression (tree t) return potential_constant_expression_1 (t, false, true, true, tf_none); } +/* As above, but expect an rvalue. */ + +bool +is_rvalue_constant_expression (tree t) +{ + return potential_constant_expression_1 (t, true, true, true, tf_none); +} + /* Like above, but complain about non-constant expressions. */ bool -- cgit v1.1