From: Daniel Jasper Date: Wed, 4 Feb 2015 14:29:47 +0000 (+0000) Subject: Rewrite r228138 to be somewhat saner. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf0504fac4c5ae0be0ce7d188e6f1e2d7fea0394;p=clang Rewrite r228138 to be somewhat saner. While probably technically correct, the solution r228138 was quite hard to read/understand. This should be simpler. Also added a test to ensure that we are still visiting the syntactic form as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228144 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 3db0eb79e6..ff8e74b650 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2032,20 +2032,21 @@ DEF_TRAVERSE_STMT(CXXStaticCastExpr, { // to the syntactic form. template bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { - if (InitListExpr *Syn = S->getSyntacticForm()) - S = Syn; - TRY_TO(WalkUpFromInitListExpr(S)); - // All we need are the default actions. FIXME: use a helper function. - for (Stmt::child_range range = S->children(); range; ++range) { - TRY_TO(TraverseStmt(*range)); - } - if (InitListExpr *Syn = S->getSemanticForm()) { + InitListExpr *Syn = S->isSemanticForm() ? S->getSyntacticForm() : S; + if (Syn) { TRY_TO(WalkUpFromInitListExpr(Syn)); // All we need are the default actions. FIXME: use a helper function. for (Stmt::child_range range = Syn->children(); range; ++range) { TRY_TO(TraverseStmt(*range)); } } + InitListExpr *Sem = S->isSemanticForm() ? S : S->getSemanticForm(); + if (Sem) { + TRY_TO(WalkUpFromInitListExpr(Sem)); + for (Stmt::child_range range = Sem->children(); range; ++range) { + TRY_TO(TraverseStmt(*range)); + } + } return true; } diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 7325e06503..6485803a96 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -3148,6 +3148,8 @@ TEST(InitListExpression, MatchesInitListExpression) { "void f();" "S s[1] = { &f };", declRefExpr(to(functionDecl(hasName("f")))))); + EXPECT_TRUE( + matches("int i[1] = {42, [0] = 43};", integerLiteral(equals(42)))); } TEST(UsingDeclaration, MatchesUsingDeclarations) {