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

    <tr>
        <th>Summary</th>
        <td>
            detect `performance-unnecessary-value-param` when used methodd have `const` versions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    ```cpp
#include <algorithm>
#include <vector>

bool f1_a(std::vector<int>v)
{
    return v.size() == 1 && v.front() == 1;
}

bool f1_b(std::vector<int>v)
{
 return v.size() == 1 && *v.begin() == 1;
}

bool f1_c(std::vector<int>v) // warning
{
    return v.size() == 1 && *v.cbegin() == 1;
}

bool f2_a(std::vector<int>v)
{
    return std::any_of(v.begin(), v.end(), [](int i) {
        return i == 1;
 });
}

bool f2_b(std::vector<int>v) // warning
{
    return std::any_of(v.cbegin(), v.cend(), [](int i) {
        return i == 1;
 });
}
```

https://godbolt.org/z/8v9vhdcdq

In all the cases above the given container is never modified so it is possible to change it to a const reference instead.

In case of `begin()`/`end()` the code can be `const`-ified so the warning will be able to catch it. In case of a method like `front()` or `back()` there's is no version that explicitly returns a constant value (like `cfront()` or `cback()`). To trigger this warning the code could awkwardly be changed to use `*cbegin()` or `*std::prev(cback())` instead.

It would be great if it could be detected that no refence to the vector is being used and the warning is triggered.

I assume there's possibly cases for other methods and containers.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vc2OozgQfprKpRQEJiHhwCHdPZH2vveRsQvwtmNnbUM28_QrQ35IT6Se3pVGipKAXfX9lYF7r1pDVMH6BdZvC96HzrqqUY5OfKBFbeW5giKdPuJ4hPQN0h2wXBmhe0kI-SvXrXUqdAfIvz1bH0gE6-6L43dtrcYm-86BbX2QkO8g3113vioTIP82ACsvNZuX6Q8ioqPQO4ND4tUPArYFViLkb5C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