forked from OSchip/llvm-project
[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 llvm-svn: 207386
This commit is contained in:
parent
20c5693e9e
commit
d6eb2b9f4d
|
@ -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()
|
||||
|
|
|
@ -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}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue