]> granicus.if.org Git - clang/commitdiff
Clarify wording of -Wshift-op-parentheses.
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 19 Oct 2012 18:26:06 +0000 (18:26 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 19 Oct 2012 18:26:06 +0000 (18:26 +0000)
Suggestion from Matt Beaumont-Gay reviewing r165283.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/Sema/parentheses.cpp

index 18600a44463f1f06c683c57b3d22cea1b187aca3..b2779d5cb8c350fe1eaee148f360524345b7555c 100644 (file)
@@ -3865,7 +3865,8 @@ def warn_logical_and_in_logical_or : Warning<
   "'&&' within '||'">, InGroup<LogicalOpParentheses>;
 
 def warn_addition_in_bitshift : Warning<
-  "'%0' within '%1'">, InGroup<ShiftOpParentheses>;
+  "operator '%0' has lower precedence than '%1'; "
+  "'%1' will be evaluated first">, InGroup<ShiftOpParentheses>;
 
 def warn_self_assignment : Warning<
   "explicitly assigning a variable of type %0 to itself">,
index 86091d50a39c542af5e579c096f25c45caebb4ae..b75df8fe8dbf26a175ca8c1eede8d788650c348e 100644 (file)
@@ -8586,12 +8586,12 @@ static void DiagnoseBitwiseAndInBitwiseOr(Sema &S, SourceLocation OpLoc,
 }
 
 static void DiagnoseAdditionInShift(Sema &S, SourceLocation OpLoc,
-                                    Expr *SubExpr, StringRef shift) {
+                                    Expr *SubExpr, StringRef Shift) {
   if (BinaryOperator *Bop = dyn_cast<BinaryOperator>(SubExpr)) {
     if (Bop->getOpcode() == BO_Add || Bop->getOpcode() == BO_Sub) {
       StringRef Op = Bop->getOpcodeStr();
       S.Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift)
-          << Bop->getSourceRange() << OpLoc << Op << shift;
+          << Bop->getSourceRange() << OpLoc << Shift << Op;
       SuggestParentheses(S, Bop->getOperatorLoc(),
           S.PDiag(diag::note_precedence_silence) << Op,
           Bop->getSourceRange());
@@ -8623,9 +8623,9 @@ static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperatorKind Opc,
 
   if ((Opc == BO_Shl && LHSExpr->getType()->isIntegralType(Self.getASTContext()))
       || Opc == BO_Shr) {
-    StringRef shift = BinaryOperator::getOpcodeStr(Opc);
-    DiagnoseAdditionInShift(Self, OpLoc, LHSExpr, shift);
-    DiagnoseAdditionInShift(Self, OpLoc, RHSExpr, shift);
+    StringRef Shift = BinaryOperator::getOpcodeStr(Opc);
+    DiagnoseAdditionInShift(Self, OpLoc, LHSExpr, Shift);
+    DiagnoseAdditionInShift(Self, OpLoc, RHSExpr, Shift);
   }
 }
 
index d0dcdda0bf3b21ef957b19119de2e36033aa3566..8f5f24652dd7140fe4b9e96131a9ed9e7924c8a2 100644 (file)
@@ -49,11 +49,11 @@ void test(S *s, bool (S::*m_ptr)()) {
 }
 
 void test(int a, int b, int c) {
-  (void)(a >> b + c); // expected-warning {{'+' within '>>'}} \
+  (void)(a >> b + c); // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
                          expected-note {{place parentheses around the '+' expression to silence this warning}}
-  (void)(a - b << c); // expected-warning {{'-' within '<<'}} \
+  (void)(a - b << c); // expected-warning {{operator '<<' has lower precedence than '-'; '-' will be evaluated first}} \
                          expected-note {{place parentheses around the '-' expression to silence this warning}}
   Stream() << b + c;
-  Stream() >> b + c; // expected-warning {{'+' within '>>'}} \
+  Stream() >> b + c; // expected-warning {{operator '>>' has lower precedence than '+'; '+' will be evaluated first}} \
                         expected-note {{place parentheses around the '+' expression to silence this warning}}
 }