[clang] [clang] fix NestedNameSpecifier dependency calculation (PR #135067)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 9 11:44:26 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Matheus Izvekov (mizvekov)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/135067.diff
3 Files Affected:
- (modified) clang/lib/AST/NestedNameSpecifier.cpp (+2-1)
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+1-2)
- (modified) clang/test/SemaTemplate/dependent-names.cpp (+14)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/135067
More information about the cfe-commits
mailing list