<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74842>74842</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang-Tidy] `misc-const-correctness` False positive on a variable that cannot be `const`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
TedLyngmo
</td>
</tr>
</table>
<pre>
```c++
#include <fstream>
template<class Archive>
void save(Archive& archive) {
std::ofstream output("file");
output << archive;
}
int main() {
double const dval = 3.14159;
save(dval);
}
```
`clang-tidy` suggests that `output` could be declared `const`:
```
const.cpp:5:5: error: variable 'output' of type 'std::ofstream' (aka 'basic_ofstream<char>') can be declared 'const' [misc-const-correctness,-warnings-as-errors]
5 | std::ofstream output("file");
| ^
| const
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycU8uSqzgM_RqxUZEycoCwYJFOblazvPspYxTiGYMp22Sq_37KNHn0PDa3yoDx0eNIOlYhmGFibqH8gPKcqSXenG9_cv_b5zSMLutc_9lCJb6WBvpIS5xBHIGkmbRdekaQp2uIntUI8seGru_I42xVZJAnbVUIePT6Zu78NLs702NQdwY6PDCqUD22DUK95cMQe5BHkEe3JUO3xHmJQAcguhrLQATUgHx4IG4miSHI0zPuwwLq8ztdM0UclZnWiO-pEbF3S2cZtZtCxP6uLII8o9wV-6J8S7nVkgzeqbwSPXr5_NVWTUMeTf8JlcCwDAOHGDDeVESoxFZjJVC7xfbYMfasrfLcJ3jlk8LJ438mWPGdnmeQx3J7kL13Pm3uyhuVygKqH82s0V0xfs7r4b96nnCgg_pTJbhTwejfn5g86ZvyabhUpwZqNX3nS_UX3xSk_BhN0Pl6kGvnPes4cQhAp_wv5SczDSFXIV_JBijPr1mUCPUpbX5NE_h0h_LHP4-_CH5vZda3sm9kozJui1qQ2JcNVdmt5bIuKr4WotPyUBey1PWBa5YsWF5VITLTkiBZkDgUe0mi2jW6qVRVUdf09VXqDvaCR2Xsztr7uHN-yEwIC7f1_rCnzKqObVhvJ9GbUIjSbfVtcsq7ZQiwF9aEGF5hool2vden1e1ncivPSTL_0_ZK4EXZwDi7YKK5M7oJ1UsiqyC1miYX01DftJct3ra3GOeQZkEXoMtg4m3pdtqNQJfEafvks3d_sI5Al7XOAHRZS_07AAD__x1qVw4">