[clang-tools-extra] r302431 - [clang-tidy] Fix readability-implicit-bool-cast false positives
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Mon May 8 08:22:09 PDT 2017
Author: alexfh
Date: Mon May 8 10:22:09 2017
New Revision: 302431
URL: http://llvm.org/viewvc/llvm-project?rev=302431&view=rev
Log:
[clang-tidy] Fix readability-implicit-bool-cast false positives
The patch makes the check treat binary conditional operator (`x ?: y`), `while`
and regular `for` loops as conditional statements for the purpose of
AllowConditional*Cast options.
Modified:
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-cast-allow-conditional-casts.cpp
Modified: clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp?rev=302431&r1=302430&r2=302431&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp Mon May 8 10:22:09 2017
@@ -227,7 +227,8 @@ bool isAllowedConditionalCast(const Impl
const Stmt *S = N.get<Stmt>();
if (!S)
return false;
- if (isa<IfStmt>(S) || isa<ConditionalOperator>(S))
+ if (isa<IfStmt>(S) || isa<ConditionalOperator>(S) || isa<ForStmt>(S) ||
+ isa<WhileStmt>(S) || isa<BinaryConditionalOperator>(S))
return true;
if (isa<ParenExpr>(S) || isa<ImplicitCastExpr>(S) ||
isUnaryLogicalNotOperator(S) ||
Modified: clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-cast-allow-conditional-casts.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-cast-allow-conditional-casts.cpp?rev=302431&r1=302430&r2=302431&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-cast-allow-conditional-casts.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-implicit-bool-cast-allow-conditional-casts.cpp Mon May 8 10:22:09 2017
@@ -27,9 +27,17 @@ void implicitCastIntegerToBoolInConditio
if (!functionReturningInt()) {}
if (functionReturningInt() && functionReturningPointer()) {}
if (!functionReturningInt() && !functionReturningPointer()) {}
+ for (; functionReturningInt(); ) {}
+ for (; functionReturningPointer(); ) {}
+ for (; functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer()); ) {}
+ while (functionReturningInt()) {}
+ while (functionReturningPointer()) {}
+ while (functionReturningInt() && !functionReturningPointer() || (!functionReturningInt() && functionReturningPointer())) {}
int value1 = functionReturningInt() ? 1 : 2;
int value2 = !functionReturningInt() ? 1 : 2;
int value3 = (functionReturningInt() && functionReturningPointer() || !functionReturningInt()) ? 1 : 2;
+ int value4 = functionReturningInt() ?: value3;
+ int *p1 = functionReturningPointer() ?: &value3;
}
void regularImplicitCastPointerToBoolIsNotIgnored() {
More information about the cfe-commits
mailing list