aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-03-24 11:42:31 -0400
committerPatrick Palka <ppalka@redhat.com>2022-03-24 11:42:31 -0400
commit647537adefb34041cc2d44585252fd765cc0daae (patch)
tree5ed08216df295c81f1bd701921175c1afce8ee4e /gcc/cp/constexpr.cc
parentfb488cba571539b6644e8f99f1dd997cdb4c82c1 (diff)
downloadgcc-647537adefb34041cc2d44585252fd765cc0daae.zip
gcc-647537adefb34041cc2d44585252fd765cc0daae.tar.gz
gcc-647537adefb34041cc2d44585252fd765cc0daae.tar.bz2
c++: missing SFINAE for non-constant consteval calls [PR104620]
Here we weren't respecting SFINAE when evaluating a call to a consteval function, which caused us to reject the new testcase below. This patch fixes this by making build_over_call use the SFINAE-friendly version of cxx_constant_value. This change causes us to no longer diagnose ahead of time a couple of non-constant non-dependent consteval calls in consteval-if2.C with -fchecking=2. These errors were apparently coming from the call to fold_non_dependent_expr in build_non_dependent_expr (for the RHS of the +=) despite complain=tf_none being passed. Now that build_over_call respects the value of complain during constant evaluation of a consteval call, the errors are gone. That the errors are also gone without -fchecking=2 is a regression caused by r12-7264-gc19f317a78c0e4 and is the subject of PR104620. As described in comment #5, I think it's basically an accident that we were diagnosing these two calls correctly before r12-7264, so perhaps we can live without these errors for GCC 12. Thus this patch just XFAILs the two tests. PR c++/104620 gcc/cp/ChangeLog: * call.cc (build_over_call): Use cxx_constant_value_sfinae instead of cxx_constant_value to evaluate a consteval call. * constexpr.cc (cxx_constant_value_sfinae): Add decl parameter and pass it to cxx_eval_outermost_constant_expr. * cp-tree.h (cxx_constant_value_sfinae): Add decl parameter. * pt.cc (fold_targs_r): Pass NULL_TREE as decl parameter to cxx_constant_value_sfinae. gcc/testsuite/ChangeLog: * g++.dg/cpp23/consteval-if2.C: XFAIL two dg-error tests where the argument to the non-constant non-dependent consteval call is wrapped by NON_DEPENDENT_EXPR. * g++.dg/cpp2a/consteval30.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r--gcc/cp/constexpr.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index ce4ef8e..778680b 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -7960,10 +7960,10 @@ cxx_constant_value (tree t, tree decl)
/* As above, but respect SFINAE. */
tree
-cxx_constant_value_sfinae (tree t, tsubst_flags_t complain)
+cxx_constant_value_sfinae (tree t, tree decl, tsubst_flags_t complain)
{
bool sfinae = !(complain & tf_error);
- tree r = cxx_eval_outermost_constant_expr (t, sfinae, true, true);
+ tree r = cxx_eval_outermost_constant_expr (t, sfinae, true, true, false, decl);
if (sfinae && !TREE_CONSTANT (r))
r = error_mark_node;
return r;