]> granicus.if.org Git - clang/commitdiff
For -Wlogical-op-parentheses, point at '&&', not '||'. Fixes rdar://9125333.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 22 Apr 2011 19:16:27 +0000 (19:16 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 22 Apr 2011 19:16:27 +0000 (19:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130009 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0e0bf435b2784c42bb3d6402daaba7c4e59de82b..a773c3a8173083c044302eab06fa11c77188bdb1 100644 (file)
@@ -8788,14 +8788,13 @@ static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc,
 /// in parentheses.
 static void
 EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc,
-                                       Expr *E) {
-  assert(isa<BinaryOperator>(E) &&
-         cast<BinaryOperator>(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());
 }
 
index b45d8512f6bf7f39e1098141728841e40b027ac8..a25ded66a665b1c23333bb07c3ba301ce898028a 100644 (file)
@@ -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.