blob: 2c4d8066f60412a271438875cc516681ede0eb9b [file] [log] [blame]
Patrick Beardb2f68202012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %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
John McCall2fbe92c2013-03-01 09:20:14 +000098 [X rect]; // expected-warning {{receiver type 'struct objc_object *' is not 'id' or interface pointer, consider casting it to 'id'}}
Chris Lattnerd0d45992009-04-29 05:48:32 +000099}
Chris Lattner0c73f372009-03-09 21:19:16 +0000100
Argyrios Kyrtzidisdb546fa2013-02-15 18:34:15 +0000101// rdar://13207886
102void foo5(id p) {
103 p
104 [(id)(p) bar]; // expected-error {{missing '['}} \
105 // expected-error {{expected ']'}} \
106 // expected-note {{to match this '['}} \
107 // expected-warning {{instance method '-bar' not found}}
108}
Argyrios Kyrtzidisf4d02392013-05-01 00:24:09 +0000109
Fariborz Jahanian14040142013-05-15 15:27:35 +0000110@interface I1 // expected-note {{receiver is instance of class declared here}}
Argyrios Kyrtzidisf4d02392013-05-01 00:24:09 +0000111-(void)unavail_meth __attribute__((unavailable)); // expected-note {{marked unavailable here}}
112@end
113
114// rdar://13620447
115void foo6(I1 *p) {
116 [p
117 bar]; // expected-warning {{instance method '-bar' not found}}
118 [p
119 unavail_meth]; // expected-error {{unavailable}}
120}