Index: docs/LibASTMatchersReference.html
===================================================================
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -3636,11 +3636,6 @@
matches x(1, y, 42)
with hasAnyArgument(...)
matching y
-
-FIXME: Currently this will ignore parentheses and implicit casts on
-the argument before applying the inner matcher. We'll want to remove
-this to allow for greater control by the user once ignoreImplicit()
-has been implemented.
@@ -3907,11 +3902,6 @@
matches x(1, y, 42)
with hasAnyArgument(...)
matching y
-
-FIXME: Currently this will ignore parentheses and implicit casts on
-the argument before applying the inner matcher. We'll want to remove
-this to allow for greater control by the user once ignoreImplicit()
-has been implemented.
Index: docs/ReleaseNotes.rst
===================================================================
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -119,6 +119,12 @@
AST Matchers
------------
+- hasAnyArgument: Matcher no longer ignores parentheses and implicit casts on
+ the argument before applying the inner matcher. The fix was done allow for
+ greater control by the user. In all existing checkers that use this matcher
+ all instances of code hasAnyArgument() must be changed to
+ hasAnyArgument(ignoringParenImpCasts()).
+
...
libclang
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2989,18 +2989,13 @@
/// matches x(1, y, 42)
/// with hasAnyArgument(...)
/// matching y
-///
-/// FIXME: Currently this will ignore parentheses and implicit casts on
-/// the argument before applying the inner matcher. We'll want to remove
-/// this to allow for greater control by the user once \c ignoreImplicit()
-/// has been implemented.
AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,
AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
CXXConstructExpr),
internal::Matcher, InnerMatcher) {
for (const Expr *Arg : Node.arguments()) {
BoundNodesTreeBuilder Result(*Builder);
- if (InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, &Result)) {
+ if (InnerMatcher.matches(*Arg, Finder, &Result)) {
*Builder = std::move(Result);
return true;
}
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ 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) {