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; |
Jean-Daniel Dupas | 3965574 | 2013-07-17 18:17:14 +0000 | [diff] [blame] | 12 | - (id) myInit __attribute__((objc_method_family(init))); |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 13 | - (void) iterate: (id) coll; |
| 14 | - (id) nextObject; |
Fariborz Jahanian | f07bcc5 | 2012-08-29 17:17:11 +0000 | [diff] [blame] | 15 | @property unsigned uid; |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 16 | @end |
| 17 | |
| 18 | @implementation Object |
Fariborz Jahanian | f07bcc5 | 2012-08-29 17:17:11 +0000 | [diff] [blame] | 19 | @synthesize uid; |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 20 | - (id) init { |
| 21 | if (self = [self init]) { |
| 22 | } |
| 23 | return self; |
| 24 | } |
| 25 | |
| 26 | - (id) initWithInt: (int) i { |
| 27 | if (self = [self initWithInt: i]) { |
| 28 | } |
Fariborz Jahanian | f07bcc5 | 2012-08-29 17:17:11 +0000 | [diff] [blame] | 29 | // rdar://11066598 |
| 30 | if (self.uid = 100) { // expected-warning {{using the result of an assignment as a condition without parentheses}} \ |
| 31 | // expected-note {{place parentheses around the assignment to silence this warning}} \ |
| 32 | // expected-note {{use '==' to turn this assignment into an equality comparison}} |
| 33 | // ... |
| 34 | } |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 35 | return self; |
| 36 | } |
| 37 | |
Jean-Daniel Dupas | 3965574 | 2013-07-17 18:17:14 +0000 | [diff] [blame] | 38 | - (id) myInit { |
| 39 | if (self = [self myInit]) { |
| 40 | } |
| 41 | return self; |
| 42 | } |
| 43 | |
John McCall | b0e419e | 2009-11-12 00:06:05 +0000 | [diff] [blame] | 44 | - (void) iterate: (id) coll { |
| 45 | id cur; |
| 46 | while (cur = [coll nextObject]) { |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | - (id) nextObject { |
| 51 | return self; |
| 52 | } |
| 53 | @end |