| Issue |
57297
|
| Summary |
`misc-const-correctness` false positive with variable in template
|
| Labels |
|
| Assignees |
|
| Reporter |
firewave
|
```cpp
#include <sstream>
#include <string>
template<class T> static std::string toString(T t)
{
std::ostringstream ostr; // warning
ostr << t;
return ostr.str();
}
std::string toStringF(int i)
{
std::ostringstream ostr; // no warning
ostr << i;
return ostr.str();
}
static void f()
{
toString(1);
toStringF(1);
}
```
```
<source>:6:5: warning: variable 'ostr' of type 'std::ostringstream' (aka 'basic_ostringstream<char>') can be declared 'const' [misc-const-correctness]
std::ostringstream ostr; // warning
^
const
```
https://godbolt.org/z/8n1K8dfEx
Fixing the warning results in a compiler error:
```
error: invalid operands to binary _expression_ ('const std::ostringstream' (aka 'const basic_ostringstream<char>') and 'long long')
ostr << t;
~~~~ ^ ~
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs