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

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] misc-const-correctness false positive for map insertion with key from templated function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy,
            false-positive
      </td>
    </tr>

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

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

<pre>
    It seems there's a false positive for misc-const-correctness when insertion into a map occurs with a key coming from a templated function.

`#include <unordered_map>

template <typename T>
int f()
{
    return 3;
}

template <typename T>
void func()
{
    std::unordered_map<int, int> map;

    map[f<T>()] = 3;
}

int main() {
 func<int>();
}
`
Reproducer in godbolt: https://godbolt.org/z/xYT5z1hnf.

Of course, adding const to the map will cause a compilation error.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEU01v4zgM_TX0hUigSLFdH3zIRwPsaYFFL3sayDIVaypLhiSnk_76gZx0pmg7GMCAbYl8fCTfkzGasyNqodxDeSzknAYf2ulZal10vr-2_ySMRGPENFAg4HVEiVraSDj5aJK5EGofcDRRrZR3Ma2UD4FUchQjvgzk0LhIIRmfv5JHiaOc0Cs1h4gvJg0o8ZmuqPxo3Bl18CNKTDROVibqUc9O5ew1sF1-KgZcGKfs3BOCOMzOh54C9d9GOYF4vIW95eeIdJ3IyZHw6XZtXEIN_AF4k4PrPbAdImKgNAeHAsR-OT_-HerizY3hF3Ax9SB2IHYfGB6MS8APeRogHnE5299K5bT8X-41iMNS44ZbHhHE8RO13MkojbtF4b32wudW5hfA-7yKAdv9R1Pw_awooHF49n3nbQKxwyGlKWbi_AT8dL9Y-3AGfnoFfvrx_1P5uhmcvi_kX43KzyFS7kn2fV7iogRMPstmWfeLsRaVnCOhzJuejJWLJCgEH9ZF34q-EY0sqN3UomnKpqzqYmirbSe7SpWdfNjIpmnKkmnNdCW2df0gtqwwLWe8ZHzTbBirWL3utGpYL-uGGtLUEWwZjdLYtbWXMbdRmBhnaje8ruuqsLIjGxcDcK6sdOdVMv0VOAd-AM4Xra_etJ6Py2MR2gy26uZzhC2zJqb4Gz6ZZBdHvUMrj39yyFdektM7zywOyf5YjPHZFsUcbPthZyYNc7dWfgR-yrzur9UU_HdSCfhpmUEEfrqP4dLynwEAAP__QzZJLg">