diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index f0fca30de3b3c..672f28721114c 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -274,8 +274,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { allOf(anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)), hasSourceExpression(cxxBoolLiteral()))), - hasSourceExpression(expr(hasType(booleanType()))), - unless(ExceptionCases)); + hasSourceExpression(expr(hasType(booleanType())))); auto BoolXor = binaryOperator(hasOperatorName("^"), hasLHS(ImplicitCastFromBool), hasRHS(ImplicitCastFromBool)); @@ -315,7 +314,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { traverse( TK_AsIs, implicitCastExpr( - ImplicitCastFromBool, + ImplicitCastFromBool, unless(ExceptionCases), // Exclude comparisons of bools, as they are always cast to // integers in such context: // bool_expr_a == bool_expr_b diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b4d87e0ed2a67..f7274229bf52c 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -478,7 +478,8 @@ Changes in existing checks ` check to take do-while loops into account for the `AllowIntegerConditions` and `AllowPointerConditions` options. It also now provides more consistent - suggestions when parentheses are added to the return value. + suggestions when parentheses are added to the return value. It also ignores + false-positives for comparison containing bool bitfield. - Improved :doc:`readability-misleading-indentation ` check to ignore diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-allow-in-conditions.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-allow-in-conditions.cpp index e393e297140cb..48984d2932287 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-allow-in-conditions.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-allow-in-conditions.cpp @@ -12,6 +12,7 @@ int* functionReturningPointer(); struct Struct { int member; unsigned bitfield : 1; + bool boolfield : 1; }; @@ -28,6 +29,8 @@ void implicitConversionIntegerToBoolInConditionalsIsAllowed() { if (!s.member) {} if (s.bitfield) {} if (!s.bitfield) {} + if (s.boolfield == true) {} + if (s.boolfield != true) {} if (functionReturningInt()) {} if (!functionReturningInt()) {} if (functionReturningInt() && functionReturningPointer()) {}