-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Clang][Sema] Use correct TemplateName when transforming TemplateSpecializationType #93411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7216,9 +7216,30 @@ TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, | |
return QualType(); | ||
} | ||
|
||
QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); | ||
if (NamedT.isNull()) | ||
return QualType(); | ||
QualType NamedT; | ||
if (SemaRef.getLangOpts().CPlusPlus20 && QualifierLoc && | ||
isa<TemplateSpecializationType>(TL.getNamedTypeLoc().getType())) { | ||
TemplateSpecializationTypeLoc SpecTL = | ||
TL.getNamedTypeLoc().castAs<TemplateSpecializationTypeLoc>(); | ||
const TemplateSpecializationType *TST = | ||
SpecTL.getType()->castAs<TemplateSpecializationType>(); | ||
CXXScopeSpec SS; | ||
SS.Adopt(QualifierLoc); | ||
if (TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl()) { | ||
TemplateName InstName = getDerived().RebuildTemplateName( | ||
SS, TL.getTemplateKeywordLoc(), *TD->getIdentifier(), | ||
TL.getNamedTypeLoc().getBeginLoc(), /*ObjectType=*/QualType(), | ||
/*FirstQualifierInScope=*/nullptr, /*AllowInjectedClassName=*/false); | ||
if (InstName.isNull()) | ||
return QualType(); | ||
NamedT = TransformTemplateSpecializationType(TLB, SpecTL, InstName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean |
||
} | ||
} | ||
if (NamedT.isNull()) { | ||
NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); | ||
if (NamedT.isNull()) | ||
return QualType(); | ||
} | ||
|
||
// C++0x [dcl.type.elab]p2: | ||
// If the identifier resolves to a typedef-name or the simple-template-id | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s | ||
// expected-no-diagnostics | ||
|
||
template <typename> struct t1 { | ||
template <typename> | ||
struct t2 {}; | ||
}; | ||
|
||
template <typename T> | ||
t1<T>::template t2<T> f1(); | ||
|
||
void f2() { | ||
f1<bool>(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,16 +28,17 @@ namespace PR12884_original { | |
typedef int arg; | ||
}; | ||
struct C { | ||
typedef B::X<typename B::arg> x; // precxx17-warning{{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A drive-by comment: The test |
||
typedef B::X<typename B::arg> x; // precxx17-warning{{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}} \ | ||
cxx17-error{{typename specifier refers to non-type member 'arg' in 'PR12884_original::A<int>::B'}} | ||
}; | ||
}; | ||
|
||
template <> struct A<int>::B { | ||
template <int N> struct X {}; | ||
static const int arg = 0; | ||
static const int arg = 0; // cxx17-note{{referenced member 'arg' is declared here}} | ||
}; | ||
|
||
A<int>::C::x a; | ||
A<int>::C::x a; // cxx17-note{{in instantiation of member class 'PR12884_original::A<int>::C' requested here}} | ||
} | ||
namespace PR12884_half_fixed { | ||
template <typename T> struct A { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably looks better.