diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -8,6 +8,7 @@ #include "ImplicitBoolConversionCheck.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ExprCXX.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" #include "clang/Tooling/FixIt.h" @@ -270,7 +271,9 @@ // Prior to C++11 cast from bool literal to pointer was allowed. allOf(anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)), - hasSourceExpression(cxxBoolLiteral()))), + hasSourceExpression(cxxBoolLiteral())), + hasDescendant(materializeTemporaryExpr( + allOf(hasType(booleanType()), hasDescendant(cxxBoolLiteral()))))), hasSourceExpression(expr(hasType(booleanType()))), unless(ExceptionCases)); auto BoolXor = @@ -282,7 +285,12 @@ anyOf(hasCastKind(CK_IntegralToBoolean), hasCastKind(CK_FloatingToBoolean), hasCastKind(CK_PointerToBoolean), - hasCastKind(CK_MemberPointerToBoolean)), + hasCastKind(CK_MemberPointerToBoolean), + hasSourceExpression(cxxConstructExpr( + hasType(classTemplateSpecializationDecl( + hasName("::std::optional"), + hasTemplateArgument(0, refersToType(booleanType())))), + unless(hasArgument(0, expr(hasType(booleanType()))))))), // Exclude case of using if or while statements with variable // declaration, e.g.: // if (int var = functionCall()) {}