https://gcc.gnu.org/g:12ba140ee93adc56a3426f0c6c05f4d6c6a3d08e

commit r13-8967-g12ba140ee93adc56a3426f0c6c05f4d6c6a3d08e
Author: Patrick Palka <ppa...@redhat.com>
Date:   Fri Aug 9 09:03:14 2024 -0400

    c++: local class memfn synth from uneval context [PR113063]
    
    This is essentially a narrow backport of r14-6724-gfced59166f95e9 that
    instead 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
    trigger is a <compare> change backport r13-7739-gd919309679334a).
    
            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.
    
    Reviewed-by: Jason Merrill <ja...@redhat.com>

Diff:
---
 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(+)

diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 9fd5567e97fd..09ea6d732dfc 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 000000000000..37a183de0f5b
--- /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 000000000000..68388a680b20
--- /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 m = 0;
+    auto operator<=>(const X&) const = default;
+  };
+  X x;
+  static_assert(noexcept(x <=> x));
+  x <=> x;
+}

Reply via email to