[llvm-branch-commits] [clang] 14ca8d4 - [clang] Fix a bug with qualified name lookup into current instantiation (#73018)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 30 09:46:43 PST 2023
Author: Mariya Podchishchaeva
Date: 2023-11-30T10:46:35+01:00
New Revision: 14ca8d44d0f44ea5125b3c41b66276c902929a54
URL: https://github.com/llvm/llvm-project/commit/14ca8d44d0f44ea5125b3c41b66276c902929a54
DIFF: https://github.com/llvm/llvm-project/commit/14ca8d44d0f44ea5125b3c41b66276c902929a54.diff
LOG: [clang] Fix a bug with qualified name lookup into current instantiation (#73018)
Due to d0d2ee0e4bbe915d649e983c12d37bcfcf58823c clang doesn't perform
qualified name lookup into the current instantiation when it has
dependent bases, because of that `getTypeName` call always returns null
for unknown specialization case. When there is a `typename` keyword,
`DependentNameType` is constructed instead of simply returning null.
This change attempts to do the same in case of `typename` absence.
Fixes https://github.com/llvm/llvm-project/issues/13826
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaTemplate/dependent-base-classes.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7d64647433d92a7..748e2db2f850744 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -645,6 +645,9 @@ Bug Fixes in This Version
- Fix crash when the object used as a ``static_assert`` message has ``size`` or ``data`` members
which are not member functions.
- Support UDLs in ``static_assert`` message.
+- Fixed false positive error emitted by clang when performing qualified name
+ lookup and the current class instantiation has dependent bases.
+ Fixes (`#13826 <https://github.com/llvm/llvm-project/issues/13826>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9591f8b87ba5456..67d0997b32e157a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -442,7 +442,6 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
UsingShadowDecl *FoundUsingShadow = nullptr;
switch (Result.getResultKind()) {
case LookupResult::NotFound:
- case LookupResult::NotFoundInCurrentInstantiation:
if (CorrectedII) {
TypeNameValidatorCCC CCC(/*AllowInvalid=*/true, isClassName,
AllowDeducedTemplate);
@@ -482,7 +481,18 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
}
}
}
- // If typo correction failed or was not performed, fall through
+ Result.suppressDiagnostics();
+ return nullptr;
+ case LookupResult::NotFoundInCurrentInstantiation:
+ if (AllowImplicitTypename == ImplicitTypenameContext::Yes) {
+ QualType T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
+ SS->getScopeRep(), &II);
+ TypeLocBuilder TLB;
+ DependentNameTypeLoc TL = TLB.push<DependentNameTypeLoc>(T);
+ TL.setQualifierLoc(SS->getWithLocInContext(Context));
+ TL.setNameLoc(NameLoc);
+ return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
+ }
[[fallthrough]];
case LookupResult::FoundOverloaded:
case LookupResult::FoundUnresolvedValue:
diff --git a/clang/test/SemaTemplate/dependent-base-classes.cpp b/clang/test/SemaTemplate/dependent-base-classes.cpp
index 09f475f8bde9183..92a37efaa7e73f6 100644
--- a/clang/test/SemaTemplate/dependent-base-classes.cpp
+++ b/clang/test/SemaTemplate/dependent-base-classes.cpp
@@ -130,3 +130,17 @@ namespace PR5812 {
Derived<int> di;
}
+
+namespace GH13826 {
+template <typename T> struct A {
+ typedef int type;
+ struct B;
+};
+
+template <typename T> struct A<T>::B : A<T> {
+ B::type t;
+};
+
+A<int> a;
+A<int>::B b;
+}
More information about the llvm-branch-commits
mailing list