aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-12-19 16:33:55 -0500
committerPatrick Palka <ppalka@redhat.com>2023-12-19 16:33:55 -0500
commitfced59166f95e9922a72392955e4fed095afd47e (patch)
tree9e9bd0d84e6ca93ac374907e719083c246f456c7 /gcc
parent7f26997e6479920c8c6f40894f7d02931f983f82 (diff)
downloadgcc-fced59166f95e9922a72392955e4fed095afd47e.zip
gcc-fced59166f95e9922a72392955e4fed095afd47e.tar.gz
gcc-fced59166f95e9922a72392955e4fed095afd47e.tar.bz2
c++: local class memfn synth from uneval context [PR113063]
Here we first use and therefore synthesize the local class operator<=> from an unevaluated context, which inadvertently affects synthesization by preventing functions used within the definition (such as the copy constructor of std::strong_ordering) from getting marked as odr-used. This patch fixes this by using maybe_push_to_top_level in synthesize_method which ensures cp_unevaluated_operand gets cleared even in the function-local case. PR c++/113063 gcc/cp/ChangeLog: * method.cc (synthesize_method): Use maybe_push_to_top_level and maybe_pop_from_top_level. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-synth16.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/method.cc12
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/spaceship-synth16.C13
2 files changed, 15 insertions, 10 deletions
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 26e6eb7..f645066 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -1770,8 +1770,6 @@ decl_remember_implicit_trigger_p (tree decl)
void
synthesize_method (tree fndecl)
{
- bool nested = (current_function_decl != NULL_TREE);
- tree context = decl_function_context (fndecl);
bool need_body = true;
tree stmt;
location_t save_input_location = input_location;
@@ -1795,10 +1793,7 @@ synthesize_method (tree fndecl)
it now. */
push_deferring_access_checks (dk_no_deferred);
- if (! context)
- push_to_top_level ();
- else if (nested)
- push_function_context ();
+ bool push_to_top = maybe_push_to_top_level (fndecl);
input_location = DECL_SOURCE_LOCATION (fndecl);
@@ -1843,10 +1838,7 @@ synthesize_method (tree fndecl)
input_location = save_input_location;
- if (! context)
- pop_from_top_level ();
- else if (nested)
- pop_function_context ();
+ maybe_pop_from_top_level (push_to_top);
pop_deferring_access_checks ();
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 0000000..37a183d
--- /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;
+}