[llvm-bugs] [Bug 51885] New: [C++20] Defaulting a comparison operator on second declaration should be diagnosed

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 16 18:22:12 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51885

            Bug ID: 51885
           Summary: [C++20] Defaulting a comparison operator on second
                    declaration should be diagnosed
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arthur.j.odwyer at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210917/7c592e26/attachment.html>


More information about the llvm-bugs mailing list