public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116310] New: default equality operator== selects not-const conversion operator
@ 2024-08-09  7:35 fchelnokov at gmail dot com
  2024-08-09  7:56 ` [Bug c++/116310] " pinskia at gcc dot gnu.org
  2024-08-09  8:01 ` [Bug c++/116310] default equality operator== const " pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: fchelnokov at gmail dot com @ 2024-08-09  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116310
           Summary: default equality operator== selects not-const
                    conversion operator
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
struct A {
    int i = 0;
    constexpr operator int() const { return i; }
    constexpr operator int&() { return ++i; }
};

struct B {
    A a;
    bool operator==(const B &) const = default;
};

constexpr bool f() {
    B x;
    return x == x;
}

static_assert( f() ); // fails in GCC
```
is accepted by Clang and MSVC, but fails static assertion in GCC. Online demo:
https://gcc.godbolt.org/z/4xjTnM54M

GCC looks wrong here, because not-const `operator int&` should not be called
from within `B::operator==(const B &) const`.

Original discussion: https://stackoverflow.com/q/78850335/7325599

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

* [Bug c++/116310] default equality operator== selects not-const conversion operator
  2024-08-09  7:35 [Bug c++/116310] New: default equality operator== selects not-const conversion operator fchelnokov at gmail dot com
@ 2024-08-09  7:56 ` pinskia at gcc dot gnu.org
  2024-08-09  8:01 ` [Bug c++/116310] default equality operator== const " pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-08-09  7:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jlame646 at gmail dot com

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 116311 has been marked as a duplicate of this bug. ***

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

* [Bug c++/116310] default equality operator== const selects not-const conversion operator
  2024-08-09  7:35 [Bug c++/116310] New: default equality operator== selects not-const conversion operator fchelnokov at gmail dot com
  2024-08-09  7:56 ` [Bug c++/116310] " pinskia at gcc dot gnu.org
@ 2024-08-09  8:01 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-08-09  8:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|default equality operator== |default equality operator==
                   |selects not-const           |const selects not-const
                   |conversion operator         |conversion operator
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-08-09
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Looks like the const on the default operator== is being ignored
incorrectly.

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

end of thread, other threads:[~2024-08-09  8:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-09  7:35 [Bug c++/116310] New: default equality operator== selects not-const conversion operator fchelnokov at gmail dot com
2024-08-09  7:56 ` [Bug c++/116310] " pinskia at gcc dot gnu.org
2024-08-09  8:01 ` [Bug c++/116310] default equality operator== const " 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).