Skip to content

clang-tidy "cppcoreguidelines-pro-bounds-pointer-arithmetic" false negative #139241

@adesitter

Description

@adesitter

❯ clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 20.1.2
Optimized build.

❯ cat g.cpp

#include <span>

auto g1(std::span<int> s, std::size_t i) {
    // pointer arithmetic **not** detected
    return *(s.data() + i);
}

auto g2(std::span<int> s, std::size_t i) {
    auto p = s.data();
    // pointer arithmetic detected
    return *(p + i);
}

❯ clang-tidy "--checks=-*,cppcoreguidelines-pro-bounds-pointer-arithmetic" -quiet g.cpp -- -std=c++20 --gcc-toolchain=/usr/local/gcc-15

4 warnings generated.
.../g.cpp:11:16: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
   11 |     return *(p + i);
      |                ^

The usage of pointer arithmetic in function g1 is not detected.

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