Skip to content

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

@adesitter

Description

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions