<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107281>107281</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
False-positive const-correctness warning would cause compiler error (functor with default args)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hgrattenthaler
</td>
</tr>
</table>
<pre>
The following code (minimal, marked otherwise) causes clang-tidy to suggest a const-fix which obviously does not compile. It seems to be related to calls to functions taking default arguments of type `std::function<>`. Does **not** reproduce if you take out any of the following:
* the call to `functor`, utilizing the default value
* the argument of `functor` having a default value
* changing the type of the argument of `functor` to any primitive types
```C++
#include <functional>
template <typename function_t = std::function<void()>>
void functor(function_t && f = [](){}) {
//not minimal, but isolates the erroneous const-correctness warning
static_cast<void>(f);
}
int main( ) {
functor();
bool x = false; //<-- erroneous warning: variable 'x' of type 'bool' can be declared 'const'
x = true;
//not minimal, but isolates the erroneous const-correctness warning
static_cast<void>(x);
}
```
**Expected behavior**: clang-tidy does not warn
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VE1v6zgM_DXKhUjgyEkcH3xImwbY-94fZJm2tU-WAonKx_76BR27dYHX6wJG3UjmcDgcUsVoOodYif2b2J9XKlHvQ9V3QRGho15ZDKvaN8_q7x6h9db6u3EdaN8gCHkcjDODskK-w6DCb2zAU4_hbiIKWYJWKWIEbZXr1mSaJ5CHmLoOI4EC7V2kdWsecO-N7sHXN-NTtE9oPEZwnkD74WosbuAvgog4REaoEQJaRdjwL62sHY_b5DQZ7yKQ-s0sG2xVsgQqdGlARxF8C_S8IohDFqkR-UnkpzlM5O8i_xCHbANnTi_kSciT8_T6BwJeg2-SRjAtPH3iLAg-ESj3HJGXEjF2dhbZGMo3TJNZikM2ZvRBHDIWLpGx5l_my5_NnG_KJvyOMJfBub6hQK9uHK9-ita9ct2cYRRgovszJP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