aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaLookup.cpp
diff options
context:
space:
mode:
authorKrystian Stasiowski <sdkrystian@gmail.com>2024-05-09 16:34:40 -0400
committerGitHub <noreply@github.com>2024-05-09 16:34:40 -0400
commit75ebcbf24abb2e5b045ec920bc86f667516e4cc6 (patch)
tree79b7ae1e0bfbb507c08fe01324ae6e7f9f49792e /clang/lib/Sema/SemaLookup.cpp
parentd36b4abb51a9f84d436f184581b15021fdf22114 (diff)
downloadllvm-75ebcbf24abb2e5b045ec920bc86f667516e4cc6.zip
llvm-75ebcbf24abb2e5b045ec920bc86f667516e4cc6.tar.gz
llvm-75ebcbf24abb2e5b045ec920bc86f667516e4cc6.tar.bz2
[Clang][Sema] Revert changes to operator= lookup in templated classes from #91498, #90999, and #90152 (#91620)
This reverts changes in #91498, #90999, and #90152 which make `operator=` dependent whenever the current class is templated.
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r--clang/lib/Sema/SemaLookup.cpp51
1 files changed, 17 insertions, 34 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index e20de33..7251aab 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1267,20 +1267,6 @@ struct FindLocalExternScope {
LookupResult &R;
bool OldFindLocalExtern;
};
-
-/// Returns true if 'operator=' should be treated as a dependent name.
-bool isDependentAssignmentOperator(DeclarationName Name,
- DeclContext *LookupContext) {
- const auto *LookupRecord = dyn_cast_if_present<CXXRecordDecl>(LookupContext);
- // If the lookup context is the current instantiation but we are outside a
- // complete-class context, we will never find the implicitly declared
- // copy/move assignment operators because they are declared at the closing '}'
- // of the class specifier. In such cases, we treat 'operator=' like any other
- // unqualified name because the results of name lookup in the template
- // definition/instantiation context will always be the same.
- return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
- !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();
-}
} // end anonymous namespace
bool Sema::CppLookupName(LookupResult &R, Scope *S) {
@@ -1289,6 +1275,14 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
DeclarationName Name = R.getLookupName();
Sema::LookupNameKind NameKind = R.getLookupKind();
+ // If this is the name of an implicitly-declared special member function,
+ // go through the scope stack to implicitly declare
+ if (isImplicitlyDeclaredMemberFunctionName(Name)) {
+ for (Scope *PreS = S; PreS; PreS = PreS->getParent())
+ if (DeclContext *DC = PreS->getEntity())
+ DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), DC);
+ }
+
// C++23 [temp.dep.general]p2:
// The component name of an unqualified-id is dependent if
// - it is a conversion-function-id whose conversion-type-id
@@ -1301,20 +1295,6 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
return false;
}
- // If this is the name of an implicitly-declared special member function,
- // go through the scope stack to implicitly declare
- if (isImplicitlyDeclaredMemberFunctionName(Name)) {
- for (Scope *PreS = S; PreS; PreS = PreS->getParent())
- if (DeclContext *DC = PreS->getEntity()) {
- if (!R.isTemplateNameLookup() &&
- isDependentAssignmentOperator(Name, DC)) {
- R.setNotFoundInCurrentInstantiation();
- return false;
- }
- DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), DC);
- }
- }
-
// Implicitly declare member functions with the name we're looking for, if in
// fact we are in a scope where it matters.
@@ -2478,6 +2458,10 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
}
} QL(LookupCtx);
+ 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
@@ -2488,16 +2472,13 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
// is operator=, or
// - [...]
if (DeclarationName Name = R.getLookupName();
- (Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
- Name.getCXXNameType()->isDependentType()) ||
- (!R.isTemplateNameLookup() &&
- isDependentAssignmentOperator(Name, LookupCtx))) {
+ Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
+ Name.getCXXNameType()->isDependentType()) {
R.setNotFoundInCurrentInstantiation();
return false;
}
}
- CXXRecordDecl *LookupRec = dyn_cast<CXXRecordDecl>(LookupCtx);
if (LookupDirect(*this, R, LookupCtx)) {
R.resolveKind();
if (LookupRec)
@@ -2588,6 +2569,8 @@ 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,
@@ -2609,7 +2592,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
// template, and if the name is used as a template-name, the
// reference refers to the class template itself and not a
// specialization thereof, and is not ambiguous.
- if (R.isTemplateNameLookup())
+ if (TemplateNameLookup)
if (auto *TD = getAsTemplateNameDecl(ND))
ND = TD;