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

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] `misc-const-correctness` false positive when calling a function with default lambda argument
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

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

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

<pre>
    Hi! Here's minimal repro:

```c++
class A {};
void poison(void(*f)() = []{}) {}
void foo() {
    A a;
    a = {};
 poison();
}
```

I get following warning (godbolt: https://godbolt.org/z/cedY7o5ev):

```
<source>:4:5: warning: variable 'a' of type 'A' can be declared 'const' [misc-const-correctness]
 4 |     A a;
      |     ^
      |       const 
1 warning generated.
```

Even though I assign to `a` on the next line. Something is wrong with calling a function with a function pointer type (or `std::function`) that defaults to a lambda, it completely messes up the check -- note that it does not even use `a` in any way. Following changes would remove the false-positive:

* Removing the argument from `poison` function: https://godbolt.org/z/qvcz4jqE1
* Replacing lambda with `nullptr`: https://godbolt.org/z/cTTW84x15
* Explicitly passing a lambda to the call: https://godbolt.org/z/YEaWjY15r

Thanks in advance! Let me know if any other information is needed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVVFvozgQ_jXOyyiRMRDggYe0TbSVTjrprtKqj8YewK2xWdskzf76kyFJe6vuqhIKzIz9fTPfjB3uveoMYk3yO5I_rPgUeuvqO9s8-r_NQTlcNVae62-KsAS-oUPCCg-DMmrgGhyOzpJ0R-gDodffLV0eQdhdfGav0Nx72AEp7kjxQNKL-2iVhNEqbw1hZbQIKwnbtYRV81cFJH2AJbvL3uhbvt4hWmuvy4sLNADADviNKtp8Qft_Du_8kfTqveHf6vlY5CN0GKC1WtuTMh2cuDPxTVjZWdlYHUi6gz6E0Ud52IGwwyWwsa4j7PCTsINA-Vz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