1// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2
3typedef struct objc_object {
4  Class isa;
5} *id;
6
7
8@interface foo
9- (void)meth;
10@end
11
12@implementation foo
13- (void) contents {}			// No declaration in @interface!
14- (void) meth { [self contents]; }
15@end
16
17typedef 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}
44
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
69@interface I0
70-(void) nonVararg: (int) x;
71@end
72
73int f0(I0 *ob) {
74  [ ob nonVararg: 0, 1, 2]; // expected-error {{too many arguments to method call}}
75}
76
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
83
84// PR3766
85struct S { int X; } S;
86
87int test5(int X) {
88  int a = [X somemsg];  // expected-warning {{receiver type 'int' is not 'id'}} \
89                           expected-warning {{method '-somemsg' not found}} \
90                           expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'id'}}
91  int b = [S somemsg];  // expected-error {{bad receiver type 'struct S'}}
92}
93
94// PR4021
95void foo4() {
96  struct objc_object X[10];
97
98  [X rect]; // expected-warning {{receiver type 'struct objc_object *' is not 'id' or interface pointer, consider casting it to 'id'}}
99}
100
101// 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}
109
110@interface I1 // expected-note {{receiver is instance of class declared here}}
111-(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}
121