blob: fed3961ce111d808a4a84467600d95fc75117252 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Steve Naroffc43d8682007-11-11 00:10:47 +00002
Chris Lattnerd0d45992009-04-29 05:48:32 +00003typedef struct objc_object {
4 Class isa;
5} *id;
6
7
Steve Naroffc43d8682007-11-11 00:10:47 +00008@interface foo
9- (void)meth;
10@end
11
12@implementation foo
13- (void) contents {} // No declaration in @interface!
Steve Naroff0416fb92007-11-11 17:19:15 +000014- (void) meth { [self contents]; }
Steve Naroffc43d8682007-11-11 00:10:47 +000015@end
16
Steve Naroffa924e7c2007-12-11 03:34:41 +000017typedef struct _NSPoint {
18 float x;
19 float y;
20} NSPoint;
21
22typedef struct _NSSize {
23 float width;
24 float height;
25} NSSize;
26
27typedef struct _NSRect {
28 NSPoint origin;
29 NSSize size;
30} NSRect;
31
32@interface AnyClass
33- (NSRect)rect;
34@end
35
36@class Helicopter;
37
38static 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 Naroffa56f6162007-12-18 01:30:32 +000044
45@interface NSObject @end
46
47extern 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 Dunbar91e19b22008-09-11 00:50:25 +000069@interface I0
70-(void) nonVararg: (int) x;
71@end
72
73int f0(I0 *ob) {
Chris Lattner2c21a072008-11-21 18:44:24 +000074 [ ob nonVararg: 0, 1, 2]; // expected-error {{too many arguments to method call}}
Daniel Dunbar91e19b22008-09-11 00:50:25 +000075}
Chris Lattnere47f7b12009-02-18 04:41:38 +000076
77int 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 Lattner0c73f372009-03-09 21:19:16 +000083
84// PR3766
85struct S { int X; } S;
86
87int test5(int X) {
Chris Lattner4018a282009-03-11 03:47:47 +000088 int a = [X somemsg]; // expected-warning {{receiver type 'int' is not 'id'}} \
Chris Lattner0c73f372009-03-09 21:19:16 +000089 expected-warning {{method '-somemsg' not found}} \
Douglas Gregor08a41902010-04-09 17:53:29 +000090 expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'id'}}
Chris Lattner0c73f372009-03-09 21:19:16 +000091 int b = [S somemsg]; // expected-error {{bad receiver type 'struct S'}}
92}
93
Chris Lattnerd0d45992009-04-29 05:48:32 +000094// PR4021
95void foo4() {
96 struct objc_object X[10];
97
Steve Naroff0cdad6c2009-07-15 19:44:23 +000098 [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 Lattnerd0d45992009-04-29 05:48:32 +000099}
Chris Lattner0c73f372009-03-09 21:19:16 +0000100