diff options
author | Marek Polacek <polacek@redhat.com> | 2023-08-31 20:11:50 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2023-09-19 09:24:44 -0400 |
commit | 6851e3423c2b5ec6516efa0677745d25c905e079 (patch) | |
tree | 72c6c8bc7a321e6f9f6090b9db82fea35931e707 /gcc/testsuite/g++.dg/cpp23 | |
parent | f25960b03834712f312d46fed9a021df36f89f22 (diff) | |
download | gcc-6851e3423c2b5ec6516efa0677745d25c905e079.zip gcc-6851e3423c2b5ec6516efa0677745d25c905e079.tar.gz gcc-6851e3423c2b5ec6516efa0677745d25c905e079.tar.bz2 |
c++: Move consteval folding to cp_fold_r
In the review of P2564:
<https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628747.html>
it turned out that in order to correctly handle an example in the paper,
we should stop doing immediate evaluation in build_over_call and
bot_replace, and instead do it in cp_fold_r. This patch does that.
Another benefit is that this is a pretty significant simplification, at
least in my opinion. Also, this fixes the c++/110997 ICE (but the test
doesn't compile yet).
The main drawback seems to be that cp_fold_r doesn't process
uninstantiated templates. We still have to handle things like
"false ? foo () : 1". To that end, I've added cp_fold_immediate, called
on dead branches in cxx_eval_conditional_expression.
You'll see that I've reintroduced ADDR_EXPR_DENOTES_CALL_P here. This
is to detect
*(&foo)) ()
(s.*&S::foo) ()
which were deemed ill-formed.
gcc/cp/ChangeLog:
* call.cc (build_over_call): Set ADDR_EXPR_DENOTES_CALL_P. Don't handle
immediate_invocation_p here.
* constexpr.cc (cxx_eval_call_expression): Use mce_true for
DECL_IMMEDIATE_FUNCTION_P.
(cxx_eval_conditional_expression): Call cp_fold_immediate.
* cp-gimplify.cc (enum fold_flags): Add ff_fold_immediate.
(maybe_replace_decl): Make static.
(cp_fold_r): Expand immediate invocations.
(cp_fold_immediate_r): New.
(cp_fold_immediate): New.
* cp-tree.h (ADDR_EXPR_DENOTES_CALL_P): Define.
(cp_fold_immediate): Declare.
* tree.cc (bot_replace): Don't handle immediate invocations here.
libstdc++-v3/ChangeLog:
* testsuite/20_util/allocator/105975.cc: Add dg-error.
gcc/testsuite/ChangeLog:
* g++.dg/cpp23/consteval-if2.C: Add xfail.
* g++.dg/cpp2a/consteval-memfn1.C: Adjust.
* g++.dg/cpp2a/consteval11.C: Remove dg-message.
* g++.dg/cpp2a/consteval3.C: Remove dg-message and dg-error.
* g++.dg/cpp2a/consteval9.C: Remove dg-message.
* g++.dg/cpp2a/consteval32.C: New test.
* g++.dg/cpp2a/consteval33.C: New test.
* g++.dg/cpp2a/consteval34.C: New test.
* g++.dg/cpp2a/consteval35.C: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp23')
-rw-r--r-- | gcc/testsuite/g++.dg/cpp23/consteval-if2.C | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/testsuite/g++.dg/cpp23/consteval-if2.C b/gcc/testsuite/g++.dg/cpp23/consteval-if2.C index d1845da..b2c5472 100644 --- a/gcc/testsuite/g++.dg/cpp23/consteval-if2.C +++ b/gcc/testsuite/g++.dg/cpp23/consteval-if2.C @@ -58,6 +58,7 @@ baz (int x) return r; } +// This function is not instantiated so NDR. template <typename T> constexpr int qux (int x) @@ -65,7 +66,7 @@ qux (int x) int r = 0; if not consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } } { - r += foo (x); // { dg-error "'x' is not a constant expression" } + r += foo (x); // { dg-error "'x' is not a constant expression" "" { xfail *-*-* } } } else { |