Date: Fri, 20 Nov 2026 13:29:49 +0530
The bullet given at class.compare.default
<https://eel.is/c++draft/class.compare.default#1.3> seems to make the
following program invalid. I don't think this is the intention. That is, I
think it should be valid but the current wording makes it invalid. We see
compiler divergence here. Demo <https://godbolt.org/z/8Y8ahM38M>
```
struct A {
friend bool operator==(const A, A) = default; //gcc and edg ok but
clang and msvc no
};
```
Similarly, we have another compiler divergence
<https://godbolt.org/z/4h43Ed3Ef> for the following program:
```
struct A {
friend bool operator==(const A, const A) = default;//clang no but gcc,
msvc and edg ok
};
```
The bullet says:
> either has two parameters of type const C& or* two parameters of type C*,
> where the implicit object parameter (if any) is considered to be the first
> parameter. <https://eel.is/c++draft/class.compare.default#1.sentence-1>
Moreover, there is a note in dcl.fct that says:
> [*Note 3 <https://eel.is/c++draft/dcl.fct#note-3>*: *This
transformation does not affect the types of the parameters.
<https://eel.is/c++draft/dcl.fct#5.sentence-6>* For example, int(*)(const
int p, decltype(p)*) and int(*)(int, const int*) are identical types.
<https://eel.is/c++draft/dcl.fct#5.sentence-7> — *end note*]
This would mean that the above program is invalid. But I think this is an
over/under sight as it makes sense to allow `const A, A` as parameters or
even the case `const A, const A` also makes sense. Should this be a CWG
issue or is this as it should be?
Regards,
Anoop S. Rana
M.Sc Physics
<https://eel.is/c++draft/class.compare.default#1.3> seems to make the
following program invalid. I don't think this is the intention. That is, I
think it should be valid but the current wording makes it invalid. We see
compiler divergence here. Demo <https://godbolt.org/z/8Y8ahM38M>
```
struct A {
friend bool operator==(const A, A) = default; //gcc and edg ok but
clang and msvc no
};
```
Similarly, we have another compiler divergence
<https://godbolt.org/z/4h43Ed3Ef> for the following program:
```
struct A {
friend bool operator==(const A, const A) = default;//clang no but gcc,
msvc and edg ok
};
```
The bullet says:
> either has two parameters of type const C& or* two parameters of type C*,
> where the implicit object parameter (if any) is considered to be the first
> parameter. <https://eel.is/c++draft/class.compare.default#1.sentence-1>
Moreover, there is a note in dcl.fct that says:
> [*Note 3 <https://eel.is/c++draft/dcl.fct#note-3>*: *This
transformation does not affect the types of the parameters.
<https://eel.is/c++draft/dcl.fct#5.sentence-6>* For example, int(*)(const
int p, decltype(p)*) and int(*)(int, const int*) are identical types.
<https://eel.is/c++draft/dcl.fct#5.sentence-7> — *end note*]
This would mean that the above program is invalid. But I think this is an
over/under sight as it makes sense to allow `const A, A` as parameters or
even the case `const A, const A` also makes sense. Should this be a CWG
issue or is this as it should be?
Regards,
Anoop S. Rana
M.Sc Physics
Received on 2026-11-20 08:00:08
