From 7af41ccdc478f8bf27694f3d17fa60df4d534fc9 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 24 Apr 2012 20:39:49 +0000 Subject: RecursiveASTVisitor: Visit instantiations of member templates of class templates. In an implicit instantiation of a member class, any member templates don't get instantiated, so the existing check which only visited the instantiations of a defined template skipped these templates' instantiations. Since there is only a single declaration of a member template of a class template specialization, just use that to determine whether to visit the instantiations. This introduces a slight inconsistency in that we will visit the instantiations of such templates whether or not they are defined, but we never visit a declared-but-not-defined instantiation, so this turns out to not matter. Patch by Daniel Jasper! llvm-svn: 155487 --- .../unittests/Tooling/RecursiveASTVisitorTest.cpp | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'clang/unittests/Tooling/RecursiveASTVisitorTest.cpp') diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp index 8ddae504a0a..6ef2786210f 100644 --- a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -208,8 +208,7 @@ TEST(RecursiveASTVisitor, VisitsCallInTemplateInstantiation) { "void foo() { y(Y()); }")); } -/* FIXME: -TEST(RecursiveASTVisitor, VisitsCallInNestedTemplateInstantiation) { +TEST(RecursiveASTVisitor, VisitsCallInNestedFunctionTemplateInstantiation) { CXXMemberCallVisitor Visitor; Visitor.ExpectMatch("Y::x", 4, 5); EXPECT_TRUE(Visitor.runOver( @@ -221,7 +220,24 @@ TEST(RecursiveASTVisitor, VisitsCallInNestedTemplateInstantiation) { "};\n" "void foo() { Z::f(); }")); } -*/ + +TEST(RecursiveASTVisitor, VisitsCallInNestedClassTemplateInstantiation) { + CXXMemberCallVisitor Visitor; + Visitor.ExpectMatch("A::x", 5, 7); + EXPECT_TRUE(Visitor.runOver( + "template struct X {\n" + " template struct Y {\n" + " void f() {\n" + " T2 y;\n" + " y.x();\n" + " }\n" + " };\n" + "};\n" + "struct A { void x(); };\n" + "int main() {\n" + " (new X::Y())->f();\n" + "}")); +} /* FIXME: According to Richard Smith this is a bug in the AST. TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) { @@ -236,4 +252,3 @@ TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) { */ } // end namespace clang - -- cgit v1.2.3