From: Malcolm Parsons Date: Wed, 26 Oct 2016 20:39:54 +0000 (+0000) Subject: [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9ca017f54d9ac5b7a46539e42ec114b99e9504a;p=clang [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr Summary: The matcher varDecl(hasDescendant( callExpr(hasDeclaration(functionDecl(unless(isNoThrow())))))) didn't match calls from default arguments because the expression for a CXXDefaultArgExpr was not visited. Reviewers: klimek, jdennett, alexfh, aaron.ballman Subscribers: aaron.ballman, cfe-commits Differential Revision: https://reviews.llvm.org/D25992 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285239 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 2129d7092f..99f46c7c8a 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2354,7 +2354,10 @@ DEF_TRAVERSE_STMT(CompoundLiteralExpr, { }) DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {}) DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {}) -DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {}) +DEF_TRAVERSE_STMT(CXXDefaultArgExpr, { + if (getDerived().shouldVisitImplicitCode()) + TRY_TO(TraverseStmt(S->getExpr())); +}) DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {}) DEF_TRAVERSE_STMT(CXXDeleteExpr, {}) DEF_TRAVERSE_STMT(ExprWithCleanups, {}) diff --git a/unittests/Tooling/RecursiveASTVisitorTest.cpp b/unittests/Tooling/RecursiveASTVisitorTest.cpp index 991ae8bb7f..a2aedb6485 100644 --- a/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -152,4 +152,21 @@ TEST(RecursiveASTVisitor, ArrayInitializersAreVisited) { "};\n")); } +// Check to ensure that implicit default argument expressions are visited. +class IntegerLiteralVisitor + : public ExpectedLocationVisitor { +public: + bool VisitIntegerLiteral(const IntegerLiteral *IL) { + Match("literal", IL->getLocation()); + return true; + } +}; + +TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) { + IntegerLiteralVisitor Visitor; + Visitor.ExpectMatch("literal", 1, 15, 2); + EXPECT_TRUE(Visitor.runOver("int f(int i = 1);\n" + "static int k = f();\n")); +} + } // end anonymous namespace