public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/106802] New: Comparators in <functional> don't work with orderings in <compare>
@ 2022-09-01 16:25 aaron at aarongraham dot com
2022-09-01 16:33 ` [Bug libstdc++/106802] " redi at gcc dot gnu.org
2022-09-01 16:34 ` redi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: aaron at aarongraham dot com @ 2022-09-01 16:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106802
Bug ID: 106802
Summary: Comparators in <functional> don't work with orderings
in <compare>
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: aaron at aarongraham dot com
Target Milestone: ---
gcc does not allow this to compile:
std::less<>{}(std::strong_ordering::less, 0);
Even though `std::strong_ordering::less < 0` is perfectly legal and
well-formed.
It will compile this (but clang will not):
std::less<>{}(std::strong_ordering::less, nullptr);
Godbolt link: https://gcc.godbolt.org/z/9ed16KbhP
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/106802] Comparators in <functional> don't work with orderings in <compare>
2022-09-01 16:25 [Bug libstdc++/106802] New: Comparators in <functional> don't work with orderings in <compare> aaron at aarongraham dot com
@ 2022-09-01 16:33 ` redi at gcc dot gnu.org
2022-09-01 16:34 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-01 16:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106802
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Aaron Graham from comment #0)
> Even though `std::strong_ordering::less < 0` is perfectly legal and
> well-formed.
I disagree.
[cmp.categories.pre] p3 says:
The relational and equality operators for the comparison category types are
specified
with an anonymous parameter of unspecified type. This type shall be selected
by the
implementation such that these parameters can accept literal 0 as a
corresponding
argument.
When the comparison happens inside std::less<>::operator() it's not being
compared with a literal 0, it's an lvalue of type int by that point. That isn't
required to work.
The version with nullptr isn't required to work either (so libc++ is correct to
reject that).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/106802] Comparators in <functional> don't work with orderings in <compare>
2022-09-01 16:25 [Bug libstdc++/106802] New: Comparators in <functional> don't work with orderings in <compare> aaron at aarongraham dot com
2022-09-01 16:33 ` [Bug libstdc++/106802] " redi at gcc dot gnu.org
@ 2022-09-01 16:34 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-01 16:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106802
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> When the comparison happens inside std::less<>::operator() it's not being
> compared with a literal 0, it's an lvalue of type int by that point. That
> isn't required to work.
In fact, it isn't just not required to work, it's explicitly undefined. The
rest of p3 is:
"In this context, the behavior of a program that supplies an argument other
than a literal 0 is undefined."
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-01 16:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 16:25 [Bug libstdc++/106802] New: Comparators in <functional> don't work with orderings in <compare> aaron at aarongraham dot com
2022-09-01 16:33 ` [Bug libstdc++/106802] " redi at gcc dot gnu.org
2022-09-01 16:34 ` redi 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).