]> granicus.if.org Git - clang/commitdiff
do not warn about -=/=- confusion with macros, thanks to rdogra for a testcase.
authorChris Lattner <sabre@nondot.org>
Mon, 9 Mar 2009 07:11:10 +0000 (07:11 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 9 Mar 2009 07:11:10 +0000 (07:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66416 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4fb03b3d6bc575449277996176bb2d10d6aa56be..4ba35a593c279f20710e46599773f782d4644add 100644 (file)
@@ -3499,7 +3499,8 @@ QualType Sema::CheckAssignmentOperands(Expr *LHS, Expr *&RHS,
           Loc.getFileLocWithOffset(1) == UO->getOperatorLoc() &&
           // And there is a space or other character before the subexpr of the
           // unary +/-.  We don't want to warn on "x=-1".
-          Loc.getFileLocWithOffset(2) != UO->getSubExpr()->getLocStart()) {
+          Loc.getFileLocWithOffset(2) != UO->getSubExpr()->getLocStart() &&
+          UO->getSubExpr()->getLocStart().isFileID()) {
         Diag(Loc, diag::warn_not_compound_assign)
           << (UO->getOpcode() == UnaryOperator::Plus ? "+" : "-")
           << SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc());
index 25da12b5861f95a32dcc65a1c532c23ed7006c4f..8bf42f7d7ddf45b4fea2ce0789d791eb3abd4ecd 100644 (file)
@@ -25,6 +25,10 @@ void test4() {
 
       var =+5;  // no warning when the subexpr of the unary op has no space before it.
       var =-5;
+  
+#define FIVE 5
+      var=-FIVE;  // no warning with macros.
+      var=-FIVE;
 }
 
 // rdar://6319320