public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94141] New: c++20 rewritten operator== recursive call mixing friend and external operators for template class
@ 2020-03-11 13:51 glisse at gcc dot gnu.org
2020-04-05 14:00 ` [Bug c++/94141] " glisse at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-03-11 13:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94141
Bug ID: 94141
Summary: c++20 rewritten operator== recursive call mixing
friend and external operators for template class
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: glisse at gcc dot gnu.org
Target Milestone: ---
(reduced from a user of boost/operators.hpp)
template <typename> class A;
template <typename T> bool operator==(const A<T>&, int) { return false; }
template <typename> class A {
friend bool operator==(int y, const A& x) { return x == y; }
};
int main(){
A<short> q;
q==3;
3==q;
}
$ g++ -std=c++2a a.c -Wall && ./a.out
a.c: In instantiation of 'bool operator==(int, const A<short int>&)':
a.c:10:6: required from here
a.c:5:56: warning: in C++20 this comparison calls the current function
recursively with reversed arguments
5 | friend bool operator==(int y, const A& x) { return x == y; }
| ~~^~~~
zsh: segmentation fault ./a.out
If I make both operators friends, or move both outside, gcc is happy, but in
this mixed case, it doesn't seem to want to use the first operator== and
prefers the rewritten second operator==. Of course removing the second
operator== completely also works.
Clang is fine with this version of the code.
I have trouble parsing the standard wording, but IIRC one of the principles
when adding <=> was that explicitly written functions should have priority over
new, invented ones.
Bug 93807 is the closest I could find.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94141] c++20 rewritten operator== recursive call mixing friend and external operators for template class
2020-03-11 13:51 [Bug c++/94141] New: c++20 rewritten operator== recursive call mixing friend and external operators for template class glisse at gcc dot gnu.org
@ 2020-04-05 14:00 ` glisse at gcc dot gnu.org
2020-04-05 16:48 ` glisse at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-04-05 14:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94141
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
It looks like clang-10+ also generates an infinite loop on this code. Does the
standard really give priority to some implicit function over a user-defined one
that is an exact match?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94141] c++20 rewritten operator== recursive call mixing friend and external operators for template class
2020-03-11 13:51 [Bug c++/94141] New: c++20 rewritten operator== recursive call mixing friend and external operators for template class glisse at gcc dot gnu.org
2020-04-05 14:00 ` [Bug c++/94141] " glisse at gcc dot gnu.org
@ 2020-04-05 16:48 ` glisse at gcc dot gnu.org
2020-05-21 9:12 ` glisse at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-04-05 16:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94141
--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
Ah, maybe the friend function is not quite a template, so the generated swapped
function is not a template either, and thus it has priority over a template if
both are exact matches?
This is going to break a number of users of boost/operators.hpp, and possibly
other mixins using a similar technique.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94141] c++20 rewritten operator== recursive call mixing friend and external operators for template class
2020-03-11 13:51 [Bug c++/94141] New: c++20 rewritten operator== recursive call mixing friend and external operators for template class glisse at gcc dot gnu.org
2020-04-05 14:00 ` [Bug c++/94141] " glisse at gcc dot gnu.org
2020-04-05 16:48 ` glisse at gcc dot gnu.org
@ 2020-05-21 9:12 ` glisse at gcc dot gnu.org
2020-05-21 9:53 ` Laurent.Rineau__gcc at normalesup dot org
2021-08-04 17:46 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-05-21 9:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94141
Marc Glisse <glisse at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-05-21
Status|UNCONFIRMED |SUSPENDED
Ever confirmed|0 |1
--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
It seems that this is as currently specified in C++20, but that some people are
going to try and change the rules to avoid breaking code like this.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94141] c++20 rewritten operator== recursive call mixing friend and external operators for template class
2020-03-11 13:51 [Bug c++/94141] New: c++20 rewritten operator== recursive call mixing friend and external operators for template class glisse at gcc dot gnu.org
` (2 preceding siblings ...)
2020-05-21 9:12 ` glisse at gcc dot gnu.org
@ 2020-05-21 9:53 ` Laurent.Rineau__gcc at normalesup dot org
2021-08-04 17:46 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: Laurent.Rineau__gcc at normalesup dot org @ 2020-05-21 9:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94141
--- Comment #4 from Laurent Rineau <Laurent.Rineau__gcc at normalesup dot org> ---
(In reply to Marc Glisse from comment #3)
> It seems that this is as currently specified in C++20, but that some people
> are going to try and change the rules to avoid breaking code like this.
Do you have reference to the discussion on the subject?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94141] c++20 rewritten operator== recursive call mixing friend and external operators for template class
2020-03-11 13:51 [Bug c++/94141] New: c++20 rewritten operator== recursive call mixing friend and external operators for template class glisse at gcc dot gnu.org
` (3 preceding siblings ...)
2020-05-21 9:53 ` Laurent.Rineau__gcc at normalesup dot org
@ 2021-08-04 17:46 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04 17:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94141
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2020-05-21 00:00:00 |2021-8-4
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #1)
> It looks like clang-10+ also generates an infinite loop on this code.
clang 12+ now does not produce an infinite loop.
GCC trunk still does though.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-08-04 17:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 13:51 [Bug c++/94141] New: c++20 rewritten operator== recursive call mixing friend and external operators for template class glisse at gcc dot gnu.org
2020-04-05 14:00 ` [Bug c++/94141] " glisse at gcc dot gnu.org
2020-04-05 16:48 ` glisse at gcc dot gnu.org
2020-05-21 9:12 ` glisse at gcc dot gnu.org
2020-05-21 9:53 ` Laurent.Rineau__gcc at normalesup dot org
2021-08-04 17:46 ` pinskia at gcc dot gnu.org
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).