From: Argyrios Kyrtzidis Date: Fri, 22 Apr 2011 19:16:27 +0000 (+0000) Subject: For -Wlogical-op-parentheses, point at '&&', not '||'. Fixes rdar://9125333. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a61aedc48efae959d951d2aadadbac3e6d49acc5;p=clang For -Wlogical-op-parentheses, point at '&&', not '||'. Fixes rdar://9125333. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130009 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0e0bf435b2..a773c3a817 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -8788,14 +8788,13 @@ static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc, /// in parentheses. static void EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc, - Expr *E) { - assert(isa(E) && - cast(E)->getOpcode() == BO_LAnd); - SuggestParentheses(Self, OpLoc, + BinaryOperator *Bop) { + assert(Bop->getOpcode() == BO_LAnd); + SuggestParentheses(Self, Bop->getOperatorLoc(), Self.PDiag(diag::warn_logical_and_in_logical_or) - << E->getSourceRange(), + << Bop->getSourceRange() << OpLoc, Self.PDiag(diag::note_logical_and_in_logical_or_silence), - E->getSourceRange(), + Bop->getSourceRange(), Self.PDiag(0), SourceRange()); } diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c index b45d8512f6..a25ded66a6 100644 --- a/test/Sema/parentheses.c +++ b/test/Sema/parentheses.c @@ -26,7 +26,8 @@ void bitwise_rel(unsigned i) { (void)(i == 1 | i == 2 | i == 3); (void)(i != 1 & i != 2 & i != 3); - (void)(i || i && i); // expected-warning {{'&&' within '||'}} \ + (void)(i || + i && i); // expected-warning {{'&&' within '||'}} \ // expected-note {{place parentheses around the '&&' expression to silence this warning}} (void)(i || i && "w00t"); // no warning. (void)("w00t" && i || i); // no warning.