From: Balazs Keri <1.int32@gmail.com> Date: Tue, 17 Jul 2018 09:52:41 +0000 (+0000) Subject: [ASTImporter] Import described template (if any) of function. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0d3baaed339a76574fdfecc2f756e568bf58f53;p=clang [ASTImporter] Import described template (if any) of function. Summary: When a function is imported, check if it has a described template. The name lookup is corrected to find the templated entity in this case. The described template of the function is imported too. Reviewers: a.sidorin, a_sidorin Reviewed By: a_sidorin Subscribers: a_sidorin, martong, cfe-commits Differential Revision: https://reviews.llvm.org/D49235 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337260 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 366c2064d4..980ab478d5 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -2539,6 +2539,7 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { 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 @@ -2565,6 +2566,14 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { 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()) { @@ -2740,6 +2749,11 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) + if (!Importer.Import(FromFT)) + return nullptr; + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { diff --git a/unittests/AST/ASTImporterTest.cpp b/unittests/AST/ASTImporterTest.cpp index cc8ed92faa..c59c2cd125 100644 --- a/unittests/AST/ASTImporterTest.cpp +++ b/unittests/AST/ASTImporterTest.cpp @@ -1185,7 +1185,7 @@ TEST_P(ASTImporterTestBase, } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl());