summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
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
commitc90d12d1df14b16aa83700e5dd4ec2009bfa2655 (patch)
tree256ce5204622e0607a71ab016cf7dc01e25bbd58 /clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
parent17c17bce2a3bba6d80b4a4fd115f03ecae0f8545 (diff)
downloadbcm5719-llvm-c90d12d1df14b16aa83700e5dd4ec2009bfa2655.tar.gz
bcm5719-llvm-c90d12d1df14b16aa83700e5dd4ec2009bfa2655.zip
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. llvm-svn: 190528
Diffstat (limited to 'clang/unittests/Tooling/RecursiveASTVisitorTest.cpp')
-rw-r--r--clang/unittests/Tooling/RecursiveASTVisitorTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
index b1d6f4a37c0..b3a8915a59d 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud