llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic generates incorrect warnings re. to std::map::operator[]

Open adesitter opened this issue 1 year ago • 1 comments

❯ 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.

adesitter avatar Feb 09 '25 17:02 adesitter

@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>

llvmbot avatar Feb 09 '25 17:02 llvmbot