Skip to content

Commit 5caba30

Browse files
committed
[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 llvm-svn: 355596
1 parent e7ec39c commit 5caba30

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7129,15 +7129,19 @@ ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) {
71297129

71307130
DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
71317131

7132+
TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
71327133
if (E->hasExplicitTemplateArgs()) {
7133-
// FIXME: handle template arguments
7134-
return make_error<ImportError>(ImportError::UnsupportedConstruct);
7134+
if (Error Err =
7135+
ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
7136+
E->template_arguments(), ToTAInfo))
7137+
return std::move(Err);
7138+
ResInfo = &ToTAInfo;
71357139
}
71367140

71377141
return MemberExpr::Create(
71387142
Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
71397143
ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl,
7140-
ToMemberNameInfo, nullptr, ToType, E->getValueKind(), E->getObjectKind());
7144+
ToMemberNameInfo, ResInfo, ToType, E->getValueKind(), E->getObjectKind());
71417145
}
71427146

71437147
ExpectedStmt

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,56 @@ TEST_P(ImportFunctions, ImportImplicitFunctionsInLambda) {
26042604
EXPECT_TRUE(LambdaRec->getDestructor());
26052605
}
26062606

2607+
TEST_P(ImportFunctions,
2608+
CallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) {
2609+
Decl *FromTU = getTuDecl(
2610+
R"(
2611+
struct X {
2612+
template <typename T>
2613+
void foo(){}
2614+
};
2615+
void f() {
2616+
X x;
2617+
x.foo<int>();
2618+
}
2619+
)",
2620+
Lang_CXX);
2621+
auto *FromD = FirstDeclMatcher<FunctionDecl>().match(
2622+
FromTU, functionDecl(hasName("f")));
2623+
auto *ToD = Import(FromD, Lang_CXX);
2624+
EXPECT_TRUE(ToD);
2625+
EXPECT_TRUE(MatchVerifier<FunctionDecl>().match(
2626+
ToD, functionDecl(hasName("f"), hasDescendant(declRefExpr()))));
2627+
}
2628+
2629+
TEST_P(ImportFunctions,
2630+
DependentCallExprOfMemberFunctionTemplateWithExplicitTemplateArgs) {
2631+
Decl *FromTU = getTuDecl(
2632+
R"(
2633+
struct X {
2634+
template <typename T>
2635+
void foo(){}
2636+
};
2637+
template <typename T>
2638+
void f() {
2639+
X x;
2640+
x.foo<T>();
2641+
}
2642+
void g() {
2643+
f<int>();
2644+
}
2645+
)",
2646+
Lang_CXX);
2647+
auto *FromD = FirstDeclMatcher<FunctionDecl>().match(
2648+
FromTU, functionDecl(hasName("g")));
2649+
auto *ToD = Import(FromD, Lang_CXX);
2650+
EXPECT_TRUE(ToD);
2651+
Decl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
2652+
EXPECT_TRUE(MatchVerifier<TranslationUnitDecl>().match(
2653+
ToTU, translationUnitDecl(hasDescendant(
2654+
functionDecl(hasName("f"), hasDescendant(declRefExpr()))))));
2655+
}
2656+
26072657
struct ImportFriendFunctions : ImportFunctions {};
26082658

26092659
TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {

0 commit comments

Comments
 (0)