Author: Matheus Izvekov Date: 2025-04-09T19:44:40-03:00 New Revision: 154507cf403e1859b9a81fa76af406e8489daa4b
URL: https://github.com/llvm/llvm-project/commit/154507cf403e1859b9a81fa76af406e8489daa4b DIFF: https://github.com/llvm/llvm-project/commit/154507cf403e1859b9a81fa76af406e8489daa4b.diff LOG: [clang] fix NestedNameSpecifier dependency calculation (#135067) A NestedNameSpecifier of TypeSpec kind can be non-dependent even if its prefix is dependent, when for example the prefix is an injected class type but the type itself is a simple alias to a non-dependent type. This issue was a bit hard to observe because if it is an alias to a class type, then we (for some unknown reason) ignored that the NNS was dependent in the first place, which wouldn't happen with an enum type. This could have been a workaround for previous dependency bugs, and is not relevant anymore for any of the test cases in the tree, so this patch also removes that. The other kinds of dependencies are still relevant. If the prefix contains an unexpanded pack, then this NNS is still unexpanded, and likewise for errors. This fixes a regression reported here: https://github.com/llvm/llvm-project/pull/133610#issuecomment-2787909829 which was introduced by https://github.com/llvm/llvm-project/pull/133610 There are no release notes since the regression was never released. Added: Modified: clang/lib/AST/NestedNameSpecifier.cpp clang/lib/Sema/SemaCXXScopeSpec.cpp clang/test/SemaTemplate/dependent-names.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp index 51aa2d69d0f0d..bd0fe36d781da 100644 --- a/clang/lib/AST/NestedNameSpecifier.cpp +++ b/clang/lib/AST/NestedNameSpecifier.cpp @@ -221,7 +221,8 @@ NestedNameSpecifierDependence NestedNameSpecifier::getDependence() const { NestedNameSpecifierDependence Dep = toNestedNameSpecifierDependendence(getAsType()->getDependence()); if (NestedNameSpecifier *Prefix = getPrefix()) - Dep |= Prefix->getDependence(); + Dep |= + Prefix->getDependence() & ~NestedNameSpecifierDependence::Dependent; return Dep; } } diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index ea7936b0e5b8f..68ee006c6cf00 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -31,8 +31,7 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T, const Type *Ty = T->getCanonicalTypeInternal().getTypePtr(); if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) { CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl()); - if (!Record->isDependentContext() || - Record->isCurrentInstantiation(CurContext)) + if (Record->isCurrentInstantiation(CurContext)) return Record; return nullptr; diff --git a/clang/test/SemaTemplate/dependent-names.cpp b/clang/test/SemaTemplate/dependent-names.cpp index 538abde3eddd5..54ce3760d2d01 100644 --- a/clang/test/SemaTemplate/dependent-names.cpp +++ b/clang/test/SemaTemplate/dependent-names.cpp @@ -467,3 +467,17 @@ namespace TransformDependentTemplates { void f(Arg<int>); }; } // namespace TransformDependentTemplates + +namespace TransformNestedName { + enum class S { kA }; + + template <class T> struct N { + using State = S; + template <typename T::template X<State::kA> = 0> + void F(); + }; + + template <class T> + template <typename T::template X<N<T>::State::kA>> + inline void N<T>::F() {} +} // namespace TransformNestedName _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits