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

    <tr>
        <th>Summary</th>
        <td>
            `misc-const-correctness` false positive with variable in template
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    ```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;
    ~~~~ ^  ~
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVE1zmzAQ_TXiookHhEH4wCFp7EuPzb0jxGKrlSVGEk7SX98VBJukdiczYYSQ9vNp96HGtq81KdNpyL4n6SNJ7wnLlZF6aIGS_Jv3wYE4knx7VRucMvuLcpwDHHstAqBeauE9fUID6oMISuKnJfk9jsmVBvtjisGqJxoI27xF4g_TguJz9rGT0wSJxh3JHyhhOxz0WTgTA53doj6CxIGR80VAB2FwZjRYxSCsiolnC8Ifl8e5hRiTVsoEqr4C2tj_41ZfwT0W_GRVS7s3039hLuqfLYMtdbuPykummT3LxB-FSBM7OAmRJvl9iW-B7_ncuDwJp0SjkVKMjwVinNqOhtd-FF0vZTRCYOK3iDaN8Er-fG-A_DsIF9MyjvCpFIY2QFtAWjpoo5u0xocxUvFwVF7ejQKcnQMZDHhPiscvM5EU28vmyjOhuF3RQwi9j4nH-HvbNlaHlXXYtd0ffCuTfa_abvuydNqpl5GuB5gBIX_8oIOnylCBSY-90uAoOGddjH4NwKxEn5PQSCXbgxOm9cgO2igj3CuFlx4je2UNHXk2VfVGsd63bbL8TPMwZ3TQFs8Rp0n8mb-d8O15xFZMkveHTaDOyjJjxTqteNLWebvJNyIJKmiId-QNbpQp7YT2QHvrVVAnLLUKhwufsdDzbZgMTtcfGom2Q7PCRuBG69P8ueud_YUpcKu8H8DjouBsw5NDzdO8rFouxUZkeVmKRnRVti5ZwdedhJYnWjSgfY18RuYmqmYpY2nF8ixjVcpX67LJUCQ3nKdVxjuyTuEolF7FxJFSiatHDM2w96jUygd_UeJ1rvYGYI4vhnCwru6Ug2dxgmTEW49g_wJNj9zl">