3 Commits

Author SHA1 Message Date
Julian Schmidt
605a9adb43
[clang-tidy] fix false positive in modernize-min-max-use-initializer-list (#107649)
Previously, whenever a replacement was generated by the analysis, a
diagnostic was generated. This became an issue when a call to
`std::min` or `std::max` consisted only of an initializer list with at
least one argument to the list requiring a type cast.
In this case, a single replacement that added a `static_cast` was
created,
that resulted in a diagnostic being issued but with no nested call
to `std::min` or `std::max`.

Instead, explicitly track if a nested call was detected and only emit a
diagnostic if this is the case.

Fixes #107594
2024-09-17 10:43:40 +02:00
Julian Schmidt
932f0de43a
[clang-tidy] fix crash due to assumed callee in min-max-use-initializer-list (#91992)
Previously, the call to `findArgs` for a `CallExpr` inside of a `min` or
`max` call would call `findArgs` before checking if the argument is a
call to `min` or `max`, which is what `findArgs` is expecting.
The fix moves the name checking before the call to `findArgs`, such that
only a `min` or `max` function call is used as an argument.

Fixes #91982 
Fixes #92249
2024-05-15 14:52:32 +02:00
Sopy
d3f92e30bb
[clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (#85572)
Identifies cases where `std::min` or `std::max` is used to find the
minimum or maximum value among more than two items through repeated
calls. The check replaces these calls with a single call to `std::min`
or `std::max` that uses an initializer list. This makes the code
slightly more efficient.

Closes #25340
2024-04-25 17:02:45 +02:00