Issue 97835
Summary [Clang-Tidy] readability-use-std-min-max should consider `std::clamp`
Labels enhancement, clang-tidy
Assignees
Reporter SunBlack
    Tried the new check `readability-use-std-min-max` of the upcoming Clang-Tidy 19.

In one case we had following code:
```cpp
if (ratio < 0.0F)
{
	ratio = 0.0F;
}
if (ratio > 1.0F)
{
	ratio = 1.0F;
}
```

Running `run-clang-tidy-19  -header-filter='.*' -checks='-*,readability-use-std-min-max' -fix` results in:
```cpp
ratio = std::max(ratio, 0.0F);
ratio = std::min(ratio, 1.0F);
```

But in this case it would be better
```cpp
ratio = std::clamp(ratio, 0.0F, 1.0F);
```

I don't know how complex it would be to recognize this pattern, i.e. whether it is better to introduce a `readability-use-std-clamp`, even if this may require a second pass, or whether this can be combined by changing the check to `readability-use-std-min-max-clamp`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to