Issue |
132931
|
Summary |
clang-tidy suggests adding const to arrays that are already const
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
hvdijk
|
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
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs