File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,8 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
152
152
return " false" ;
153
153
}
154
154
155
- if (const auto *IntLit = dyn_cast<IntegerLiteral>(Expression)) {
155
+ if (const auto *IntLit =
156
+ dyn_cast<IntegerLiteral>(Expression->IgnoreParens ())) {
156
157
return (IntLit->getValue () == 0 ) ? " false" : " true" ;
157
158
}
158
159
@@ -385,7 +386,7 @@ void ImplicitBoolConversionCheck::handleCastFromBool(
385
386
<< DestType;
386
387
387
388
if (const auto *BoolLiteral =
388
- dyn_cast<CXXBoolLiteralExpr>(Cast->getSubExpr ())) {
389
+ dyn_cast<CXXBoolLiteralExpr>(Cast->getSubExpr ()-> IgnoreParens () )) {
389
390
Diag << tooling::fixit::createReplacement (
390
391
*Cast, getEquivalentForBoolLiteral (BoolLiteral, DestType, Context));
391
392
} else {
Original file line number Diff line number Diff line change @@ -416,7 +416,8 @@ Changes in existing checks
416
416
- Improved :doc: `readability-implicit-bool-conversion
417
417
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take
418
418
do-while loops into account for the `AllowIntegerConditions ` and
419
- `AllowPointerConditions ` options.
419
+ `AllowPointerConditions ` options. It also now provides more consistent
420
+ suggestions when parentheses are added to the return value.
420
421
421
422
- Improved :doc: `readability-non-const-parameter
422
423
<clang-tidy/checks/readability/non-const-parameter>` check to ignore
Original file line number Diff line number Diff line change @@ -472,6 +472,36 @@ bool f(S& s) {
472
472
473
473
} // namespace ignore_1bit_bitfields
474
474
475
+ int implicitConversionReturnInt ()
476
+ {
477
+ return true ;
478
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion bool -> 'int'
479
+ // CHECK-FIXES: return 1
480
+ }
481
+
482
+ int implicitConversionReturnIntWithParens ()
483
+ {
484
+ return (true );
485
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion bool -> 'int'
486
+ // CHECK-FIXES: return 1
487
+ }
488
+
489
+
490
+ bool implicitConversionReturnBool ()
491
+ {
492
+ return 1 ;
493
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion 'int' -> bool
494
+ // CHECK-FIXES: return true
495
+ }
496
+
497
+ bool implicitConversionReturnBoolWithParens ()
498
+ {
499
+ return (1 );
500
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion 'int' -> bool
501
+ // CHECK-FIXES: return true
502
+ }
503
+
504
+
475
505
namespace PR47000 {
476
506
int to_int (bool x) { return int {x}; }
477
507
You can’t perform that action at this time.
0 commit comments