Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] readability-implicit-bool-conversion emits useless fixit for comparisons in C #111013

Open
5chmidti opened this issue Oct 3, 2024 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior clang-tidy

Comments

@5chmidti
Copy link
Contributor

5chmidti commented Oct 3, 2024

In C, the result of a comparison is defined as returning a 1 or a 0 of type int (C N3220 6.5.9.7 & 6.5.10.4).

https://godbolt.org/z/fTErfvzqW

bool foo() { return 1 != 0; }
[<source>:1:21: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]](javascript:;)
    1 | bool foo() { return 1 != 0; }
      |                     ^     
      |                     (     ) != 0
1 warning generated.

The check should probably be adapted to check if the source expression of the cast is a comparison (ignoring parens), and just add a cast instead.

Additionally, a new option could be added to ignore the conversion warning in this case for C.

@5chmidti 5chmidti added bug Indicates an unexpected problem or unintended behavior clang-tidy labels Oct 3, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 3, 2024

@llvm/issue-subscribers-bug

Author: Julian Schmidt (5chmidti)

In C, the result of a comparison is defined as returning a `1` or a `0` of type `int` (C N3220 6.5.9.7 & 6.5.10.4).

https://godbolt.org/z/fTErfvzqW

bool foo() { return 1 != 0; }
[&lt;source&gt;:1:21: warning: implicit conversion 'int' -&gt; 'bool' [readability-implicit-bool-conversion]](javascript:;)
    1 | bool foo() { return 1 != 0; }
      |                     ^     
      |                     (     ) != 0
1 warning generated.

The check should probably be adapted to check if the source expression of the cast is a comparison (ignoring parens), and just add a cast instead.

Additionally, a new option could be added to ignore the conversion warning in this case for C.

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 3, 2024

@llvm/issue-subscribers-clang-tidy

Author: Julian Schmidt (5chmidti)

In C, the result of a comparison is defined as returning a `1` or a `0` of type `int` (C N3220 6.5.9.7 & 6.5.10.4).

https://godbolt.org/z/fTErfvzqW

bool foo() { return 1 != 0; }
[&lt;source&gt;:1:21: warning: implicit conversion 'int' -&gt; 'bool' [readability-implicit-bool-conversion]](javascript:;)
    1 | bool foo() { return 1 != 0; }
      |                     ^     
      |                     (     ) != 0
1 warning generated.

The check should probably be adapted to check if the source expression of the cast is a comparison (ignoring parens), and just add a cast instead.

Additionally, a new option could be added to ignore the conversion warning in this case for C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior clang-tidy
Projects
None yet
Development

No branches or pull requests

2 participants