Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8262,6 +8262,8 @@ class DefaultedComparisonAnalyzer
/// resolution [...]
CandidateSet.exclude(FD);

auto &Fns = this->Fns;
Copy link
Collaborator

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.

Copy link
Member

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, Fns is an lvalue equivalent to this->Fns; after this line, Fns is ... an lvalue that aliases this->Fns?


if (Args[0]->getType()->isOverloadableType())
S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
else
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @zygoloid comment:

#97087 (comment)

here it looks like the fix is the pass Scope instead of nullptr here:

if (CheckExplicitlyDefaultedComparison(nullptr, FD, DefKind.asComparison()))

Did you try this?

S = getScopeForContext(FD->getLexicalDeclContext());

if (S) {
UnresolvedSet<32> Operators;
lookupOperatorsForDefaultedComparison(*this, S, Operators,
Expand Down
17 changes: 17 additions & 0 deletions clang/test/SemaCXX/default-op-notusing-namespace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
Copy link
Collaborator

Choose a reason for hiding this comment

The 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'}}
13 changes: 13 additions & 0 deletions clang/test/SemaCXX/default-op-using-namespace.cpp
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline needed here.