summaryrefslogtreecommitdiff
path: root/unittests/Tooling
diff options
context:
space:
mode:
authorMichael Han <fragmentshaders@gmail.com>2013-09-11 15:53:29 +0000
committerMichael Han <fragmentshaders@gmail.com>2013-09-11 15:53:29 +0000
commit4b6730d40e7c603bd0e223d3fa8b56a0c88a324a (patch)
tree25e74149cb69ed0a2708f7125e436008659769fc /unittests/Tooling
parent54272116ba68aad779fac42477013eef500ff211 (diff)
downloadclang-4b6730d40e7c603bd0e223d3fa8b56a0c88a324a.tar.gz
clang-4b6730d40e7c603bd0e223d3fa8b56a0c88a324a.tar.bz2
clang-4b6730d40e7c603bd0e223d3fa8b56a0c88a324a.tar.xz
Teach RAV to visit parameter variable declarations of implicit functions. Fixes PR16182.
Normally RAV visits parameter variable declarations of a function by traversing the TypeLoc of the parameter declarations. However, for implicit functions, their parameters don't have any TypeLoc, because they are implicit. So for implicit functions, we visit their parameter variable declarations by traversing them through the function declaration, and visit them accordingly. Reviewed by Richard Smith and Manuel Klimek. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190528 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling')
-rw-r--r--unittests/Tooling/RecursiveASTVisitorTest.cpp25
-rw-r--r--unittests/Tooling/TestVisitor.h6
2 files changed, 30 insertions, 1 deletions
diff --git a/unittests/Tooling/RecursiveASTVisitorTest.cpp b/unittests/Tooling/RecursiveASTVisitorTest.cpp
index b1d6f4a37c..b3a8915a59 100644
--- a/unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ b/unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -37,6 +37,17 @@ public:
}
};
+class ParmVarDeclVisitorForImplicitCode :
+ public ExpectedLocationVisitor<ParmVarDeclVisitorForImplicitCode> {
+public:
+ bool shouldVisitImplicitCode() const { return true; }
+
+ bool VisitParmVarDecl(ParmVarDecl *ParamVar) {
+ Match(ParamVar->getNameAsString(), ParamVar->getLocStart());
+ return true;
+ }
+};
+
class CXXMemberCallVisitor
: public ExpectedLocationVisitor<CXXMemberCallVisitor> {
public:
@@ -144,6 +155,20 @@ public:
}
};
+// Test RAV visits parameter variable declaration of the implicit
+// copy assignment operator.
+TEST(RecursiveASTVisitor, VisitsParmVarDeclForImplicitCode) {
+ ParmVarDeclVisitorForImplicitCode Visitor;
+ // Match parameter variable name of implicit copy assignment operator.
+ // This parameter name does not have a valid IdentifierInfo, and shares
+ // same SourceLocation with its class declaration, so we match an empty name
+ // with the class' source location.
+ Visitor.ExpectMatch("", 1, 7);
+ EXPECT_TRUE(Visitor.runOver(
+ "class X {};\n"
+ "void foo(X a, X b) {a = b;}"));
+}
+
TEST(RecursiveASTVisitor, VisitsBaseClassDeclarations) {
TypeLocVisitor Visitor;
Visitor.ExpectMatch("class X", 1, 30);
diff --git a/unittests/Tooling/TestVisitor.h b/unittests/Tooling/TestVisitor.h
index 5ee118ebdc..ec751c350e 100644
--- a/unittests/Tooling/TestVisitor.h
+++ b/unittests/Tooling/TestVisitor.h
@@ -31,7 +31,7 @@ namespace clang {
/// This is a drop-in replacement for RecursiveASTVisitor itself, with the
/// additional capability of running it over a snippet of code.
///
-/// Visits template instantiations (but not implicit code) by default.
+/// Visits template instantiations and implicit code by default.
template <typename T>
class TestVisitor : public RecursiveASTVisitor<T> {
public:
@@ -56,6 +56,10 @@ public:
return true;
}
+ bool shouldVisitImplicitCode() const {
+ return true;
+ }
+
protected:
virtual ASTFrontendAction* CreateTestAction() {
return new TestAction(this);