https://github.com/Fznamznon updated https://github.com/llvm/llvm-project/pull/73018
>From 0275f3ea777750b3f410d2132d61ea406131de6c Mon Sep 17 00:00:00 2001 From: "Podchishchaeva, Mariya" <mariya.podchishcha...@intel.com> Date: Tue, 21 Nov 2023 08:32:36 -0800 Subject: [PATCH 1/2] [clang] Fix a bug with qualified name lookup into current instantiation 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 --- clang/docs/ReleaseNotes.rst | 3 +++ clang/lib/Sema/SemaDecl.cpp | 20 ++++++++++++++++--- .../SemaTemplate/dependent-base-classes.cpp | 14 +++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 157afd9e8629152..09ceb591d06eab5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -610,6 +610,9 @@ Bug Fixes in This Version inside a lambda. (`#61460 <https://github.com/llvm/llvm-project/issues/61460>`_) - Fix crash during instantiation of some class template specializations within class templates. Fixes (`#70375 <https://github.com/llvm/llvm-project/issues/70375>`_) +- 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 4e1857b931cc868..71003c1815c90e4 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,8 +481,23 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, } } } - // If typo correction failed or was not performed, fall through - [[fallthrough]]; + Result.suppressDiagnostics(); + return nullptr; + case LookupResult::NotFoundInCurrentInstantiation: { + if (AllowImplicitTypename == ImplicitTypenameContext::Yes) { + QualType T; + T = Context.getDependentNameType(ElaboratedTypeKeyword::None, + SS->getScopeRep(), &II); + TypeLocBuilder TLB; + DependentNameTypeLoc TL = TLB.push<DependentNameTypeLoc>(T); + TL.setElaboratedKeywordLoc(SourceLocation()); + TL.setQualifierLoc(SS->getWithLocInContext(Context)); + TL.setNameLoc(NameLoc); + return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T)); + } + Result.suppressDiagnostics(); + return nullptr; + } case LookupResult::FoundOverloaded: case LookupResult::FoundUnresolvedValue: Result.suppressDiagnostics(); 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; +} >From 5f4b4b93ed52ca06451289c9d5054824186901e7 Mon Sep 17 00:00:00 2001 From: "Podchishchaeva, Mariya" <mariya.podchishcha...@intel.com> Date: Wed, 29 Nov 2023 10:47:38 -0800 Subject: [PATCH 2/2] Apply comments --- clang/lib/Sema/SemaDecl.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 71003c1815c90e4..7ac0d40a33c3126 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -483,21 +483,17 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, } Result.suppressDiagnostics(); return nullptr; - case LookupResult::NotFoundInCurrentInstantiation: { + case LookupResult::NotFoundInCurrentInstantiation: if (AllowImplicitTypename == ImplicitTypenameContext::Yes) { - QualType T; - T = Context.getDependentNameType(ElaboratedTypeKeyword::None, - SS->getScopeRep(), &II); + QualType T = Context.getDependentNameType(ElaboratedTypeKeyword::None, + SS->getScopeRep(), &II); TypeLocBuilder TLB; DependentNameTypeLoc TL = TLB.push<DependentNameTypeLoc>(T); - TL.setElaboratedKeywordLoc(SourceLocation()); TL.setQualifierLoc(SS->getWithLocInContext(Context)); TL.setNameLoc(NameLoc); return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T)); } - Result.suppressDiagnostics(); - return nullptr; - } + [[fallthrough]]; case LookupResult::FoundOverloaded: case LookupResult::FoundUnresolvedValue: Result.suppressDiagnostics(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits