public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++
@ 2024-01-14  9:01 janschultke at googlemail dot com
  2024-01-14  9:03 ` [Bug libstdc++/113386] " janschultke at googlemail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: janschultke at googlemail dot com @ 2024-01-14  9:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

            Bug ID: 113386
           Summary: std::pair comparison operators should be transparent,
                    but are not in libstdc++
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janschultke at googlemail dot com
  Target Milestone: ---

## Code to reproduce

#include <utility>

bool equals(const std::pair<int, int>& a, const std::pair<const int, const
int>& b) {
    return a == b;
}

## Explanation

Clang with -stdlib=libc++ compiles this, as does MSVC. Bug #90203 was
incorrectly closed.

std::pair comparison operators should be transparent, see
https://eel.is/c++draft/pairs.spec The standard requires the signature:

> template<class T1, class T2, class U1, class U2>
> constexpr bool operator==(const pair<T1, T2>& x, const pair<U1, U2>& y);

libstdc++ incorrectly implements this with only two template parameters:

> template<typename _T1, typename _T2>
>   inline _GLIBCXX_CONSTEXPR bool
>   operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
>   { return __x.first == __y.first && __x.second == __y.second; }

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
@ 2024-01-14  9:03 ` janschultke at googlemail dot com
  2024-01-14  9:19 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janschultke at googlemail dot com @ 2024-01-14  9:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #1 from Jan Schultke <janschultke at googlemail dot com> ---
https://godbolt.org/z/9x9n4bGKK

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
  2024-01-14  9:03 ` [Bug libstdc++/113386] " janschultke at googlemail dot com
@ 2024-01-14  9:19 ` pinskia at gcc dot gnu.org
  2024-01-14  9:19 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-14  9:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jan Schultke from comment #0)

> Clang with -stdlib=libc++ compiles this, as does MSVC. Bug #90203 was
> incorrectly closed.

No PR 90203 was not closed incorrectly as that was what the C++ standard said
at the time (and even says still for C++20).


C++ LWG defect report 3865 added this to the standard for C++23:
https://cplusplus.github.io/LWG/lwg-defects.html#3865

GCC just does not implement that yet ...

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
  2024-01-14  9:03 ` [Bug libstdc++/113386] " janschultke at googlemail dot com
  2024-01-14  9:19 ` pinskia at gcc dot gnu.org
@ 2024-01-14  9:19 ` pinskia at gcc dot gnu.org
  2024-01-14  9:24 ` [Bug libstdc++/113386] [C++23] " janschultke at googlemail dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-14  9:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-01-14
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (2 preceding siblings ...)
  2024-01-14  9:19 ` pinskia at gcc dot gnu.org
@ 2024-01-14  9:24 ` janschultke at googlemail dot com
  2024-01-14  9:26 ` janschultke at googlemail dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janschultke at googlemail dot com @ 2024-01-14  9:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #4 from Jan Schultke <janschultke at googlemail dot com> ---
My bad. https://en.cppreference.com/w/cpp/utility/pair/operator_cmp currently
shows

> template< class T1, class T2, class U1, class U2 >
> bool operator==( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
> (until C++14)

I'll fix this page. Never trust cppreference blindly I guess :)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (3 preceding siblings ...)
  2024-01-14  9:24 ` [Bug libstdc++/113386] [C++23] " janschultke at googlemail dot com
@ 2024-01-14  9:26 ` janschultke at googlemail dot com
  2024-01-14  9:28 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janschultke at googlemail dot com @ 2024-01-14  9:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #5 from Jan Schultke <janschultke at googlemail dot com> ---
My bad again, it's a defect report, so cppreference is fine.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (4 preceding siblings ...)
  2024-01-14  9:26 ` janschultke at googlemail dot com
@ 2024-01-14  9:28 ` pinskia at gcc dot gnu.org
  2024-01-14  9:55 ` janschultke at googlemail dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-14  9:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jan Schultke from comment #5)
> My bad again, it's a defect report, so cppreference is fine.

No, the status is C++23 which means it was only voted as part of C++23. as far
as I understand that.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (5 preceding siblings ...)
  2024-01-14  9:28 ` pinskia at gcc dot gnu.org
@ 2024-01-14  9:55 ` janschultke at googlemail dot com
  2024-01-14 12:55 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janschultke at googlemail dot com @ 2024-01-14  9:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #7 from Jan Schultke <janschultke at googlemail dot com> ---
I've noticed that too by now. What confuses me is that both libc++ and MSVC STL
implement it as if it was a DR, so transparent comparisons work even outside
C++23 mode.

Is it just a collective mistake, or what's going on with that? What would be
the right way to implement it in libstdc++ then?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (6 preceding siblings ...)
  2024-01-14  9:55 ` janschultke at googlemail dot com
@ 2024-01-14 12:55 ` redi at gcc dot gnu.org
  2024-01-15 14:46 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-14 12:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We will do it as a DR against all previous standards, as we do for most DRs.

But closing Bug 90203 was still correct at the time.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (7 preceding siblings ...)
  2024-01-14 12:55 ` redi at gcc dot gnu.org
@ 2024-01-15 14:46 ` redi at gcc dot gnu.org
  2024-01-29 20:29 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-15 14:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #8)
> We will do it as a DR against all previous standards, as we do for most DRs.

That should have said "as we do for most issues", sorry. All the major impls
treat most library issues as DRs, applying the fixes to all affected standards
modes.

But as this particular issue changes operator<=> and is motivated by ranges,
I'm tempted to say it's only a DR against C++20, nothing older. If people want
it for older standards, they can contribute the patch to change the pre-C++20
operator!=, operator< etc. overloads.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (8 preceding siblings ...)
  2024-01-15 14:46 ` redi at gcc dot gnu.org
@ 2024-01-29 20:29 ` redi at gcc dot gnu.org
  2024-04-15 18:29 ` cvs-commit at gcc dot gnu.org
  2024-04-15 18:33 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-29 20:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (9 preceding siblings ...)
  2024-01-29 20:29 ` redi at gcc dot gnu.org
@ 2024-04-15 18:29 ` cvs-commit at gcc dot gnu.org
  2024-04-15 18:33 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-15 18:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:2a0c083558b4ac6609692294df7a388cf4468711

commit r14-9979-g2a0c083558b4ac6609692294df7a388cf4468711
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jan 15 14:47:52 2024 +0000

    libstdc++: Heterogeneous std::pair comparisons [PR113386]

    I'm only treating this as a DR for C++20 for now, because it's less work
    and only requires changes to operator== and operator<=>. To do this for
    older standards would require changes to the six relational operators
    used pre-C++20.

    libstdc++-v3/ChangeLog:

            PR libstdc++/113386
            * include/bits/stl_pair.h (operator==, operator<=>): Support
            heterogeneous comparisons, as per LWG 3865.
            * testsuite/20_util/pair/comparison_operators/lwg3865.cc: New
            test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/113386] [C++23] std::pair comparison operators should be transparent, but are not in libstdc++
  2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
                   ` (10 preceding siblings ...)
  2024-04-15 18:29 ` cvs-commit at gcc dot gnu.org
@ 2024-04-15 18:33 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-15 18:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113386

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Done for gcc 14.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-04-15 18:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-14  9:01 [Bug libstdc++/113386] New: std::pair comparison operators should be transparent, but are not in libstdc++ janschultke at googlemail dot com
2024-01-14  9:03 ` [Bug libstdc++/113386] " janschultke at googlemail dot com
2024-01-14  9:19 ` pinskia at gcc dot gnu.org
2024-01-14  9:19 ` pinskia at gcc dot gnu.org
2024-01-14  9:24 ` [Bug libstdc++/113386] [C++23] " janschultke at googlemail dot com
2024-01-14  9:26 ` janschultke at googlemail dot com
2024-01-14  9:28 ` pinskia at gcc dot gnu.org
2024-01-14  9:55 ` janschultke at googlemail dot com
2024-01-14 12:55 ` redi at gcc dot gnu.org
2024-01-15 14:46 ` redi at gcc dot gnu.org
2024-01-29 20:29 ` redi at gcc dot gnu.org
2024-04-15 18:29 ` cvs-commit at gcc dot gnu.org
2024-04-15 18:33 ` 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).