From 2574f8830c81c9846e897db853cc2312cbaaae93 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 28 Apr 2014 00:20:16 +0000 Subject: [PATCH] [SemaCXX] Silence -Wconstant-logical-operand if the operand is a 0/1 from a macro. 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 | 3 ++- test/SemaCXX/expressions.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 6d624adc4e..595770dc36 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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() diff --git a/test/SemaCXX/expressions.cpp b/test/SemaCXX/expressions.cpp index 25a9c84172..1a50c99c59 100644 --- a/test/SemaCXX/expressions.cpp +++ b/test/SemaCXX/expressions.cpp @@ -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}} +} -- 2.40.0