From: Chris Lattner Date: Thu, 15 Jul 2010 00:26:43 +0000 (+0000) Subject: restrict the && -> & warning to cover a case daniel noted. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23ef3e4f044d701d0f84980fd9816fedf17fc0cb;p=clang restrict the && -> & warning to cover a case daniel noted. Don't warn about "logically bool" expressions on the RHS, even if they fold to a constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108388 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c06943f671..5f46a977b1 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -5742,6 +5742,10 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14] // is a constant. if (lex->getType()->isIntegerType() && !lex->getType()->isBooleanType() && rex->getType()->isIntegerType() && rex->isEvaluatable(Context) && + // Don't warn if the RHS is a (constant folded) boolean expression like + // "sizeof(int) == 4". + !rex->isKnownToHaveBooleanValue() && + // Don't warn in macros. !Loc.isMacroID()) Diag(Loc, diag::warn_logical_instead_of_bitwise) << rex->getSourceRange() diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c index 54e44693e0..9d3da90854 100644 --- a/test/Sema/exprs.c +++ b/test/Sema/exprs.c @@ -144,4 +144,6 @@ void test19() { int test20(int x) { return x && 4; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}} + + return x && sizeof(int) == 4; // no warning. }