| Issue |
243420
|
| Summary |
Defaulted comparison operator with `const` by-value parameters is rejected
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Fedr
|
Clang rejects defaulted comparison operators whose by-value parameters are declared with top-level `const`, but only in some places:
```c++
struct A {
friend bool operator==(const A, const A) = default; // #1 error in Clang
};
struct B {
friend bool operator==(B, B);
};
bool operator==(const B, const B) = default; // #2 ok
struct C {
bool operator==(this C, C);
};
bool C::operator==(this const C, const C) = default; // #3 error in Clang
```
```
<source>:2:17: error: invalid parameter type for defaulted equality comparison operator; found 'const A', expected 'const A &' or 'A'
<source>:13:9: error: invalid parameter type for defaulted equality comparison operator; found 'const C', expected 'const C &'
```
Top-level cv-qualifiers are not part of the function type ([dcl.fct]/5), and Clang itself accepts #2. GCC, MSVC and EDG accept all three. Online demo: https://godbolt.org/z/8cE4Md3jq
#1 is rejected since Clang 10, #3 since Clang 20 (Clang 18 and 19 reject it as "out-of-line definition does not match any declaration").
Related: #101160, #104414
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs