[C++20] Defaulting a comparison operator on second declaration should be diagnosed #51227
Labels
bugzilla
Issues migrated from bugzilla
c++20
clang:diagnostics
New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Extended Description
https://eel.is/c++draft/class.compare.default#1.sentence-4
IIUC, this sentence is designed to prevent people from default'ing a "non-hidden" friend, like this:
// https://godbolt.org/z/6Tdac86TP
struct B;
bool operator==(const B&, const B&);
struct B {
friend bool operator==(const B&, const B&) = default;
};
int main() { B b; return b == b; }
However, Clang trunk does not diagnose any problem with this code. Instead, Clang quietly pretends that the friend declaration wasn't there at all.
FWIW, GCC also does not diagnose this code, but GCC quietly accepts the friend declaration (so we don't get any undefined symbol for operator== and the program links fine).
The text was updated successfully, but these errors were encountered: