Patrick Beard | acfbe9e | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wparentheses -Wno-objc-root-class %s |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 2 | |
Ted Kremenek | 2b2e06d | 2011-04-29 20:30:39 +0000 | [diff] [blame] | 3 | // Don't warn about some common ObjC idioms unless we have -Widiomatic-parentheses on. |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 4 | // <rdar://problem/7382435> |
| 5 | |
| 6 | @interface Object |
Fariborz Jahanian | f07bcc5 | 2012-08-29 17:17:11 +0000 | [diff] [blame^] | 7 | { |
| 8 | unsigned uid; |
| 9 | } |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 10 | - (id) init; |
| 11 | - (id) initWithInt: (int) i; |
| 12 | - (void) iterate: (id) coll; |
| 13 | - (id) nextObject; |
Fariborz Jahanian | f07bcc5 | 2012-08-29 17:17:11 +0000 | [diff] [blame^] | 14 | @property unsigned uid; |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 15 | @end |
| 16 | |
| 17 | @implementation Object |
Fariborz Jahanian | f07bcc5 | 2012-08-29 17:17:11 +0000 | [diff] [blame^] | 18 | @synthesize uid; |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 19 | - (id) init { |
| 20 | if (self = [self init]) { |
| 21 | } |
| 22 | return self; |
| 23 | } |
| 24 | |
| 25 | - (id) initWithInt: (int) i { |
| 26 | if (self = [self initWithInt: i]) { |
| 27 | } |
Fariborz Jahanian | f07bcc5 | 2012-08-29 17:17:11 +0000 | [diff] [blame^] | 28 | // rdar://11066598 |
| 29 | if (self.uid = 100) { // expected-warning {{using the result of an assignment as a condition without parentheses}} \ |
| 30 | // expected-note {{place parentheses around the assignment to silence this warning}} \ |
| 31 | // expected-note {{use '==' to turn this assignment into an equality comparison}} |
| 32 | // ... |
| 33 | } |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 34 | return self; |
| 35 | } |
| 36 | |
| 37 | - (void) iterate: (id) coll { |
| 38 | id cur; |
| 39 | while (cur = [coll nextObject]) { |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | - (id) nextObject { |
| 44 | return self; |
| 45 | } |
| 46 | @end |