]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: defaulted op== for incomplete class [PR107291]
authorJason Merrill <jason@redhat.com>
Tue, 6 Feb 2024 00:56:45 +0000 (19:56 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 6 Feb 2024 03:41:29 +0000 (22:41 -0500)
After complaining about lack of friendship, we should not try to go on and
define the defaulted comparison operator anyway.

PR c++/107291

gcc/cp/ChangeLog:

* method.cc (early_check_defaulted_comparison): Fail if not friend.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/spaceship-eq17.C: New test.

(cherry picked from commit c5d34912ad576be1ef19be92f7eabde54b9089eb)

gcc/cp/method.cc
gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C [new file with mode: 0644]

index 903ee666ef3966ef5be691d6a573acf4da666109..be9406e3303933ef42915ae111652e859d86726c 100644 (file)
@@ -1222,7 +1222,11 @@ early_check_defaulted_comparison (tree fn)
          /* Defaulted outside the class body.  */
          ctx = TYPE_MAIN_VARIANT (parmtype);
          if (!is_friend (ctx, fn))
-           error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx);
+           {
+             error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx);
+             inform (location_of (ctx), "declared here");
+             ok = false;
+           }
        }
       else if (!same_type_ignoring_top_level_qualifiers_p (parmtype, ctx))
        saw_bad = true;
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C
new file mode 100644 (file)
index 0000000..039bfac
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/107291
+// { dg-do compile { target c++20 } }
+
+struct S4;                                        // { dg-message "declared here" }
+bool operator==(S4 const &, S4 const &) = default; // { dg-error "not a friend" }