-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[SemaCXX] Fixed defaulted equality operator deletion issue (#97087)[SemaCXX] Fix defaulted equality operator being incorrectly deleted when using namespace (llvm#97087) #166996
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -8262,6 +8262,8 @@ class DefaultedComparisonAnalyzer | |||
| /// resolution [...] | ||||
| CandidateSet.exclude(FD); | ||||
|
|
||||
| auto &Fns = this->Fns; | ||||
|
|
||||
| if (Args[0]->getType()->isOverloadableType()) | ||||
| S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args); | ||||
| else | ||||
|
|
@@ -8913,6 +8915,9 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD, | |||
|
|
||||
| // Perform any unqualified lookups we're going to need to default this | ||||
| // function. | ||||
| if (!S) | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't align right with the comment. This probably needs a comment itself as well.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on @zygoloid comment: here it looks like the fix is the pass Scope instead of llvm-project/clang/lib/Sema/SemaDeclCXX.cpp Line 17990 in 4c63672
Did you try this? |
||||
| S = getScopeForContext(FD->getLexicalDeclContext()); | ||||
|
|
||||
| if (S) { | ||||
| UnresolvedSet<32> Operators; | ||||
| lookupOperatorsForDefaultedComparison(*this, S, Operators, | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two should just be in the same test file, there is no reason to have two separate tests for this. Perhaps find an existing test file for this to live in? |
||
|
|
||
| struct X {}; | ||
| namespace NS { | ||
| bool operator==(X, X); | ||
| } | ||
|
|
||
| struct Y { | ||
| X x; | ||
| friend bool operator==(Y, Y); | ||
| }; | ||
|
|
||
| // There is no `using namespace NS;` here, so this operator== | ||
| // will be implicitly deleted due to missing viable operator== for X. | ||
| bool operator==(Y, Y) = default; | ||
| // expected-error@-1 {{defaulting this equality comparison operator would delete it after its first declaration}} | ||
| // expected-note@9 {{defaulted 'operator==' is implicitly deleted because there is no viable 'operator==' for member 'x'}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s | ||
| // expected-no-diagnostics | ||
|
|
||
| struct X {}; | ||
| namespace NS { | ||
| bool operator==(X, X); | ||
| } | ||
| using namespace NS; | ||
| struct Y { | ||
| X x; | ||
| friend bool operator==(Y, Y); | ||
| }; | ||
| bool operator==(Y, Y) = default; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline needed here. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has 2 problems: First, it is horrifyingly subtle (with the shadowing). Second, you have to use the type here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this even do? Before this line,
Fnsis an lvalue equivalent tothis->Fns; after this line,Fnsis ... an lvalue that aliasesthis->Fns?