[ASTMatchers] Existing matcher hasAnyArgument fixed
Summary: A checker (will be uploaded after this patch) needs to check implicit casts. The checker needs matcher hasAnyArgument but it ignores implicit casts and parenthesized expressions which disables checking of implicit casts for arguments in the checker. However the documentation of the matcher contains a FIXME that this should be removed once separate matchers for ignoring implicit casts and parenthesized expressions are ready. Since these matchers were already there the fix could be executed. Only one Clang checker was affected which was also fixed (ignoreParenImpCasts added) and is separately uploaded. Third party checkers (not in the Clang repository) may be affected by this fix so the fix must be emphasized in the release notes.
Reviewers: klimek, sbenza, alexfh
Subscribers: alexfh, klimek, xazax.hun, cfe-commits
Differential Revision: http://reviews.llvm.org/D18243
llvm-svn: 264855
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index fc98373..a346179 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1633,10 +1633,15 @@
TEST(Matcher, AnyArgument) {
StatementMatcher CallArgumentY = callExpr(
- hasAnyArgument(declRefExpr(to(varDecl(hasName("y"))))));
+ hasAnyArgument(
+ ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y")))))));
EXPECT_TRUE(matches("void x(int, int) { int y; x(1, y); }", CallArgumentY));
EXPECT_TRUE(matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY));
EXPECT_TRUE(notMatches("void x(int, int) { x(1, 2); }", CallArgumentY));
+
+ StatementMatcher ImplicitCastedArgument = callExpr(
+ hasAnyArgument(implicitCastExpr()));
+ EXPECT_TRUE(matches("void x(long) { int y; x(y); }", ImplicitCastedArgument));
}
TEST(ForEachArgumentWithParam, ReportsNoFalsePositives) {