Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2499,6 +2499,7 @@ return ToD; const FunctionDecl *FoundByLookup = nullptr; + FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); // If this is a function template specialization, then try to find the same // existing specialization in the "to" context. The localUncachedLookup @@ -2525,6 +2526,14 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; + // If template was found, look at the templated function. + if (FromFT) { + if (auto *Template = dyn_cast(FoundDecl)) + FoundDecl = Template->getTemplatedDecl(); + else + continue; + } + if (auto *FoundFunction = dyn_cast(FoundDecl)) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -2700,6 +2709,14 @@ ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) { + if (auto *ToFT = dyn_cast(Importer.Import(FromFT))) + ToFunction->setDescribedFunctionTemplate(ToFT); + else + return nullptr; + } + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { Index: unittests/AST/ASTImporterTest.cpp =================================================================== --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1125,7 +1125,7 @@ } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl());