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

Reply via email to