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

    <tr>
        <th>Summary</th>
        <td>
            clang 15.0.1: misc-const-correctness mislead by template function yields false-positive for uninvolved variable
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Due to findings in our code we created a small example which demonstrates that the clang-tidy check misc-const-correctness emits a false-positive warning for a variable which is not involved in the template function:
```c++
#include <functional>

template<typename T>
void function(const std::function<void (const T&)> p_function=[](const T&) { /* do nothing */ })
{
    const T value = T();
    if (p_function)
        p_function(value);
}

int main()
{
    unsigned int value=0U;
    value=1U;
    function<float>(); // warning regarding 'value'
    //function<float>(nullptr); // no warning
    return EXIT_SUCCESS;
}
```
This is the warning:
```console
<source>:13:5: warning: variable 'value' of type 'unsigned int' can be declared 'const' [misc-const-correctness]](javascript:;)
    unsigned int value=0U;
    ^
                 const
```
The example can bee seen/tested here: https://godbolt.org/z/aYrnn3sbr
If `function()` is called with `nullptr` as argument then no warning is emitted.
Note that in our case we got a false-positive warning for each non-const variable inside the method, i.e. all were affected.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVMFu2zgQ_Rr5QkSgJduyDjo4dgL00ktSoD0VFDmS2FKkQVJOvV-_Q8qy5SS7qGDLJmf4-Djz-GojztVhAOINaaQWUreOSE3MYAk3AsgbEG6BeRCEEdczpQj8Yf1RYaiTvCMCeqOdt5jiiO-YxxeuUUy3D16KM-Ed8N-kl44_8JCJb2uBew3OEeild4jcMOXg4Wic9PKE0MxqpEIaYzF4Ylay-rqjdEQbjyxPRp2QF9INW3pAVsiCNIPmXhqd5LuEHhK6SzZ0_PAkewyfcTbLpeZqwEMm-X5axFSSP10S4nuCxRx_PoJmPZDX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