From 1cd076eb34980ae49cf11e5d2c21363269b8a117 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Wed, 19 Aug 2015 21:33:54 +0000 Subject: Fix -Wlogical-not-parentheses to work better with C code. Remove the assumption of a Boolean type by checking if an expression is known to have a boolean value. Disable warning in two other tests. llvm-svn: 245507 --- clang/lib/Sema/SemaExpr.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0d3913448f3..76b9aecdac8 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -8374,19 +8374,16 @@ static void diagnoseLogicalNotOnLHSofComparison(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc) { - // This checking requires bools. - if (!S.getLangOpts().Bool) return; - // Check that left hand side is !something. UnaryOperator *UO = dyn_cast(LHS.get()->IgnoreImpCasts()); if (!UO || UO->getOpcode() != UO_LNot) return; // Only check if the right hand side is non-bool arithmetic type. - if (RHS.get()->getType()->isBooleanType()) return; + if (RHS.get()->isKnownToHaveBooleanValue()) return; // Make sure that the something in !something is not bool. Expr *SubExpr = UO->getSubExpr()->IgnoreImpCasts(); - if (SubExpr->getType()->isBooleanType()) return; + if (SubExpr->isKnownToHaveBooleanValue()) return; // Emit warning. S.Diag(UO->getOperatorLoc(), diag::warn_logical_not_on_lhs_of_comparison) -- cgit v1.2.3