[cfe-commits] r66370 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/exprs.c
Chris Lattner
sabre at nondot.org
Sat Mar 7 22:51:11 PST 2009
Author: lattner
Date: Sun Mar 8 00:51:10 2009
New Revision: 66370
URL: http://llvm.org/viewvc/llvm-project?rev=66370&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/exprs.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=66370&r1=66369&r2=66370&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Mar 8 00:51:10 2009
@@ -3479,10 +3479,14 @@
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"
Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=66370&r1=66369&r2=66370&view=diff
==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Sun Mar 8 00:51:10 2009
@@ -20,8 +20,11 @@
static int var;
var =+ 5; // expected-warning {{use of unary operator that may be intended as compound assignment (+=)}}
var =- 5; // expected-warning {{use of unary operator that may be intended as compound assignment (-=)}}
- var = +5;
+ var = +5; // no warning when space between the = and +.
var = -5;
+
+ var =+5; // no warning when the subexpr of the unary op has no space before it.
+ var =-5;
}
// rdar://6319320
More information about the cfe-commits
mailing list