Skip to content

Commit f263f45

Browse files
committed
[clang-tidy] readability-implicit-bool-conversion.AllowIntegerConditions ignores DoStmts
Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D157428
1 parent 81ccfeb commit f263f45

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-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
@@ -228,7 +228,8 @@ bool isCastAllowedInCondition(const ImplicitCastExpr *Cast,
228228
if (!S)
229229
return false;
230230
if (isa<IfStmt>(S) || isa<ConditionalOperator>(S) || isa<ForStmt>(S) ||
231-
isa<WhileStmt>(S) || isa<BinaryConditionalOperator>(S))
231+
isa<WhileStmt>(S) || isa<DoStmt>(S) ||
232+
isa<BinaryConditionalOperator>(S))
232233
return true;
233234
if (isa<ParenExpr>(S) || isa<ImplicitCastExpr>(S) ||
234235
isUnaryLogicalNotOperator(S) ||

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ Changes in existing checks
196196
<clang-tidy/checks/readability/identifier-naming>` check to emit proper
197197
warnings when a type forward declaration precedes its definition.
198198

199+
- Improved :doc:`readability-implicit-bool-conversion
200+
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take
201+
do-while loops into account for the `AllowIntegerConditions` and
202+
`AllowPointerConditions` options.
203+
199204
Removed checks
200205
^^^^^^^^^^^^^^
201206

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ void implicitConversionIntegerToBoolInConditionalsIsAllowed() {
3838
while (functionReturningInt()) {}
3939
while (functionReturningPointer()) {}
4040
while (functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer())) {}
41+
do {} while (functionReturningInt());
42+
do {} while (functionReturningPointer());
43+
do {} while (functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer()));
4144
int value1 = functionReturningInt() ? 1 : 2;
4245
int value2 = !functionReturningInt() ? 1 : 2;
4346
int value3 = (functionReturningInt() && functionReturningPointer() || !functionReturningInt()) ? 1 : 2;

0 commit comments

Comments
 (0)