Skip to content
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

[C++20] Defaulting a comparison operator on second declaration should be diagnosed #51227

Closed
Quuxplusone opened this issue Sep 17, 2021 · 0 comments
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

Comments

@Quuxplusone
Copy link
Contributor

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

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@EugeneZelenko EugeneZelenko added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Jan 17, 2023
CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Jan 18, 2023
…operators

Comparison operators are not allowed to be defaulted if they were previously declared outside the class.
Pretty low-impact, but it's nice to reject this without a linking error.
Fixes llvm/llvm-project#51227.

Reviewed By: #clang-language-wg, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D141803
veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue Jun 13, 2024
…operators

Comparison operators are not allowed to be defaulted if they were previously declared outside the class.
Pretty low-impact, but it's nice to reject this without a linking error.
Fixes llvm/llvm-project#51227.

Reviewed By: #clang-language-wg, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D141803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
Status: Done
Development

No branches or pull requests

2 participants