Skip to content

C++23 default comparisons is incorrectly rejected #104413

Closed
@marco-antognini-sonarsource

Description

Sibling issue of #104414.

According to https://eel.is/c++draft/class.compare#default-1, the following C++23 program should compile.

struct A { 
  bool operator ==(this A, A) = default;
};

int main() {
  return A{}.operator ==(A{});
}

but Clang (18.1 and trunk) reports

<source>:2:20: error: defaulted member equality comparison operator must be const-qualified
    2 |   bool operator ==(this A, A) = default;
      |                    ^
      |                         const
<source>:2:8: error: invalid parameter type for defaulted equality comparison operator; found 'A', expected 'const A &'
    2 |   bool operator ==(this A, A) = default;
      |        ^                   ~
2 errors generated.

FWIW, GCC accepts it.

Reproducible at https://godbolt.org/z/qM57nxz5d

See also https://stackoverflow.com/a/78808748/24103368 from @brevzin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions