Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Steve Naroff | c43d868 | 2007-11-11 00:10:47 +0000 | [diff] [blame] | 2 | |
Chris Lattner | d0d4599 | 2009-04-29 05:48:32 +0000 | [diff] [blame] | 3 | typedef struct objc_object { |
| 4 | Class isa; |
| 5 | } *id; |
| 6 | |
| 7 | |
Steve Naroff | c43d868 | 2007-11-11 00:10:47 +0000 | [diff] [blame] | 8 | @interface foo |
| 9 | - (void)meth; |
| 10 | @end |
| 11 | |
| 12 | @implementation foo |
| 13 | - (void) contents {} // No declaration in @interface! |
Steve Naroff | 0416fb9 | 2007-11-11 17:19:15 +0000 | [diff] [blame] | 14 | - (void) meth { [self contents]; } |
Steve Naroff | c43d868 | 2007-11-11 00:10:47 +0000 | [diff] [blame] | 15 | @end |
| 16 | |
Steve Naroff | a924e7c | 2007-12-11 03:34:41 +0000 | [diff] [blame] | 17 | typedef struct _NSPoint { |
| 18 | float x; |
| 19 | float y; |
| 20 | } NSPoint; |
| 21 | |
| 22 | typedef struct _NSSize { |
| 23 | float width; |
| 24 | float height; |
| 25 | } NSSize; |
| 26 | |
| 27 | typedef struct _NSRect { |
| 28 | NSPoint origin; |
| 29 | NSSize size; |
| 30 | } NSRect; |
| 31 | |
| 32 | @interface AnyClass |
| 33 | - (NSRect)rect; |
| 34 | @end |
| 35 | |
| 36 | @class Helicopter; |
| 37 | |
| 38 | static void func(Helicopter *obj) { |
| 39 | // Note that the proto for "rect" is found in the global pool even when |
| 40 | // a statically typed object's class interface isn't in scope! This |
| 41 | // behavior isn't very desirable, however wee need it for GCC compatibility. |
| 42 | NSRect r = [obj rect]; |
| 43 | } |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 44 | |
| 45 | @interface NSObject @end |
| 46 | |
| 47 | extern Class NSClassFromObject(id object); |
| 48 | |
| 49 | @interface XX : NSObject |
| 50 | @end |
| 51 | |
| 52 | @implementation XX |
| 53 | |
| 54 | + _privateMethod { |
| 55 | return self; |
| 56 | } |
| 57 | |
| 58 | - (void) xx { |
| 59 | [NSClassFromObject(self) _privateMethod]; |
| 60 | } |
| 61 | @end |
| 62 | |
| 63 | @implementation XX (Private) |
| 64 | - (void) yy { |
| 65 | [NSClassFromObject(self) _privateMethod]; |
| 66 | } |
| 67 | @end |
| 68 | |
Daniel Dunbar | 91e19b2 | 2008-09-11 00:50:25 +0000 | [diff] [blame] | 69 | @interface I0 |
| 70 | -(void) nonVararg: (int) x; |
| 71 | @end |
| 72 | |
| 73 | int f0(I0 *ob) { |
Chris Lattner | 2c21a07 | 2008-11-21 18:44:24 +0000 | [diff] [blame] | 74 | [ ob nonVararg: 0, 1, 2]; // expected-error {{too many arguments to method call}} |
Daniel Dunbar | 91e19b2 | 2008-09-11 00:50:25 +0000 | [diff] [blame] | 75 | } |
Chris Lattner | e47f7b1 | 2009-02-18 04:41:38 +0000 | [diff] [blame] | 76 | |
| 77 | int f2() { |
| 78 | const id foo; |
| 79 | [foo bar]; // expected-warning {{method '-bar' not found (return type defaults to 'id')}} |
| 80 | return 0; |
| 81 | } |
| 82 | |
Chris Lattner | 0c73f37 | 2009-03-09 21:19:16 +0000 | [diff] [blame] | 83 | |
| 84 | // PR3766 |
| 85 | struct S { int X; } S; |
| 86 | |
| 87 | int test5(int X) { |
Chris Lattner | 4018a28 | 2009-03-11 03:47:47 +0000 | [diff] [blame] | 88 | int a = [X somemsg]; // expected-warning {{receiver type 'int' is not 'id'}} \ |
Chris Lattner | 0c73f37 | 2009-03-09 21:19:16 +0000 | [diff] [blame] | 89 | expected-warning {{method '-somemsg' not found}} \ |
Douglas Gregor | 08a4190 | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 90 | expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'id'}} |
Chris Lattner | 0c73f37 | 2009-03-09 21:19:16 +0000 | [diff] [blame] | 91 | int b = [S somemsg]; // expected-error {{bad receiver type 'struct S'}} |
| 92 | } |
| 93 | |
Chris Lattner | d0d4599 | 2009-04-29 05:48:32 +0000 | [diff] [blame] | 94 | // PR4021 |
| 95 | void foo4() { |
| 96 | struct objc_object X[10]; |
| 97 | |
Steve Naroff | 0cdad6c | 2009-07-15 19:44:23 +0000 | [diff] [blame] | 98 | [X rect]; // expected-warning {{receiver type 'struct objc_object *' is not 'id' or interface pointer, consider casting it to 'id'}} expected-warning {{method '-rect' not found (return type defaults to 'id')}} |
Chris Lattner | d0d4599 | 2009-04-29 05:48:32 +0000 | [diff] [blame] | 99 | } |
Chris Lattner | 0c73f37 | 2009-03-09 21:19:16 +0000 | [diff] [blame] | 100 | |