public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] c++: Constant expression parsing and parameters.
@ 2020-08-22 21:29 Giuliano Belinassi
0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:29 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a23219ff59b0be9eb72e8323850a9e8c0bc31c62
commit a23219ff59b0be9eb72e8323850a9e8c0bc31c62
Author: Jason Merrill <jason@redhat.com>
Date: Thu May 21 10:27:11 2020 -0400
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.
Diff:
---
gcc/cp/constexpr.c | 8 ++++++++
gcc/cp/cp-tree.h | 1 +
gcc/cp/decl.c | 2 +-
gcc/cp/parser.c | 4 ++--
4 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index c1ab9288f72..98c974e657f 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
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 07c16144c98..db125a3a1db 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7939,6 +7939,7 @@ extern tree constexpr_fn_retval (tree);
extern tree ensure_literal_type_for_constexpr_object (tree);
extern bool potential_constant_expression (tree);
extern bool is_constant_expression (tree);
+extern bool is_rvalue_constant_expression (tree);
extern bool is_nondependent_constant_expression (tree);
extern bool is_nondependent_static_init_expression (tree);
extern bool is_static_init_expression (tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a389579ee52..6d1c08e064a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7612,7 +7612,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
init = boolean_true_node;
}
else if (init
- && init_const_expr_p
+ && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
&& !TYPE_REF_P (type)
&& decl_maybe_constant_var_p (decl)
&& !(dep_init = value_dependent_init_p (init)))
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index a8082d39aca..6a0ef4d76ee 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10184,10 +10184,10 @@ cp_parser_constant_expression (cp_parser* parser,
if (TREE_TYPE (expression)
&& TREE_CODE (TREE_TYPE (expression)) == ARRAY_TYPE)
decay = build_address (expression);
- bool is_const = potential_rvalue_constant_expression (decay);
+ bool is_const = is_rvalue_constant_expression (decay);
parser->non_integral_constant_expression_p = !is_const;
if (!is_const && !allow_non_constant_p)
- require_potential_rvalue_constant_expression (decay);
+ require_rvalue_constant_expression (decay);
}
if (allow_non_constant_p)
*non_constant_p = parser->non_integral_constant_expression_p;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-22 21:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:29 [gcc/devel/autopar_devel] c++: Constant expression parsing and parameters Giuliano Belinassi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).