Skip to content

Commit 4415e4d

Browse files
committed
Do not create a template parameter list for the index
1 parent ec6fde3 commit 4415e4d

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,18 +3432,18 @@ class TemplateParamObjectDecl : public ValueDecl,
34323432
/// \see CXXExpansionStmtInstantiation
34333433
class CXXExpansionStmtDecl : public Decl, public DeclContext {
34343434
CXXExpansionStmtPattern *Expansion = nullptr;
3435-
TemplateParameterList *TParams;
3435+
NonTypeTemplateParmDecl *IndexNTTP = nullptr;
34363436
CXXExpansionStmtInstantiation *Instantiations = nullptr;
34373437

34383438
CXXExpansionStmtDecl(DeclContext *DC, SourceLocation Loc,
3439-
TemplateParameterList *TParams);
3439+
NonTypeTemplateParmDecl *NTTP);
34403440

34413441
public:
34423442
friend class ASTDeclReader;
34433443

34443444
static CXXExpansionStmtDecl *Create(ASTContext &C, DeclContext *DC,
34453445
SourceLocation Loc,
3446-
TemplateParameterList *TParams);
3446+
NonTypeTemplateParmDecl *NTTP);
34473447
static CXXExpansionStmtDecl *CreateDeserialized(ASTContext &C,
34483448
GlobalDeclID ID);
34493449

@@ -3462,10 +3462,10 @@ class CXXExpansionStmtDecl : public Decl, public DeclContext {
34623462
Instantiations = S;
34633463
}
34643464

3465-
NonTypeTemplateParmDecl *getIndexTemplateParm() const {
3466-
return cast<NonTypeTemplateParmDecl>(TParams->getParam(0));
3465+
NonTypeTemplateParmDecl *getIndexTemplateParm() { return IndexNTTP; }
3466+
const NonTypeTemplateParmDecl *getIndexTemplateParm() const {
3467+
return IndexNTTP;
34673468
}
3468-
TemplateParameterList *getTemplateParameters() const { return TParams; }
34693469

34703470
SourceRange getSourceRange() const override LLVM_READONLY;
34713471

clang/lib/AST/ASTImporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,14 +2879,14 @@ ASTNodeImporter::VisitCXXExpansionStmtDecl(CXXExpansionStmtDecl *D) {
28792879
Error Err = Error::success();
28802880
auto ToLocation = importChecked(Err, D->getLocation());
28812881
auto ToExpansion = importChecked(Err, D->getExpansionPattern());
2882-
auto ToTemplateParams = importChecked(Err, D->getTemplateParameters());
2882+
auto ToIndex = importChecked(Err, D->getIndexTemplateParm());
28832883
auto ToInstantiations = importChecked(Err, D->getInstantiations());
28842884
if (Err)
28852885
return std::move(Err);
28862886

28872887
CXXExpansionStmtDecl *ToD;
28882888
if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToLocation,
2889-
ToTemplateParams))
2889+
ToIndex))
28902890
return ToD;
28912891

28922892
ToD->setExpansionPattern(ToExpansion);

clang/lib/AST/DeclTemplate.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,9 +1718,8 @@ clang::getReplacedTemplateParameter(Decl *D, unsigned Index) {
17181718
cast<FunctionDecl>(D)->getTemplateSpecializationInfo()->getTemplate(),
17191719
Index);
17201720
case Decl::Kind::CXXExpansionStmt:
1721-
return {
1722-
cast<CXXExpansionStmtDecl>(D)->getTemplateParameters()->getParam(Index),
1723-
{}};
1721+
assert(Index == 0 && "expansion stmts only have a single template param");
1722+
return {cast<CXXExpansionStmtDecl>(D)->getIndexTemplateParm(), {}};
17241723
default:
17251724
llvm_unreachable("Unhandled templated declaration kind");
17261725
}
@@ -1794,14 +1793,14 @@ const Decl &clang::adjustDeclToTemplate(const Decl &D) {
17941793
}
17951794

17961795
CXXExpansionStmtDecl::CXXExpansionStmtDecl(DeclContext *DC, SourceLocation Loc,
1797-
TemplateParameterList *TParams)
1796+
NonTypeTemplateParmDecl *NTTP)
17981797
: Decl(CXXExpansionStmt, DC, Loc), DeclContext(CXXExpansionStmt),
1799-
TParams(TParams) {}
1798+
IndexNTTP(NTTP) {}
18001799

18011800
CXXExpansionStmtDecl *
18021801
CXXExpansionStmtDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation Loc,
1803-
TemplateParameterList *TParams) {
1804-
return new (C, DC) CXXExpansionStmtDecl(DC, Loc, TParams);
1802+
NonTypeTemplateParmDecl *NTTP) {
1803+
return new (C, DC) CXXExpansionStmtDecl(DC, Loc, NTTP);
18051804
}
18061805
CXXExpansionStmtDecl *
18071806
CXXExpansionStmtDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,7 @@ void ASTDeclReader::VisitCXXExpansionStmtDecl(CXXExpansionStmtDecl *D) {
27752775
D->Expansion = cast<CXXExpansionStmtPattern>(Record.readStmt());
27762776
D->Instantiations =
27772777
cast_or_null<CXXExpansionStmtInstantiation>(Record.readStmt());
2778-
D->TParams = Record.readTemplateParameterList();
2778+
D->IndexNTTP = cast<NonTypeTemplateParmDecl>(Record.readDeclRef());
27792779
}
27802780

27812781
void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) {

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ void ASTDeclWriter::VisitCXXExpansionStmtDecl(CXXExpansionStmtDecl *D) {
21932193
VisitDecl(D);
21942194
Record.AddStmt(D->getExpansionPattern());
21952195
Record.AddStmt(D->getInstantiations());
2196-
Record.AddTemplateParameterList(D->getTemplateParameters());
2196+
Record.AddDeclRef(D->getIndexTemplateParm());
21972197
Code = serialization::DECL_EXPANSION_STMT;
21982198
}
21992199

0 commit comments

Comments
 (0)