Skip to content

Commit 154507c

Browse files
authored
[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: #133610 (comment) which was introduced by #133610 There are no release notes since the regression was never released.
1 parent 2f7e685 commit 154507c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

clang/lib/AST/NestedNameSpecifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ NestedNameSpecifierDependence NestedNameSpecifier::getDependence() const {
221221
NestedNameSpecifierDependence Dep =
222222
toNestedNameSpecifierDependendence(getAsType()->getDependence());
223223
if (NestedNameSpecifier *Prefix = getPrefix())
224-
Dep |= Prefix->getDependence();
224+
Dep |=
225+
Prefix->getDependence() & ~NestedNameSpecifierDependence::Dependent;
225226
return Dep;
226227
}
227228
}

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
3131
const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
3232
if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
3333
CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
34-
if (!Record->isDependentContext() ||
35-
Record->isCurrentInstantiation(CurContext))
34+
if (Record->isCurrentInstantiation(CurContext))
3635
return Record;
3736

3837
return nullptr;

clang/test/SemaTemplate/dependent-names.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,17 @@ namespace TransformDependentTemplates {
467467
void f(Arg<int>);
468468
};
469469
} // namespace TransformDependentTemplates
470+
471+
namespace TransformNestedName {
472+
enum class S { kA };
473+
474+
template <class T> struct N {
475+
using State = S;
476+
template <typename T::template X<State::kA> = 0>
477+
void F();
478+
};
479+
480+
template <class T>
481+
template <typename T::template X<N<T>::State::kA>>
482+
inline void N<T>::F() {}
483+
} // namespace TransformNestedName

0 commit comments

Comments
 (0)