Skip to content

Commit 1859b1d

Browse files
committed
[clang-tidy] Fix false positives about CompoundAssignOperator in readability-implicit-bool-conversion
1 parent 009da92 commit 1859b1d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
8989

9090
const Expr *SubExpr = Cast->getSubExpr();
9191

92-
bool NeedInnerParens = utils::fixit::areParensNeededForStatement(*SubExpr);
92+
bool NeedInnerParens =
93+
utils::fixit::areParensNeededForStatement(*SubExpr->IgnoreImpCasts());
9394
bool NeedOuterParens =
9495
Parent != nullptr && utils::fixit::areParensNeededForStatement(*Parent);
9596

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ Changes in existing checks
381381
declarations and macros in system headers. The documentation is also improved
382382
to differentiate the general options from the specific ones.
383383

384+
- Improved :doc:`readability-implicit-bool-conversion
385+
<clang-tidy/checks/readability/implicit-bool-conversion>` check by correctly
386+
adding parentheses when the inner expression are implicitly converted
387+
multiple times.
388+
384389
- Improved :doc:`readability-qualified-auto
385390
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
386391
`IgnoreAliasing`, that allows not looking at underlying types of type aliases.

clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,13 @@ namespace PR71848 {
547547
// CHECK-FIXES: return static_cast<int>( foo );
548548
}
549549
}
550+
551+
namespace PR161318 {
552+
int AddParenOutsideOfCompoundAssignOp() {
553+
int val = -1;
554+
while(val >>= 7) {
555+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
556+
// CHECK-FIXES: while((val >>= 7) != 0) {
557+
}
558+
}
559+
}

0 commit comments

Comments
 (0)