llvm-project
llvm-project copied to clipboard
[clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic fails to detect a case of pointer arithmetic
Considering
#include <vector>
auto f1(std::vector<int*> const& ind, int i, int j)
{
// **Not** detected by cppcoreguidelines-pro-bounds-pointer-arithmetic
return ind[i][j];
}
auto f2(std::vector<int*> const& ind, int i, int j)
{
auto i0 = ind[i];
// Detected by cppcoreguidelines-pro-bounds-pointer-arithmetic
return i0[j];
}
❯ clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 20.1.0
Optimized build.
❯ clang-tidy "--checks=-*,cppcoreguidelines-pro-bounds-pointer-arithmetic" -quiet m.cpp --
12 warnings generated.
/tmp/m.cpp:11:10: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
11 | return i0[j];
| ^
clang-tidy fails to spot the issue in the first case (ind[i][j]).
@llvm/issue-subscribers-clang-tidy
Author: Arnaud Desitter (adesitter)
Considering
```
#include <vector>
auto f1(std::vector<int*> const& ind, int i, int j)
{
// **Not** detected by cppcoreguidelines-pro-bounds-pointer-arithmetic
return ind[i][j];
}
auto f2(std::vector<int*> const& ind, int i, int j)
{
auto i0 = ind[i];
// Detected by cppcoreguidelines-pro-bounds-pointer-arithmetic
return i0[j];
}
❯ clang-tidy --version LLVM (http://llvm.org/): LLVM version 20.1.0 Optimized build.
❯ clang-tidy "--checks=-*,cppcoreguidelines-pro-bounds-pointer-arithmetic" -quiet m.cpp -- 12 warnings generated. /tmp/m.cpp:11:10: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] 11 | return i0[j]; | ^
clang-tidy fails to spot the issue in the first case (`ind[i][j]`).
</details>