Expected<FunctionTemplateAndArgsTy>
ImportFunctionTemplateWithTemplateArgsFromSpecialization(
FunctionDecl *FromFD);
+ Error ImportTemplateParameterLists(const DeclaratorDecl *FromD,
+ DeclaratorDecl *ToD);
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD);
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()) {
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,
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) {