From c4acee338097f7f2a6a70cdd38dc7eb1f97c040e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 22 Jan 2016 15:11:54 +0000 Subject: Let RecursiveASTVisitor visit array index VarDecls An implicit copy ctor creates loop VarDecls that hang off CXXCtorInitializer. RecursiveASTVisitor used to not visit them, so that they didn't show up in the parent map used by ASTMatchers, causing asserts() when the implicit DeclRefExpr() in a CXXCtorInitializer referred to one of these VarDecls. Fixes PR26227. http://reviews.llvm.org/D16413 llvm-svn: 258503 --- clang/unittests/Tooling/RecursiveASTVisitorTest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'clang/unittests/Tooling/RecursiveASTVisitorTest.cpp') diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp index 5d0e2bccd4d..991ae8bb7f3 100644 --- a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -133,4 +133,23 @@ TEST(RecursiveASTVisitor, AttributesAreVisited) { "};\n")); } +// Check to ensure that VarDecls are visited. +class VarDeclVisitor : public ExpectedLocationVisitor { +public: + bool VisitVarDecl(VarDecl *VD) { + Match(VD->getNameAsString(), VD->getLocStart()); + return true; + } +}; + +TEST(RecursiveASTVisitor, ArrayInitializersAreVisited) { + VarDeclVisitor Visitor; + Visitor.ExpectMatch("__i0", 1, 8); + EXPECT_TRUE( + Visitor.runOver("struct MyClass {\n" + " int c[1];\n" + " static MyClass Create() { return MyClass(); }\n" + "};\n")); +} + } // end anonymous namespace -- cgit v1.2.3