<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64113>64113</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang-tidy incorrect misc-const-correctness
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jeremy-rifkin
</td>
</tr>
</table>
<pre>
```cpp
#include <sstream>
#include <type_traits>
auto foo(int t) {
std::ostringstream oss;
oss<<t;
return std::move(oss).str();
}
template<typename T>
std::string stringify(const T& t) {
if constexpr(std::is_arithmetic<T>::value) {
std::ostringstream oss; // <------ line 13
oss<<t;
return std::move(oss).str();
} else {
return "";
}
}
```
```cpp
[<source>:13:9: warning: variable 'oss' of type 'std::ostringstream' (aka 'basic_ostringstream<char>') can be declared 'const' [misc-const-correctness]](javascript:;)
13 | std::ostringstream oss;
| ^
| const
```
https://godbolt.org/z/zf6GGWTq1
This is an incorrect diagnostic, the code can never be valid if `oss` is `const`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVM2S4jgMfhrl4oJKZJKQQw78DPMCXbXHLsdRwD2OzdoOs-zTb9npBqab3dpxGRIs6dOnTzLCe3U0RC2UWyj3mZjCybr2jRyN14VTww9lss721xaqfN7yfIZ8D_kGkCsj9dQTA77zPjgSI_Bvz6zheqbX4IQK_u6RvsUULBusBVwrE1gAbBjU29nImA898A3wjfXBKXOcszDrPfAPp_RjF7Pcz5ijMDlzjx_thQDX0RebpQ8OcA3Y3CKg3j_SCjSetQj0zt2IkdjLjfoNdSbF5ocaroBraY0P7AWw-lIMY2pgyU5_nSOBG47yr8KpcBopKAl8l1Ily0Xoib7gxPWf0jDAA-Ahar9Ii2lliBX8V4yn0s3rdwWMMVDvGWlPX8m-owFi3LeYu-q3l485e-zGk-Ert3Ho7OQkzVoVHPimAb5hP4Uzyhzj60U4JTpNDLBOzGtmBxY7Gk-eKxidANfih4g-nfBKvv7qwHfyJFxMi3VsjRSGdcR6klo46mNY6nJCKrej8nKRDhbSOkcyGPIeyn3cuH4TF-GlU-eQyGyjqB_aFZxBvftft4DNDdh9KM6g_PbZNLP6d51PIZx9zJSG52j7zuqwtO4IePg7fobq-_c_Xv4sHoNeTsoz5ZkwTJn3AlmvxNFYH6cZdyyciEnbU1LK0IVc1OsitOrjlYAqj6VUeYSJXU40q3yZ9S3vG96IjNqianLOV_WKZ6eWd0Q99hUWPZbI12XdyaaucRjyoeFYZarFHHleY5UXWK74Mm9IDoS17IacmnwFq5xGofRS68sYS8yU9xO11aooeKZFR9qnf0VEQz9ZMsbRLfeZa2PMopuOHla5Vj74O0pQQVO708IcF0H11wdNns9BNjndfhJehdPULaUdAQ8R-f2xODv7RjIAHhIfD3hIfP8JAAD__4X_rpI">