]> granicus.if.org Git - clang/commitdiff
[SemaCXX] Silence -Wconstant-logical-operand if the operand is a 0/1 from a macro.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Apr 2014 00:20:16 +0000 (00:20 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Apr 2014 00:20:16 +0000 (00:20 +0000)
Libraries specify enabled/disabled features using macro defs of 0/1, in such cases the -Wconstant-logical-operand
is noise.

rdar://15410291

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207386 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/expressions.cpp

index 6d624adc4eb115de29eb4445e780b2a3b0a391f7..595770dc36bf0a833b3bc6e1879aad14d92daa98 100644 (file)
@@ -8268,7 +8268,8 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14]
     // Parens on the RHS are ignored.
     llvm::APSInt Result;
     if (RHS.get()->EvaluateAsInt(Result, Context))
-      if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType()) ||
+      if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
+           !RHS.get()->getExprLoc().isMacroID()) ||
           (Result != 0 && Result != 1)) {
         Diag(Loc, diag::warn_logical_instead_of_bitwise)
           << RHS.get()->getSourceRange()
index 25a9c841725c1c513dab64b24e1164fc214aafa7..1a50c99c590471085c6c6d507c3ed31219557164 100644 (file)
@@ -125,3 +125,13 @@ namespace pr16992 {
     return (sizeof T());
   }
 }
+
+void test4() {
+  #define X 0
+  #define Y 1
+  bool r1 = X || Y;
+
+  #define Y2 2
+  bool r2 = X || Y2; // expected-warning {{use of logical '||' with constant operand}} \
+                     // expected-note {{use '|' for a bitwise operation}}
+}