[clang-tools-extra] [clang] [llvm] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

Bhuminjay Soni via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 19 07:23:31 PST 2024


11happy 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;
> ```

okay, I got your point as of now I have implemented like if it contains else then it will return so working correctly as per implemented but If we want this to suggest I can try.

https://github.com/llvm/llvm-project/pull/77816


More information about the cfe-commits mailing list