On 8/8/24 2:38 PM, Patrick Palka wrote:
Bootstrap and regtest in progress, does this look OK for the 13 branch
if successful?
OK.
-- >8 --
This is essentially a narrow backport of r14-6724-gfced59166f95e9
that uses cp_evaluated instead of maybe_push_to_top_level to clear
cp_unevaluated_operand within synthesize_method, which turns out is
sufficient to also fix the 13.3 regression PR116289 (whose immediate
cause is the libstdc++ change r13-7739-gd919309679334a triggering a
consteval bug).
PR c++/113063
PR c++/116289
gcc/cp/ChangeLog:
* method.cc (synthesize_method): Use cp_evaluated.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/spaceship-synth16.C: New test.
* g++.dg/cpp2a/spaceship-synth16a.C: New test.
---
gcc/cp/method.cc | 1 +
gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C | 13 +++++++++++++
gcc/testsuite/g++.dg/cpp2a/spaceship-synth16a.C | 16 ++++++++++++++++
3 files changed, 30 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C
create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-synth16a.C
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 9fd5567e97f..09ea6d732df 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -1797,6 +1797,7 @@ synthesize_method (tree fndecl)
it now. */
push_deferring_access_checks (dk_no_deferred);
+ cp_evaluated ev;
if (! context)
push_to_top_level ();
else if (nested)
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C
b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C
new file mode 100644
index 00000000000..37a183de0f5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C
@@ -0,0 +1,13 @@
+// PR c++/113063
+// { dg-do link { target c++20 } }
+
+#include <compare>
+
+int main() {
+ struct X {
+ auto operator<=>(const X&) const = default;
+ };
+ X x;
+ static_assert(noexcept(x <=> x));
+ x <=> x;
+}
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16a.C
b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16a.C
new file mode 100644
index 00000000000..fb14d487e23
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth16a.C
@@ -0,0 +1,16 @@
+// PR c++/116289
+// PR c++/113063
+// { dg-do link { target c++20 } }
+// A version of spaceship-synth16.C where the local class isn't empty.
+
+#include <compare>
+
+int main() {
+ struct X {
+ int x = 0;
+ auto operator<=>(const X&) const = default;
+ };
+ X x;
+ static_assert(noexcept(x <=> x));
+ x <=> x;
+}