[PATCH] D49235: [ASTImporter] Import described template (if any) of function.

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 17 02:57:54 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC337260: [ASTImporter] Import described template (if any) of function. (authored by balazske, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49235?vs=155630&id=155832#toc

Repository:
  rC Clang

https://reviews.llvm.org/D49235

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2539,6 +2539,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
@@ -2565,6 +2566,14 @@
       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 @@
     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)) {
Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1185,7 +1185,7 @@
 }
 
 TEST_P(ASTImporterTestBase,
-       DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) {
+       ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) {
   Decl *FromTU = getTuDecl("template<class X> void f(){}", Lang_CXX);
   auto FromFT = FirstDeclMatcher<FunctionTemplateDecl>().match(
       FromTU, functionTemplateDecl());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49235.155832.patch
Type: text/x-patch
Size: 1891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180717/982b72ea/attachment.bin>


More information about the cfe-commits mailing list