[clang-tools-extra] [clang] [llvm] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 19 07:18:01 PST 2024
5chmidti wrote:
> It currently handles this case:
>
> ```
> if (value1 < value2)
> value = value2;
> else
> value = value1;
> ```
When I add
```c++
if (value1 < value2)
value3 = value2;
else
value3 = value1;
```
(just renamed `value` to `value3`) to the tests, the check does not suggest using `value3 = std::max(value1, value2);`.
The example from @felix642 used two different expressions on the LHS of the assignment (`value1 = ` and `value2 = `) and correctly does not emit a diagnostic:
```c++
if(value1 < value2)
value1 = value2;
else
value2 = value1;
```
https://github.com/llvm/llvm-project/pull/77816
More information about the cfe-commits
mailing list