r337260 - [ASTImporter] Import described template (if any) of function.
Balazs Keri via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 17 02:52:42 PDT 2018
Author: balazske
Date: Tue Jul 17 02:52:41 2018
New Revision: 337260
URL: http://llvm.org/viewvc/llvm-project?rev=337260&view=rev
Log:
[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
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=337260&r1=337259&r2=337260&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jul 17 02:52:41 2018
@@ -2539,6 +2539,7 @@ Decl *ASTNodeImporter::VisitFunctionDecl
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
if (!FoundDecl->isInIdentifierNamespace(IDNS))
continue;
+ // If template was found, look at the templated function.
+ if (FromFT) {
+ if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl))
+ FoundDecl = Template->getTemplatedDecl();
+ else
+ continue;
+ }
+
if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
if (FoundFunction->hasExternalFormalLinkage() &&
D->hasExternalFormalLinkage()) {
@@ -2740,6 +2749,11 @@ Decl *ASTNodeImporter::VisitFunctionDecl
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)) {
Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=337260&r1=337259&r2=337260&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Tue Jul 17 02:52:41 2018
@@ -1185,7 +1185,7 @@ TEST_P(ASTImporterTestBase,
}
TEST_P(ASTImporterTestBase,
- DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) {
+ ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) {
Decl *FromTU = getTuDecl("template<class X> void f(){}", Lang_CXX);
auto FromFT = FirstDeclMatcher<FunctionTemplateDecl>().match(
FromTU, functionTemplateDecl());
More information about the cfe-commits
mailing list