From c90d12d1df14b16aa83700e5dd4ec2009bfa2655 Mon Sep 17 00:00:00 2001 From: Michael Han Date: Wed, 11 Sep 2013 15:53:29 +0000 Subject: 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 --- .../unittests/Tooling/RecursiveASTVisitorTest.cpp | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'clang/unittests/Tooling/RecursiveASTVisitorTest.cpp') 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 { +public: + bool shouldVisitImplicitCode() const { return true; } + + bool VisitParmVarDecl(ParmVarDecl *ParamVar) { + Match(ParamVar->getNameAsString(), ParamVar->getLocStart()); + return true; + } +}; + class CXXMemberCallVisitor : public ExpectedLocationVisitor { 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); -- cgit v1.2.3