[clang] [Clang][Sema] Fix template name lookup for operator= (PR #90999)
Krystian Stasiowski via cfe-commits
cfe-commits at lists.llvm.org
Fri May 3 12:34:36 PDT 2024
https://github.com/sdkrystian created https://github.com/llvm/llvm-project/pull/90999
This fixes a bug in #90152 where `operator=` was never looked up in the current instantiation, resulting in `<` never being interpreted as the start of a template argument list.
Since function templates are not copy/move assignment operators, the fix is accomplished by allowing lookup in the current instantiation for `operator=` when looking up a template name.
Still needs tests + release note (which are currently in progress).
>From 0e013635fe6cf665cf8a928e0df2b0c451e60b89 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Fri, 3 May 2024 15:27:02 -0400
Subject: [PATCH] [Clang][Sema] Fix template name lookup for operator=
---
clang/lib/Sema/SemaLookup.cpp | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 2f6ad49fc08b61..e63da5875d2c91 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -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;
}
@@ -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
@@ -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;
}
@@ -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,
More information about the cfe-commits
mailing list