Description
Bugzilla Link | 51885 |
Version | trunk |
OS | All |
CC | @zygoloid |
Extended Description
https://eel.is/c++draft/class.compare.default#1.sentence-4
A definition of a comparison operator as defaulted that appears in a class shall be the first declaration of that function.
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).
Metadata
Metadata
Assignees
Labels
Type
Projects
Status