r354267 - [ASTImporter] Find previous friend function template
Gabor Marton via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 18 05:09:27 PST 2019
Author: martong
Date: Mon Feb 18 05:09:27 2019
New Revision: 354267
URL: http://llvm.org/viewvc/llvm-project?rev=354267&view=rev
Log:
[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
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=354267&r1=354266&r2=354267&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Feb 18 05:09:27 2019
@@ -5540,7 +5540,7 @@ ASTNodeImporter::VisitFunctionTemplateDe
// 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))
Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=354267&r1=354266&r2=354267&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Mon Feb 18 05:09:27 2019
@@ -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 <typename T> friend void foo();
+ };
+ )",
+ Lang_CXX);
+ auto *Friend = FirstDeclMatcher<FunctionTemplateDecl>().match(
+ ToTU, functionTemplateDecl(hasName("foo")));
+
+ Decl *FromTU = getTuDecl(
+ R"(
+ template <typename T> void foo();
+ )",
+ Lang_CXX);
+ auto *FromFoo = FirstDeclMatcher<FunctionTemplateDecl>().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(ParameterizedTes
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctions,
DefaultTestValuesForRunOptions, );
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFriendFunctionTemplates,
+ DefaultTestValuesForRunOptions, );
+
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportClasses,
DefaultTestValuesForRunOptions, );
More information about the cfe-commits
mailing list