public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-10138] c++: defaulted op== for incomplete class [PR107291]
@ 2024-02-06 3:41 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2024-02-06 3:41 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:db8d5b0ad074344559b3201e567c1e47e65d0bdd
commit r12-10138-gdb8d5b0ad074344559b3201e567c1e47e65d0bdd
Author: Jason Merrill <jason@redhat.com>
Date: Mon Feb 5 19:56:45 2024 -0500
c++: defaulted op== for incomplete class [PR107291]
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)
Diff:
---
gcc/cp/method.cc | 6 +++++-
gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C | 5 +++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 903ee666ef39..be9406e33039 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -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
index 000000000000..039bfac387c3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C
@@ -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" }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-06 3:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 3:41 [gcc r12-10138] c++: defaulted op== for incomplete class [PR107291] Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).