llvm-project
llvm-project copied to clipboard
[clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic generates incorrect warnings re. to std::map::operator[]
❯ clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 19.1.4
Optimized build.
❯ cat m.cpp
#include <map>
template <typename R>
int f(std::map<R*, int>& map, R* r) {
return map[r];
}
❯ clang-tidy "--checks=-*,cppcoreguidelines-pro-bounds-pointer-arithmetic" -quiet m.cpp --
67 warnings generated.
/workspaces/ix/ct_bug_1/m.cpp:4:14: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
4 | return map[r];
| ^
std::map::operator[] does not involve pointer arithmetic in user code.
@llvm/issue-subscribers-clang-tidy
Author: Arnaud Desitter (adesitter)
```
❯ clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 19.1.4
Optimized build.
❯ cat m.cpp #include <map> template <typename R> int f(std::map<R*, int>& map, R* r) { return map[r]; }
❯ clang-tidy "--checks=-*,cppcoreguidelines-pro-bounds-pointer-arithmetic" -quiet m.cpp -- 67 warnings generated. /workspaces/ix/ct_bug_1/m.cpp:4:14: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] 4 | return map[r]; | ^
`std::map::operator[]` does not involve pointer arithmetic in user code.
</details>