diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-08-29 17:17:11 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-08-29 17:17:11 +0000 |
commit | a414a2f3ae818953c88443bd617aa89a2b7712e5 (patch) | |
tree | 81cef60e21a8c4b569eb86b2c9ddf143c0fb9d9b | |
parent | e40c4238a572bf8241a04e0005f70550cbfc1cfb (diff) |
objective-C: make -Widiomatic-parentheses work
when assignment expression in conditional invloves
property reference. // rdar://11066598
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162846 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 4 | ||||
-rw-r--r-- | test/SemaObjC/idiomatic-parentheses.m | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7aa7732307..2706ae43da 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -11191,7 +11191,9 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) { IsOrAssign = Op->getOperator() == OO_PipeEqual; Loc = Op->getOperatorLoc(); - } else { + } else if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E)) + return DiagnoseAssignmentAsCondition(POE->getSyntacticForm()); + else { // Not an assignment. return; } diff --git a/test/SemaObjC/idiomatic-parentheses.m b/test/SemaObjC/idiomatic-parentheses.m index 417b948b8f..801db5944f 100644 --- a/test/SemaObjC/idiomatic-parentheses.m +++ b/test/SemaObjC/idiomatic-parentheses.m @@ -4,13 +4,18 @@ // <rdar://problem/7382435> @interface Object +{ + unsigned uid; +} - (id) init; - (id) initWithInt: (int) i; - (void) iterate: (id) coll; - (id) nextObject; +@property unsigned uid; @end @implementation Object +@synthesize uid; - (id) init { if (self = [self init]) { } @@ -20,6 +25,12 @@ - (id) initWithInt: (int) i { if (self = [self initWithInt: i]) { } + // rdar://11066598 + if (self.uid = 100) { // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note {{place parentheses around the assignment to silence this warning}} \ + // expected-note {{use '==' to turn this assignment into an equality comparison}} + // ... + } return self; } |