]> granicus.if.org Git - clang/commitdiff
[RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr
authorMalcolm Parsons <malcolm.parsons@gmail.com>
Wed, 26 Oct 2016 20:39:54 +0000 (20:39 +0000)
committerMalcolm Parsons <malcolm.parsons@gmail.com>
Wed, 26 Oct 2016 20:39:54 +0000 (20:39 +0000)
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

include/clang/AST/RecursiveASTVisitor.h
unittests/Tooling/RecursiveASTVisitorTest.cpp

index 2129d7092f6e6a03576c09d6dac263ab9df2444f..99f46c7c8a55e1b31390706a84ccf8832c63d724 100644 (file)
@@ -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, {})
index 991ae8bb7f3d274a2879675d6f5edad27db6c6b5..a2aedb64859882b346f24633b92ad006574f07d3 100644 (file)
@@ -152,4 +152,21 @@ TEST(RecursiveASTVisitor, ArrayInitializersAreVisited) {
                       "};\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