Skip to content

[clang-tidy] Add check to replace x >= min && x <= max with std::in_range #190665

@lakshayg

Description

@lakshayg

I have been working on migrating a codebase to C++20 and came across several instances of x >= std::numeric_limits<T>::min() && x <= std::numeric_limits<T>::max(). Clang-tidy already has a check that can migrate signed/unsigned comparisons to std::cmp_* functions. I think it makes sense to have the std::in_range migration a part of those checks or a new check.

Posting here to check if there’s any interest in having such a checker. If yes, I have an implementation (implemented partially by Claude) that I can clean up and push as a PR in accordance with the AI usage policy.

Post on LLVM Discourse: https://discourse.llvm.org/t/rfc-clang-tidy-check-to-suggest-std-in-range-in-place-of-x-min-x-max/90460

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions