[clang-tools-extra] [clang-tidy] Enable C99 in `implicit-bool-conversion` and avoid FP with `bool` operands in C23 (PR #171070)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 7 17:20:52 PST 2025
================
@@ -75,20 +75,10 @@ void implicitConversionFromBoolInComplexBoolExpressions() {
bool anotherBoolean = false;
int integer = boolean && anotherBoolean;
- // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: implicit conversion 'bool' -> 'int'
- // CHECK-MESSAGES: :[[@LINE-2]]:28: warning: implicit conversion 'bool' -> 'int'
- // CHECK-FIXES: int integer = (int)boolean && (int)anotherBoolean;
-
float floating = (boolean || anotherBoolean) * 0.3f;
- // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: implicit conversion 'bool' -> 'int'
- // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: implicit conversion 'bool' -> 'int'
- // CHECK-FIXES: float floating = ((int)boolean || (int)anotherBoolean) * 0.3f;
-
double doubleFloating = (boolean && (anotherBoolean || boolean)) * 0.3;
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: implicit conversion 'bool' -> 'int'
- // CHECK-MESSAGES: :[[@LINE-2]]:40: warning: implicit conversion 'bool' -> 'int'
- // CHECK-MESSAGES: :[[@LINE-3]]:58: warning: implicit conversion 'bool' -> 'int'
- // CHECK-FIXES: double doubleFloating = ((int)boolean && ((int)anotherBoolean || (int)boolean)) * 0.3;
+ // CHECK-FIXES: double doubleFloating = ((int)boolean && (anotherBoolean || boolean)) * 0.3;
----------------
zeyi2 wrote:
`(anotherBoolean || boolean)` returns an `int` type result, while `boolean` is `bool`, so there is an implicit conversion and should get a warning.
https://github.com/llvm/llvm-project/pull/171070
More information about the cfe-commits
mailing list