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

[Clang][Sema] Fix template name lookup for operator= #90999

Merged
merged 2 commits into from
May 3, 2024
Merged
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
11 changes: 4 additions & 7 deletions clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,8 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
for (Scope *PreS = S; PreS; PreS = PreS->getParent())
if (DeclContext *DC = PreS->getEntity()) {
if (DC->isDependentContext() && isa<CXXRecordDecl>(DC) &&
Name.getCXXOverloadedOperator() == OO_Equal) {
Name.getCXXOverloadedOperator() == OO_Equal &&
!R.isTemplateNameLookup()) {
R.setNotFoundInCurrentInstantiation();
return false;
}
Expand Down Expand Up @@ -2471,10 +2472,8 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
}
} QL(LookupCtx);

bool TemplateNameLookup = R.isTemplateNameLookup();
CXXRecordDecl *LookupRec = dyn_cast<CXXRecordDecl>(LookupCtx);
// FIXME: Per [temp.dep.general]p2, an unqualified name is also dependent
// if it's a dependent conversion-function-id or operator= where the current
// class is a templated entity. This should be handled in LookupName.
if (!InUnqualifiedLookup && !R.isForRedeclaration()) {
// C++23 [temp.dep.type]p5:
// A qualified name is dependent if
Expand All @@ -2488,7 +2487,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
(Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
Name.getCXXNameType()->isDependentType()) ||
(Name.getCXXOverloadedOperator() == OO_Equal && LookupRec &&
LookupRec->isDependentContext())) {
LookupRec->isDependentContext() && !TemplateNameLookup)) {
R.setNotFoundInCurrentInstantiation();
return false;
}
Expand Down Expand Up @@ -2584,8 +2583,6 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
return true;
};

bool TemplateNameLookup = R.isTemplateNameLookup();

// Determine whether two sets of members contain the same members, as
// required by C++ [class.member.lookup]p6.
auto HasSameDeclarations = [&](DeclContext::lookup_iterator A,
Expand Down
18 changes: 18 additions & 0 deletions clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,24 @@ namespace N3 {
this->A::operator=(*this);
}
};

template<typename T>
struct C {
template<typename U>
void operator=(int);

void not_instantiated() {
operator=<int>(0);
C::operator=<int>(0);
this->operator=<int>(0);
this->C::operator=<int>(0);

operator=(*this);
C::operator=(*this);
this->operator=(*this);
this->C::operator=(*this);
}
};
} // namespace N3

namespace N4 {
Expand Down
Loading