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

FĂ©lix-Antoine Constantin via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 15:37:13 PST 2024


https://github.com/felix642 requested changes to this pull request.

Looks good! I was able run your code on llvm's project and I'm happy with the changes that I see. There is maybe one more use case that we should check before I am ready to approve (Except what Piotr has already highlighted) 

The following code generates an invalid fix :

```
#include <vector>

int main()
{
  std::vector<int> a;
  int b;
  if(a[0] < b)
  {
    a[0] = b;
  }
```
```
#include <vector>

int main()
{
  std::vector<int> a;
  int b;
  a[0] = std::max<value_type>(a[0], b);
}
```
The type of `a` and `b` are considered different by your check. `a` is resolved has value_type instead of int. 

If we are able to fix that I would be ready accept this PR!

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


More information about the cfe-commits mailing list