on-internet
← Community

Can a defaulted comparison operator have parameters of types `const A` and `A`?

Stack Overflow ·

In the following program, a friend equality operator is defaulted with one parameter declared const A and the other A: struct A { friend bool operator==(const A, A) = default; }; GCC and EDG accept it, but Clang and MSVC reject it. Clang's error: error: invalid parameter type for defaulted equality comparison operator; found 'const A', expected 'const A &' or 'A' MSVC's error: error C2610: 'bool operator ==(const A,A)': is not a special member function or comparison operator which can be defaulted note: default arguments or varargs are not allowed Online demo: https://godbolt.org/z/zTdYEjPob W

Comments

Sign in or sign up to comment and upvote.

No comments yet.