Skip to content

[class.compare.default] Clarify whether a defaulted comparison operator that is a friend can be redeclared in a class #702

Open
@Sirraide

Description

@Sirraide

Full name of submitter (unless configured in github; will be published with the issue): Ambrose T.

[class.compare.default]p1 states:

A definition of a comparison operator as defaulted that appears in a class shall be the first declaration of that function

Does this apply to the following friend declarations?

struct b {
  friend bool operator==(b, b);
  friend bool operator==(b, b) = default;
};

I’m mainly asking because Clang and EDG diagnose this as an error whereas GCC and MSVC accept this code. At the same time, it’s already invalid for members to be redeclared in a class, so by that logic the fact that this sentence is even there would indicate that it should (also) apply to non-members, i.e. friends (if that is the intended reading, maybe adding a note/example for this would help?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions