| Issue |
176212
|
| Summary |
clang-tidy-21 FIX-IT for modernize-use-integer-sign-comparison causes syntax error
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
e8y
|
# Reproduce Steps
## Setup
Create a directory with two files, test.cpp and compile_commands.json, with the following content. (You may need to change the directory in compile_commands.json to use an absolute path.)
**test.cpp**
```cpp
#include <iostream>
struct Foo {
unsigned int n;
unsigned int num() const { return n; }
};
int main() {
Foo foo {3};
for (int i = 0; i < static_cast<int>(foo.num()); ++i) {
std::cout << i << "\n";
}
}
```
**compile_commands.json**
```json
[
{
"directory": ".",
"command": "clang++-21 -std=c++20 -Wall -Wextra -c test.cpp",
"file": "test.cpp"
}
]
```
## Invoke clang-tidy
```
$ clang-tidy-21 -p . --fix --warnings-as-errors='*' --checks='modernize-use-integer-sign-comparison' test.cpp
```
Command output:
```
1 warning generated.
test.cpp:10:21: error: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison,-warnings-as-errors]
2 |
3 | struct Foo {
4 | unsigned int n;
5 | unsigned int num() const { return n; }
6 | };
7 |
8 | int main() {
9 | Foo foo {3};
10 | for (int i = 0; i < static_cast<int>(foo.num()); ++i) {
| ^ ~~~~~~~~~~~~~~~~~~~
| std::cmp_less( , )
test.cpp:2:1: note: FIX-IT applied suggested code changes
2 |
| ^
test.cpp:10:21: note: FIX-IT applied suggested code changes
10 | for (int i = 0; i < static_cast<int>(foo.num()); ++i) {
| ^
test.cpp:10:23: note: FIX-IT applied suggested code changes
10 | for (int i = 0; i < static_cast<int>(foo.num()); ++i) {
| ^
test.cpp:10:52: note: FIX-IT applied suggested code changes
10 | for (int i = 0; i < static_cast<int>(foo.num()); ++i) {
| ^
clang-tidy applied 4 of 4 suggested fixes.
1 warning treated as error
```
**test.cpp** after fix-its:
```
#include <iostream>
#include <utility>
struct Foo {
unsigned int n;
unsigned int num() const { return n; }
};
int main() {
Foo foo {3};
for (int i = 0; std::cmp_less(i ,foo.num())); ++i) {
std::cout << i << "\n";
}
}
```
There is one too many close parents added here which is a syntax error that breaks compilation: `std::cmp_less(i ,foo.num()))`
# Environment
```
$ clang-tidy-21 --version
Ubuntu LLVM version 21.1.8
Optimized build.
$ uname -a
Linux alternating-bike 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.3 LTS
Release: 24.04
Codename: noble
```
I installed LLVM via `./llvm.sh 21 all` downloaded from `https://apt.llvm.org/llvm.sh`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs