aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-01-19 00:42:18 +0100
committerJakub Jelinek <jakub@redhat.com>2022-01-19 00:42:18 +0100
commit1a5145f1e3adf8b2ba4ad416a5ddef59a1e34d48 (patch)
tree88783f175903044a0c9e8e63b3c382d9c2a6d498 /gcc/cp/constexpr.cc
parentfdd6d85bd75df9a97659220373b5c1e8b3019e26 (diff)
downloadgcc-1a5145f1e3adf8b2ba4ad416a5ddef59a1e34d48.zip
gcc-1a5145f1e3adf8b2ba4ad416a5ddef59a1e34d48.tar.gz
gcc-1a5145f1e3adf8b2ba4ad416a5ddef59a1e34d48.tar.bz2
c++: Fix handling of temporaries with consteval ctors and non-trivial dtors [PR104055]
The following testcase is miscompiled. We see the constructor is immediate, in build_over_call we trigger: if (obj_arg && is_dummy_object (obj_arg)) { call = build_cplus_new (DECL_CONTEXT (fndecl), call, complain); obj_arg = NULL_TREE; } which makes call a TARGET_EXPR with the dtor in TARGET_EXPR_CLEANUP, but then call cxx_constant_value on it. In cxx_eval_outermost_constant_expr it triggers the: else if (TREE_CODE (t) != CONSTRUCTOR) { r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup); TREE_CONSTANT (r) = true; } which wraps the CONSTRUCTOR r into a new TARGET_EXPR, but one without dtors (I think we need e.g. the TREE_CONSTANT for the callers), and finally build_over_call uses that. The following patch fixes that by using get_target_expr instead of get_target_expr_sfinae + TREE_CONSTANT (r) = true if t is a TARGET_EXPR with non-NULL TARGET_EXPR_CLEANUP. 2022-01-19 Jakub Jelinek <jakub@redhat.com> PR c++/104055 * constexpr.cc (cxx_eval_outermost_constant_expr): If t is a TARGET_EXPR with TARGET_EXPR_CLEANUP, use get_target_expr rather than get_target_expr_sfinae with tf_no_cleanup, and don't set TREE_CONSTANT. * g++.dg/cpp2a/consteval27.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r--gcc/cp/constexpr.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index f73496f..dcc1674 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -7821,7 +7821,11 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
if (TREE_CODE (t) == TARGET_EXPR
&& TARGET_EXPR_INITIAL (t) == r)
return t;
- else if (TREE_CODE (t) != CONSTRUCTOR)
+ else if (TREE_CODE (t) == CONSTRUCTOR)
+ ;
+ else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t))
+ r = get_target_expr (r);
+ else
{
r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup);
TREE_CONSTANT (r) = true;