<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - forEachArgumentWithParam AST matcher silently discards casts and parentheses"
   href="https://bugs.llvm.org/show_bug.cgi?id=42937">42937</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>forEachArgumentWithParam AST matcher silently discards casts and parentheses
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dbeer1@bloomberg.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>-- Overview --

The forEachArgumentWithParam AST matcher internally ignores casts and
parentheses before matching each argument. This behavior is not documented
anywhere, and makes the matcher unusable if those expressions need to be
captured.

The offending line of code is here, where ignoreParenCasts is called on the
argument before matching it:
<a href="https://github.com/llvm-mirror/clang/blob/release_90/include/clang/ASTMatchers/ASTMatchers.h#L3935">https://github.com/llvm-mirror/clang/blob/release_90/include/clang/ASTMatchers/ASTMatchers.h#L3935</a>

This behavior should at least be documented, but it would be nice if there was
a way to use the matcher without automatically skipping all casts.

-- How to replicate --

$ cat >test.cpp <<EOF
void foo(int);

void bar(int x)
{
  foo(static_cast<int>(static_cast<short>(x)));
}

$ clang-query test.cpp
clang-query> m
callExpr(forEachArgumentWithParam(explicitCastExpr().bind("cast"), anything()))

-- Expected results --

The explicit cast expression in the first argument will be matched.

-- Actual results --

No matches found.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>