[cfe-commits] r155487 - in /cfe/trunk: include/clang/AST/RecursiveASTVisitor.h unittests/Tooling/RecursiveASTVisitorTest.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Tue Apr 24 13:39:50 PDT 2012
Author: rsmith
Date: Tue Apr 24 15:39:49 2012
New Revision: 155487
URL: http://llvm.org/viewvc/llvm-project?rev=155487&view=rev
Log:
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!
Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=155487&r1=155486&r2=155487&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Apr 24 15:39:49 2012
@@ -1436,7 +1436,8 @@
if (getDerived().shouldVisitTemplateInstantiations()) {
// If this is the definition of the primary template, visit
// instantiations which were formed from this pattern.
- if (D->isThisDeclarationADefinition())
+ if (D->isThisDeclarationADefinition() ||
+ D->getInstantiatedFromMemberTemplate())
TRY_TO(TraverseClassInstantiations(D, D));
}
@@ -1489,7 +1490,8 @@
//
// In addition, we only traverse the function instantiations when
// the function template is a function template definition.
- if (D->isThisDeclarationADefinition()) {
+ if (D->isThisDeclarationADefinition() ||
+ D->getInstantiatedFromMemberTemplate()) {
TRY_TO(TraverseFunctionInstantiations(D));
}
}
Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp?rev=155487&r1=155486&r2=155487&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp Tue Apr 24 15:39:49 2012
@@ -208,8 +208,7 @@
"void foo() { y<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 @@
"};\n"
"void foo() { Z<Y>::f<int>(); }"));
}
-*/
+
+TEST(RecursiveASTVisitor, VisitsCallInNestedClassTemplateInstantiation) {
+ CXXMemberCallVisitor Visitor;
+ Visitor.ExpectMatch("A::x", 5, 7);
+ EXPECT_TRUE(Visitor.runOver(
+ "template <typename T1> struct X {\n"
+ " template <typename T2> 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<A>::Y<A>())->f();\n"
+ "}"));
+}
/* FIXME: According to Richard Smith this is a bug in the AST.
TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) {
@@ -236,4 +252,3 @@
*/
} // end namespace clang
-
More information about the cfe-commits
mailing list