diff options
author | Jason Merrill <jason@redhat.com> | 2020-05-21 10:27:11 -0400 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-17 13:04:03 -0300 |
commit | a23219ff59b0be9eb72e8323850a9e8c0bc31c62 (patch) | |
tree | 8398a0367d9a924a38aea09d092bb4024c666c74 /gcc/cp/constexpr.c | |
parent | 6603bebbc981520241e8e9835be2b883f8fa7d43 (diff) | |
download | gcc-a23219ff59b0be9eb72e8323850a9e8c0bc31c62.zip gcc-a23219ff59b0be9eb72e8323850a9e8c0bc31c62.tar.gz gcc-a23219ff59b0be9eb72e8323850a9e8c0bc31c62.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r-- | gcc/cp/constexpr.c | 8 |
1 files changed, 8 insertions, 0 deletions
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 |