[clang-tidy] readability-implicit-bool-conversion.AllowIntegerConditions ignores DoStmts

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D157428
This commit is contained in:
Fabian Wolff 2023-08-08 23:07:10 +02:00
parent 81ccfeb86a
commit f263f45ba6
3 changed files with 10 additions and 1 deletions

View File

@ -228,7 +228,8 @@ bool isCastAllowedInCondition(const ImplicitCastExpr *Cast,
if (!S)
return false;
if (isa<IfStmt>(S) || isa<ConditionalOperator>(S) || isa<ForStmt>(S) ||
isa<WhileStmt>(S) || isa<BinaryConditionalOperator>(S))
isa<WhileStmt>(S) || isa<DoStmt>(S) ||
isa<BinaryConditionalOperator>(S))
return true;
if (isa<ParenExpr>(S) || isa<ImplicitCastExpr>(S) ||
isUnaryLogicalNotOperator(S) ||

View File

@ -196,6 +196,11 @@ Changes in existing checks
<clang-tidy/checks/readability/identifier-naming>` check to emit proper
warnings when a type forward declaration precedes its definition.
- Improved :doc:`readability-implicit-bool-conversion
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take
do-while loops into account for the `AllowIntegerConditions` and
`AllowPointerConditions` options.
Removed checks
^^^^^^^^^^^^^^

View File

@ -38,6 +38,9 @@ void implicitConversionIntegerToBoolInConditionalsIsAllowed() {
while (functionReturningInt()) {}
while (functionReturningPointer()) {}
while (functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer())) {}
do {} while (functionReturningInt());
do {} while (functionReturningPointer());
do {} while (functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer()));
int value1 = functionReturningInt() ? 1 : 2;
int value2 = !functionReturningInt() ? 1 : 2;
int value3 = (functionReturningInt() && functionReturningPointer() || !functionReturningInt()) ? 1 : 2;