diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-08 06:51:10 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-08 06:51:10 +0000 |
commit | 399bd1bc2b801ad85e4575e2401bb43919fcbee8 (patch) | |
tree | c8fbb03c2bd73308d440c9dc030e2ba4db4d51b3 /lib | |
parent | 8a9e4201aa67f844109b4c28ebb2233b81cec976 (diff) |
refine the "use of unary operator that may be intended as compound assignment (+=)"
warning to only trigger when there is whitespace or something else after the + as
suggested by Eli.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66370 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 79be162520..6c4176720a 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3479,10 +3479,14 @@ QualType Sema::CheckAssignmentOperands(Expr *LHS, Expr *&RHS, UO->getOpcode() == UnaryOperator::Minus) && Loc.isFileID() && UO->getOperatorLoc().isFileID() && // Only if the two operators are exactly adjacent. - Loc.getFileLocWithOffset(1) == UO->getOperatorLoc()) + 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()) { Diag(Loc, diag::warn_not_compound_assign) << (UO->getOpcode() == UnaryOperator::Plus ? "+" : "-") << SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc()); + } } } else { // Compound assignment "x += y" |