Skip to content

Commit 14ca8d4

Browse files
authored
[clang] Fix a bug with qualified name lookup into current instantiation (#73018)
Due to d0d2ee0 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 #13826
1 parent e9869b5 commit 14ca8d4

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ Bug Fixes in This Version
645645
- Fix crash when the object used as a ``static_assert`` message has ``size`` or ``data`` members
646646
which are not member functions.
647647
- Support UDLs in ``static_assert`` message.
648+
- Fixed false positive error emitted by clang when performing qualified name
649+
lookup and the current class instantiation has dependent bases.
650+
Fixes (`#13826 <https://github.com/llvm/llvm-project/issues/13826>`_)
648651

649652
Bug Fixes to Compiler Builtins
650653
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
442442
UsingShadowDecl *FoundUsingShadow = nullptr;
443443
switch (Result.getResultKind()) {
444444
case LookupResult::NotFound:
445-
case LookupResult::NotFoundInCurrentInstantiation:
446445
if (CorrectedII) {
447446
TypeNameValidatorCCC CCC(/*AllowInvalid=*/true, isClassName,
448447
AllowDeducedTemplate);
@@ -482,7 +481,18 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
482481
}
483482
}
484483
}
485-
// If typo correction failed or was not performed, fall through
484+
Result.suppressDiagnostics();
485+
return nullptr;
486+
case LookupResult::NotFoundInCurrentInstantiation:
487+
if (AllowImplicitTypename == ImplicitTypenameContext::Yes) {
488+
QualType T = Context.getDependentNameType(ElaboratedTypeKeyword::None,
489+
SS->getScopeRep(), &II);
490+
TypeLocBuilder TLB;
491+
DependentNameTypeLoc TL = TLB.push<DependentNameTypeLoc>(T);
492+
TL.setQualifierLoc(SS->getWithLocInContext(Context));
493+
TL.setNameLoc(NameLoc);
494+
return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
495+
}
486496
[[fallthrough]];
487497
case LookupResult::FoundOverloaded:
488498
case LookupResult::FoundUnresolvedValue:

clang/test/SemaTemplate/dependent-base-classes.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,17 @@ namespace PR5812 {
130130

131131
Derived<int> di;
132132
}
133+
134+
namespace GH13826 {
135+
template <typename T> struct A {
136+
typedef int type;
137+
struct B;
138+
};
139+
140+
template <typename T> struct A<T>::B : A<T> {
141+
B::type t;
142+
};
143+
144+
A<int> a;
145+
A<int>::B b;
146+
}

0 commit comments

Comments
 (0)