Skip to content

[clang-tidy] Add AllowIteratorDecrementIncrement option to cppcoreguidelines-pro-bounds-pointer-arithmetic #154907

@carlosgalvezp

Description

@carlosgalvezp

The check currently warns at this type of code:

while(it != end)
{
   // ...
   ++it;  // warning
}

This is technically correct as per the guidelines. However, this pattern is widespread and the warning creates a fair amount of noise. Noise which may lead to people disabling the check altogether, which leads to missing warnings on more serious types of pointer arithmetic.

Thus, I propose to introduce an option AllowIteratorDecrementIncrement (or similar), off-by-default, to be able to relax the check a bit and allow for these use cases and reduce noise. It can also help enabling the check in different steps, from the more serious cases to the less serious ones.

As an example, the corresponding rule in MISRA C++:2008 does allow these operations as an exception to the rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-tidyenhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions