From: Gabor Marton Date: Thu, 7 Mar 2019 13:38:20 +0000 (+0000) Subject: [ASTImporter] Import member expr with explicit template args X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2be515a96dfda4019e56b94c22f42e4051e0a10;p=clang [ASTImporter] Import member expr with explicit template args Summary: Member expressions with explicit template arguments were not imported correctly: the DeclRefExpr was missing. This patch fixes. Reviewers: a_sidorin, shafik, a.sidorin Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58830 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355596 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index da102988de..7ce4309457 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -7129,15 +7129,19 @@ ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); + TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; if (E->hasExplicitTemplateArgs()) { - // FIXME: handle template arguments - return make_error(ImportError::UnsupportedConstruct); + if (Error Err = + ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), + E->template_arguments(), ToTAInfo)) + return std::move(Err); + ResInfo = &ToTAInfo; } return MemberExpr::Create( Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, - ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind()); + ToMemberNameInfo, ResInfo, ToType, E->getValueKind(), E->getObjectKind()); } ExpectedStmt diff --git a/unittests/AST/ASTImporterTest.cpp b/unittests/AST/ASTImporterTest.cpp index 00e12d75bc..ebab02f500 100644 --- a/unittests/AST/ASTImporterTest.cpp +++ b/unittests/AST/ASTImporterTest.cpp @@ -2604,6 +2604,56 @@ TEST_P(ImportFunctions, ImportImplicitFunctionsInLambda) { EXPECT_TRUE(LambdaRec->getDestructor()); } +TEST_P(ImportFunctions, + CallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) { + Decl *FromTU = getTuDecl( + R"( + struct X { + template + void foo(){} + }; + void f() { + X x; + x.foo(); + } + )", + Lang_CXX); + auto *FromD = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("f"))); + auto *ToD = Import(FromD, Lang_CXX); + EXPECT_TRUE(ToD); + EXPECT_TRUE(MatchVerifier().match( + ToD, functionDecl(hasName("f"), hasDescendant(declRefExpr())))); +} + +TEST_P(ImportFunctions, + DependentCallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) { + Decl *FromTU = getTuDecl( + R"( + struct X { + template + void foo(){} + }; + template + void f() { + X x; + x.foo(); + } + void g() { + f(); + } + )", + Lang_CXX); + auto *FromD = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("g"))); + auto *ToD = Import(FromD, Lang_CXX); + EXPECT_TRUE(ToD); + Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl(); + EXPECT_TRUE(MatchVerifier().match( + ToTU, translationUnitDecl(hasDescendant( + functionDecl(hasName("f"), hasDescendant(declRefExpr())))))); +} + struct ImportFriendFunctions : ImportFunctions {}; TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {