On 2/5/24 21:55, Marek Polacek wrote:
On Mon, Feb 05, 2024 at 09:29:08PM -0500, Jason Merrill wrote:
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
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.
---
gcc/cp/method.cc | 6 +++++-
gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C | 5 +++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-eq17.C
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index d49e5a565e8..3b8dc75d198 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -1228,7 +1228,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;
Can I push this?
gcc/cp/ChangeLog:
* method.cc (early_check_defaulted_comparison): Add
auto_diagnostic_group.
Oops, yes, please. In the future, adding missing auto_diagnostic_group
can be pushed as obvious.
---
gcc/cp/method.cc | 1 +
1 file changed, 1 insertion(+)
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 3b8dc75d198..957496d3e18 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -1229,6 +1229,7 @@ early_check_defaulted_comparison (tree fn)
ctx = TYPE_MAIN_VARIANT (parmtype);
if (!is_friend (ctx, fn))
{
+ auto_diagnostic_group d;
error_at (loc, "defaulted %qD is not a friend of %qT", fn, ctx);
inform (location_of (ctx), "declared here");
ok = false;
base-commit: c5d34912ad576be1ef19be92f7eabde54b9089eb