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

            Bug ID: 101888
           Summary: constexpr default comparison member function
                    disregards the base class
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: myosotis at mail dot ustc.edu.cn
  Target Milestone: ---

This issue only occurs when the default operator== in the derived class is a
constexpr member function (non-constexpr or friend operator== won't trigger
this issue). Whether the operator== function in the base class is constexpr
member or not does not matter. I tested on gcc 11.1 and 11.2, and this issue
persists whatever the optimization level is. Repro:

struct S
{
    int s = 0;
    S(int s) : s(s) {}
    bool operator==(const S&) const = default;
};

struct T : S
{
    T(int s) : S(s) {}
    constexpr bool operator==(const T&) const = default;
};

int main() { return T(0) == T(1); } // Expected 0, but returns 1
  • [Bug c++/101888] New: conste... myosotis at mail dot ustc.edu.cn via Gcc-bugs

Reply via email to