| Issue |
208708
|
| Summary |
[clang-tidy] readability-use-std-min-max may add empty _expression_ statement and remove comment
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
e-kwsm
|
clang-tidy 22.1.8
```cpp
void f(int &n) {
if (n < -1) n = -1 ;
if (n > 1) n = 1/*use `clamp` when c++17 or later is enabled*/;
}
```
```console
$ clang-tidy --checks=readability-use-std-min-max --fix a.cpp
a.cpp:2:3: warning: use `std::max` instead of `<` [readability-use-std-min-max]
1 | void f(int &n) {
2 | if (n < -1) n = -1 ;
| ^~~~~~~~~~~~~~~~~~
| n = std::max(n, -1);
a.cpp:1:1: note: FIX-IT applied suggested code changes
1 | void f(int &n) {
| ^
a.cpp:2:3: note: FIX-IT applied suggested code changes
2 | if (n < -1) n = -1 ;
| ^
a.cpp:3:3: warning: use `std::min` instead of `>` [readability-use-std-min-max]
3 | if (n > 1) n = 1/*use `clamp` when c++17 or later is enabled*/;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| n = std::min(n, 1);
a.cpp:3:3: note: FIX-IT applied suggested code changes
clang-tidy applied 3 of 3 suggested fixes.
```
The function body becomes
```cpp
n = std::max(n, -1); ;
n = std::min(n, 1);;
```
<https://godbolt.org/z/sEz5qoTnq>
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs