]> granicus.if.org Git - clang/commitdiff
RecursiveASTVisitor:
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 9 May 2012 23:51:36 +0000 (23:51 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 9 May 2012 23:51:36 +0000 (23:51 +0000)
We don't create any declaration to mark the explicit instantiation of function
templates other than the instantiation itself, so visit that when traversing
the function template decl.

This is a temporary fix, pending the creation of a Decl node to represent the
explicit instantiation.

Patch by Daniel Jasper!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156522 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/RecursiveASTVisitor.h
unittests/Tooling/RecursiveASTVisitorTest.cpp

index a9a98d77ba2731634f0886a812256c69fc4cdc85..41a6d8f503decd0207f0e8103e3dd302958903f5 100644 (file)
@@ -1451,10 +1451,11 @@ bool RecursiveASTVisitor<Derived>::TraverseFunctionInstantiations(
       TRY_TO(TraverseDecl(FD));
       break;
 
-    // No need to visit explicit instantiations, we'll find the node
-    // eventually.
+    // FIXME: For now traverse explicit instantiations here. Change that
+    // once they are represented as dedicated nodes in the AST.
     case TSK_ExplicitInstantiationDeclaration:
     case TSK_ExplicitInstantiationDefinition:
+      TRY_TO(TraverseDecl(FD));
       break;
 
     case TSK_ExplicitSpecialization:
index 953817e61fb6934183150bc3f1fd1df25abc14a5..a26c9f3cb73157e9804fd09bd9cf866a4f48aaee 100644 (file)
@@ -301,6 +301,19 @@ TEST(RecursiveASTVisitor, VisitsCallInPartialTemplateSpecialization) {
     "}\n"));
 }
 
+TEST(RecursiveASTVisitor, VisitsExplicitTemplateSpecialization) {
+  CXXMemberCallVisitor Visitor;
+  Visitor.ExpectMatch("A::f", 4, 5);
+  EXPECT_TRUE(Visitor.runOver(
+    "struct A {\n"
+    "  void f() const {}\n"
+    "  template<class T> void g(const T& t) const {\n"
+    "    t.f();\n"
+    "  }\n"
+    "};\n"
+    "template void A::g(const A& a) const;\n"));
+}
+
 TEST(RecursiveASTVisitor, VisitsPartialTemplateSpecialization) {
   // From cfe-commits/Week-of-Mon-20100830/033998.html
   // Contrary to the approach sugggested in that email, we visit all