]> granicus.if.org Git - clang/commitdiff
Sema: Don't crash when trying to emit a precedence warning on postinc/decrement.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 30 Mar 2013 11:56:00 +0000 (11:56 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 30 Mar 2013 11:56:00 +0000 (11:56 +0000)
Post-Inc can occur as a binary call (the infamous dummy int argument), but it's
not really a binary operator.

Fixes PR15628.

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

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

index 62bfa3c709d57f47af3b3b92cf5344439b466523..75da99c344c545b5a0521b12e70c3924bcba5e6e 100644 (file)
@@ -5412,7 +5412,8 @@ static bool IsArithmeticBinaryExpr(Expr *E, BinaryOperatorKind *Opcode,
     // Make sure this is really a binary operator that is safe to pass into
     // BinaryOperator::getOverloadedOpcode(), e.g. it's not a subscript op.
     OverloadedOperatorKind OO = Call->getOperator();
-    if (OO < OO_Plus || OO > OO_Arrow)
+    if (OO < OO_Plus || OO > OO_Arrow ||
+        OO == OO_PlusPlus || OO == OO_MinusMinus)
       return false;
 
     BinaryOperatorKind OpKind = BinaryOperator::getOverloadedOpcode(OO);
index 8f5f24652dd7140fe4b9e96131a9ed9e7924c8a2..da37dd397bbaf5b484d5a7c886bd69b5fff5ef15 100644 (file)
@@ -57,3 +57,15 @@ void test(int a, int b, int c) {
   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}}
 }
+
+namespace PR15628 {
+  struct BlockInputIter {
+    void* operator++(int);
+    void* operator--(int);
+  };
+
+  void test(BlockInputIter i) {
+    (void)(i++ ? true : false); // no-warning
+    (void)(i-- ? true : false); // no-warning
+  }
+}