diff mbox series

[pushed] c++: op== defaulted outside class [PR110084]

Message ID 20240202185540.19758-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: op== defaulted outside class [PR110084] | expand

Commit Message

Jason Merrill Feb. 2, 2024, 6:55 p.m. UTC
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

defaulted_late_check is for checks that need to happen after the class is
complete; we shouldn't call it sooner.

	PR c++/110084

gcc/cp/ChangeLog:

	* pt.cc (tsubst_function_decl): Only check a function defaulted
	outside the class if the class is complete.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/spaceship-synth-neg3.C: Check error message.
	* g++.dg/cpp2a/spaceship-eq16.C: New test.
---
 gcc/cp/pt.cc                                      |  1 +
 gcc/testsuite/g++.dg/cpp2a/spaceship-eq16.C       | 11 +++++++++++
 gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg3.C |  2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-eq16.C


base-commit: 1c3cfb5a95dcc7f797ec2815690a6291878580c4
diff mbox series

Patch

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 9d30a271713..355e9609bd3 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -14812,6 +14812,7 @@  tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
   if (DECL_SECTION_NAME (t))
     set_decl_section_name (r, t);
   if (DECL_DEFAULTED_OUTSIDE_CLASS_P (r)
+      && COMPLETE_TYPE_P (DECL_CONTEXT (r))
       && !processing_template_decl)
     defaulted_late_check (r);
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq16.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq16.C
new file mode 100644
index 00000000000..e5538ea9890
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq16.C
@@ -0,0 +1,11 @@ 
+// PR c++/110084
+// { dg-do compile { target c++20 } }
+
+template <class T>
+class BadTuple {
+  constexpr bool operator==(const BadTuple&) const;
+};
+template<class T>
+constexpr bool BadTuple<T>::operator==(const BadTuple<T>&) const = default;
+
+BadTuple<int> a;
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg3.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg3.C
index a4d8b32922f..aaa0264e7b3 100644
--- a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg3.C
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg3.C
@@ -5,7 +5,7 @@  template<auto V>
 struct A {};
 
 struct B {
-    constexpr auto operator<=>(const B&) const = default; // { dg-error "" }
+    constexpr auto operator<=>(const B&) const = default; // { dg-error "strong_ordering" }
     int value;
 };