From: Gabor Marton Date: Mon, 18 Feb 2019 13:09:27 +0000 (+0000) Subject: [ASTImporter] Find previous friend function template X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94533b52c8f5040d486994fb226581b1118e0acb;p=clang [ASTImporter] Find previous friend function template Reviewers: a_sidorin, shafik, a.sidorin Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57910 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354267 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index c64a6d1707..1034694115 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -5540,7 +5540,7 @@ ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { // Try to find a function in our own ("to") context with the same name, same // type, and in the same context as the function we're importing. if (!LexicalDC->isFunctionOrMethod()) { - unsigned IDNS = Decl::IDNS_Ordinary; + unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); for (auto *FoundDecl : FoundDecls) { if (!FoundDecl->isInIdentifierNamespace(IDNS)) diff --git a/unittests/AST/ASTImporterTest.cpp b/unittests/AST/ASTImporterTest.cpp index 30bc9dc73c..fa5384503d 100644 --- a/unittests/AST/ASTImporterTest.cpp +++ b/unittests/AST/ASTImporterTest.cpp @@ -5390,6 +5390,33 @@ TEST_P(ASTImporterOptionSpecificTestBase, EXPECT_EQ(0u, ToTU->getASTContext().getDiagnostics().getNumWarnings()); } +struct ImportFriendFunctionTemplates : ASTImporterOptionSpecificTestBase {}; + +TEST_P(ImportFriendFunctionTemplates, LookupShouldFindPreviousFriend) { + Decl *ToTU = getToTuDecl( + R"( + class X { + template friend void foo(); + }; + )", + Lang_CXX); + auto *Friend = FirstDeclMatcher().match( + ToTU, functionTemplateDecl(hasName("foo"))); + + Decl *FromTU = getTuDecl( + R"( + template void foo(); + )", + Lang_CXX); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionTemplateDecl(hasName("foo"))); + auto *Imported = Import(FromFoo, Lang_CXX); + + // FIXME Currently chains of FunctionTemplateDecls are not implemented. + //EXPECT_EQ(Imported->getPreviousDecl(), Friend); + EXPECT_EQ(Imported, Friend); +} + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions, ); @@ -5408,6 +5435,9 @@ INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterOptionSpecificTestBase, INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctions, DefaultTestValuesForRunOptions, ); +INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFriendFunctionTemplates, + DefaultTestValuesForRunOptions, ); + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportClasses, DefaultTestValuesForRunOptions, );