llvm / llvm/llvm-project

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

Open
#190,665 5 comments 3 reactions 0 assignees View on GitHub
check-request clang-tidy
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I have been working on migrating a codebase to C++20 and came across several instances of `x >= std::numeric_limits::min() && x <= std::numeric_limits::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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.