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
})
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, {})
"};\n"));
}
+// Check to ensure that implicit default argument expressions are visited.
+class IntegerLiteralVisitor
+ : public ExpectedLocationVisitor<IntegerLiteralVisitor> {
+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