Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sirraide opened this issue Apr 16, 2025 · 3 comments

Comments

@Sirraide
Copy link

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

@frederick-vs-ja
Copy link

Does this apply to the following friend declarations?

I believe the answer is clearly yes. The current standard wording looks very clear to me here.

@Endilll
Copy link

Endilll commented Apr 16, 2025

We have rigorous terminology to talk about these things, so we should clarify which scope we're talking about (immediate vs target).

At the same time, it’s already invalid for members to be redeclared in a class

I'm not following. Member functions can be redeclared with e.g. additional default arguments.

@Endilll
Copy link

Endilll commented Apr 16, 2025

The wording in question comes from P2085R0 "Consistent defaulted comparisons" by Davis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants