[clang-tidy] Ignore bool -> single bit bitfield conversion in readability-implicit-bool-conversion
Summary: There is no ambiguity / information loss in this conversion
Reviewers: alexfh, aaron.ballman, hokein
Reviewed By: alexfh
Subscribers: xazax.hun, cfe-commits
Differential Revision: https://reviews.llvm.org/D54941
llvm-svn: 347671
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 1cf1d03..b8ae224 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -306,6 +306,11 @@
auto boolOpAssignment =
binaryOperator(anyOf(hasOperatorName("|="), hasOperatorName("&=")),
hasLHS(expr(hasType(booleanType()))));
+ auto bitfieldAssignment = binaryOperator(
+ hasLHS(memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1))))));
+ auto bitfieldConstruct = cxxConstructorDecl(hasDescendant(cxxCtorInitializer(
+ withInitializer(equalsBoundNode("implicitCastFromBool")),
+ forField(hasBitWidth(1)))));
Finder->addMatcher(
implicitCastExpr(
implicitCastFromBool,
@@ -313,14 +318,15 @@
// in such context:
// bool_expr_a == bool_expr_b
// bool_expr_a != bool_expr_b
- unless(hasParent(binaryOperator(
- anyOf(boolComparison, boolXor, boolOpAssignment)))),
+ unless(hasParent(binaryOperator(anyOf(
+ boolComparison, boolXor, boolOpAssignment, bitfieldAssignment)))),
+ implicitCastExpr().bind("implicitCastFromBool"),
+ unless(hasParent(bitfieldConstruct)),
// Check also for nested casts, for example: bool -> int -> float.
anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
anything()),
unless(isInTemplateInstantiation()),
- unless(hasAncestor(functionTemplateDecl())))
- .bind("implicitCastFromBool"),
+ unless(hasAncestor(functionTemplateDecl()))),
this);
}