[PATCH] D60461: [ASTImporter] Import TemplateParameterLists in function templates.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 7 03:54:17 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rC360132: [ASTImporter] Import TemplateParameterLists in function templates. (authored by balazske, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D60461?vs=194310&id=198431#toc
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60461/new/
https://reviews.llvm.org/D60461
Files:
lib/AST/ASTImporter.cpp
unittests/AST/ASTImporterTest.cpp
Index: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -419,6 +419,8 @@
Expected<FunctionTemplateAndArgsTy>
ImportFunctionTemplateWithTemplateArgsFromSpecialization(
FunctionDecl *FromFD);
+ Error ImportTemplateParameterLists(const DeclaratorDecl *FromD,
+ DeclaratorDecl *ToD);
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD);
@@ -2780,6 +2782,22 @@
return ToEnumerator;
}
+Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD,
+ DeclaratorDecl *ToD) {
+ unsigned int Num = FromD->getNumTemplateParameterLists();
+ if (Num == 0)
+ return Error::success();
+ SmallVector<TemplateParameterList *, 2> ToTPLists(Num);
+ for (unsigned int I = 0; I < Num; ++I)
+ if (Expected<TemplateParameterList *> ToTPListOrErr =
+ import(FromD->getTemplateParameterList(I)))
+ ToTPLists[I] = *ToTPListOrErr;
+ else
+ return ToTPListOrErr.takeError();
+ ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
+ return Error::success();
+}
+
Error ASTNodeImporter::ImportTemplateInformation(
FunctionDecl *FromFD, FunctionDecl *ToFD) {
switch (FromFD->getTemplatedKind()) {
@@ -2826,6 +2844,9 @@
if (!POIOrErr)
return POIOrErr.takeError();
+ if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
+ return Err;
+
TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
ToFD->setFunctionTemplateSpecialization(
std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -5083,6 +5083,24 @@
EXPECT_FALSE(ImportedD->getUnderlyingType()->isIncompleteType());
}
+TEST_P(ASTImporterOptionSpecificTestBase, ImportTemplateParameterLists) {
+ auto Code =
+ R"(
+ template<class T>
+ int f() { return 0; }
+ template <> int f<int>() { return 4; }
+ )";
+
+ Decl *FromTU = getTuDecl(Code, Lang_CXX);
+ auto *FromD = FirstDeclMatcher<FunctionDecl>().match(FromTU,
+ functionDecl(hasName("f"), isExplicitTemplateSpecialization()));
+ ASSERT_EQ(FromD->getNumTemplateParameterLists(), 1);
+
+ auto *ToD = Import(FromD, Lang_CXX);
+ // The template parameter list should exist.
+ EXPECT_EQ(ToD->getNumTemplateParameterLists(), 1);
+}
+
struct ASTImporterLookupTableTest : ASTImporterOptionSpecificTestBase {};
TEST_P(ASTImporterLookupTableTest, OneDecl) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60461.198431.patch
Type: text/x-patch
Size: 2773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190507/7292534b/attachment.bin>
More information about the cfe-commits
mailing list