* [pushed] c++: defaulted op== for incomplete class [PR107291]
@ 2024-02-06 2:29 Jason Merrill
2024-02-06 2:55 ` Marek Polacek
0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2024-02-06 2:29 UTC (permalink / raw)
To: gcc-patches
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;
+ }
}
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 00000000000..039bfac387c
--- /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" }
base-commit: d49780c08aade447953bfe4e877d386f5757f165
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pushed] c++: defaulted op== for incomplete class [PR107291]
2024-02-06 2:29 [pushed] c++: defaulted op== for incomplete class [PR107291] Jason Merrill
@ 2024-02-06 2:55 ` Marek Polacek
2024-02-06 4:31 ` Jason Merrill
0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2024-02-06 2:55 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
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.
---
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
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pushed] c++: defaulted op== for incomplete class [PR107291]
2024-02-06 2:55 ` Marek Polacek
@ 2024-02-06 4:31 ` Jason Merrill
0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2024-02-06 4:31 UTC (permalink / raw)
To: Marek Polacek; +Cc: gcc-patches
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-06 4:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 2:29 [pushed] c++: defaulted op== for incomplete class [PR107291] Jason Merrill
2024-02-06 2:55 ` Marek Polacek
2024-02-06 4:31 ` 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).