<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/104572>104572</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            detect mismatching argument in predicate
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy,
            check-request
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          firewave
      </td>
    </tr>
</table>

<pre>
    ```cpp
#include <algorithm>
#include <map>
#include <string>

void f()
{
 const std::map<int, std::string> m;
    
    auto it = std::find_if(m.cbegin(), m.cend(), [&](const std::pair<int, std::string>& p){
        return p.second.empty();
    });
 (void)it;
}
```

https://godbolt.org/z/T5jPWov98

The used type in the predicate argument is wrong. It needs to be `std::pair<const int, std::string>`. Depending on the data being stored this might lead to it being copied on each invocation.

This could be fixed by using `decltype(m.cbegin())::value_type` or (starting with C++14) `auto`. But I do not think the latter should be suggested by this check. That should be suggested by `modernize-use-auto` instead so the logic stays in a single place (see #104569).

This should probably be reported if the given argument is a const reference and the type does not match `decltype(<first>)::value_type`. Specifying it by-value is allowed starting with C++11 if "for VT a move is equivalent to a copy" according to https://en.cppreference.com/w/cpp/algorithm/find.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8Vd9v4rgT_2vMy4goTCDAQx5a-CLt21e66u5x5diTxLuOnbUn9Ni__mRDS9trDyFixvbM58fYkTGa3hE1YvMoNseFnHnwoelMoGd5pkXr9aURdXn9qmkS5VGUDwIr45SdNYGoDtL2PhgeRlH977P5UU5fzEQOxvX3yfx79kZDJ3AncH-Lbx-vA1DeRYbIWlQPonrImQ_GscDDPfqaFUZRvewEgPtIzuzBMIjqeN_WGae_m1R4LFRLvXE3DHiAsVDk9P1_kgtrsTkK3H3ANEkT_guUwBqmlGb7Blr6BOI5OJiKSMo7XdA48eVW8h2N7fFdSOAuSSZwb_g1mhZdBy_mvZV4Y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