]> granicus.if.org Git - clang/commitdiff
restrict the && -> & warning to cover a case daniel noted.
authorChris Lattner <sabre@nondot.org>
Thu, 15 Jul 2010 00:26:43 +0000 (00:26 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 15 Jul 2010 00:26:43 +0000 (00:26 +0000)
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

lib/Sema/SemaExpr.cpp
test/Sema/exprs.c

index c06943f6718edbd17b9c7088472a132e84d3e585..5f46a977b12c4ab93b035a475a290d018872b6bf 100644 (file)
@@ -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()
index 54e44693e085b059cded98b7c182916cf00bac3a..9d3da908549faa869ac402f5f9ba220be75b8a8e 100644 (file)
@@ -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.
 }