diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -13600,19 +13600,18 @@ Diag(Loc, diag::warn_enum_constant_in_bool_context); // Diagnose cases where the user write a logical and/or but probably meant a - // bitwise one. We do this when one of the operand is a non-bool integer and - // the other is a constant. - if (!EnumConstantInBoolContext && - LHS.get()->getType()->isIntegerType() && - !LHS.get()->getType()->isBooleanType() && - RHS.get()->getType()->isIntegerType() && - !RHS.get()->isValueDependent() && + // bitwise one. We do this when the LHS is a non-bool integer and the RHS + // is a constant. + if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() && + !LHS.get()->getType()->isBooleanType() && + RHS.get()->getType()->isIntegerType() && !RHS.get()->isValueDependent() && // Don't warn in macros or template instantiations. !Loc.isMacroID() && !inTemplateInstantiation()) { - // If the operand can be constant folded, and if it constant folds to - // something that isn't 0 or 1 (which indicate a potential logical operation - // that happened to fold to true/false) then warn. Parens on the operand are - // ignored. + + // If the RHS can be constant folded, and if it constant folds to something + // that isn't 0 or 1 (which indicate a potential logical operation that + // happened to fold to true/false) then warn. + // Parens on the RHS are ignored. Expr::EvalResult EVResult; if (RHS.get()->EvaluateAsInt(EVResult, Context)) { @@ -13636,25 +13635,21 @@ RHS.get()->getEndLoc())); } } -} - + } // Diagnose cases where the user write a logical and/or but probably meant a - // bitwise one. We do this when one of the operand is a non-bool integer and - // the other is a constant. - if (!EnumConstantInBoolContext && - RHS.get()->getType()->isIntegerType() && - !RHS.get()->getType()->isBooleanType() && - LHS.get()->getType()->isIntegerType() && - !LHS.get()->isValueDependent() && + // bitwise one. We do this when the RHS is a non-bool integer and the LHS + // is a constant. + if (!EnumConstantInBoolContext && RHS.get()->getType()->isIntegerType() && + !RHS.get()->getType()->isBooleanType() && + LHS.get()->getType()->isIntegerType() && !LHS.get()->isValueDependent() && // Don't warn in macros or template instantiations. !Loc.isMacroID() && !inTemplateInstantiation()) { - // If the operand can be constant folded, and if it constant folds to - // something that isn't 0 or 1 (which indicate a potential logical operation - // that happened to fold to true/false) then warn. Parens on the operand are - // ignored. + // If the LHS can be constant folded, and if it constant folds to something + // that isn't 0 or 1 (which indicate a potential logical operation that + // happened to fold to true/false) then warn. + // Parens on the LHS are ignored. Expr::EvalResult EVResult; - if (LHS.get()->EvaluateAsInt(EVResult, Context)) { llvm::APSInt Result = EVResult.Val.getInt(); if ((getLangOpts().Bool && !LHS.get()->getType()->isBooleanType() && @@ -13669,7 +13664,7 @@ SourceRange(Loc, getLocForEndOfToken(Loc)), Opc == BO_LAnd ? "&" : "|"); if (Opc == BO_LAnd) - // Suggest replacing "kNonZero && foo() " with "Foo()" + // Suggest replacing "kNonZero" && Foo() with "Foo()" Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant) << FixItHint::CreateRemoval( SourceRange(getLocForEndOfToken(RHS.get()->getEndLoc()),