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

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy suggests adding const to arrays that are already const
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

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

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

<pre>
    Given the C++ code
```c++
int foo(int i) {
    const int array[] = {1, 2, 3};
 return array[i];
}
```
The clang-tidy `misc-const-correctness` check reports:
```
$ clang-tidy-21 --checks=misc-const-correctness test.cc
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cc"
No compilation database found in /home/harald or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
1 warning generated.
/home/harald/test.cc:2:5: warning: variable 'array' of type 'const int[3]' can be declared 'const' [misc-const-correctness]
    2 |     const int array[] = {1, 2, 3};
      | ^
      |               const
$ dpkg -l clang-tidy-21
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version                                                      Architecture Description
+++-==============-============================================================-============-=================================
ii clang-tidy-21  1:21~++20250324083552+ec9546d16994-1~exp1~20250324083607.329 amd64        clang-based C++ linter tool
```
Or see it online at https://godbolt.org/z/f6c8E8eeE
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVkuT26gT_zTtS5dcCFmydfBBtkf_x2GylcfuGUNbIoNBC2gm3kM--xaSM_FMJVVJDluroowQ_fv1g-7GIgTdWaItlDsoDwsxxt75bf-o9MeHxdGpy_Y_-pEsxp5wD3wHfIfSKQLWQMXmIefvwBptI56cA75Jbxp4jbBOG4iI0tkQ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