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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258503
91177308-0d34-0410-b5e6-
96231b3b80d8
if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
TRY_TO(TraverseStmt(Init->getInit()));
+
+ if (Init->getNumArrayIndices() && getDerived().shouldVisitImplicitCode())
+ for (VarDecl *VD : Init->getArrayIndexes())
+ TRY_TO(TraverseDecl(VD));
return true;
}
hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation())))))));
}
+TEST(HasAncestor, ImplicitArrayCopyCtorDeclRefExpr) {
+ EXPECT_TRUE(matches("struct MyClass {\n"
+ " int c[1];\n"
+ " static MyClass Create() { return MyClass(); }\n"
+ "};",
+ declRefExpr(to(decl(hasAncestor(decl()))))));
+}
+
TEST(HasParent, MatchesAllParents) {
EXPECT_TRUE(matches(
"template <typename T> struct C { static void f() { 42; } };"
"};\n"));
}
+// Check to ensure that VarDecls are visited.
+class VarDeclVisitor : public ExpectedLocationVisitor<VarDeclVisitor> {
+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