https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/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 its 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. >From ac047a66e82cc3cf806e234e781fc5aa79ee8d85 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <mizve...@gmail.com> Date: Wed, 9 Apr 2025 15:15:51 -0300 Subject: [PATCH] [clang] fix NestedNameSpecifier dependency calculation 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 its 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. --- clang/lib/AST/NestedNameSpecifier.cpp | 3 ++- clang/lib/Sema/SemaCXXScopeSpec.cpp | 3 +-- clang/test/SemaTemplate/dependent-names.cpp | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) 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