1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuctypedef struct objc_object { 4*f4a2713aSLionel Sambuc Class isa; 5*f4a2713aSLionel Sambuc} *id; 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc@interface foo 9*f4a2713aSLionel Sambuc- (void)meth; 10*f4a2713aSLionel Sambuc@end 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambuc@implementation foo 13*f4a2713aSLionel Sambuc- (void) contents {} // No declaration in @interface! 14*f4a2713aSLionel Sambuc- (void) meth { [self contents]; } 15*f4a2713aSLionel Sambuc@end 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuctypedef struct _NSPoint { 18*f4a2713aSLionel Sambuc float x; 19*f4a2713aSLionel Sambuc float y; 20*f4a2713aSLionel Sambuc} NSPoint; 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuctypedef struct _NSSize { 23*f4a2713aSLionel Sambuc float width; 24*f4a2713aSLionel Sambuc float height; 25*f4a2713aSLionel Sambuc} NSSize; 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuctypedef struct _NSRect { 28*f4a2713aSLionel Sambuc NSPoint origin; 29*f4a2713aSLionel Sambuc NSSize size; 30*f4a2713aSLionel Sambuc} NSRect; 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambuc@interface AnyClass 33*f4a2713aSLionel Sambuc- (NSRect)rect; 34*f4a2713aSLionel Sambuc@end 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc@class Helicopter; 37*f4a2713aSLionel Sambuc 38*f4a2713aSLionel Sambucstatic void func(Helicopter *obj) { 39*f4a2713aSLionel Sambuc // Note that the proto for "rect" is found in the global pool even when 40*f4a2713aSLionel Sambuc // a statically typed object's class interface isn't in scope! This 41*f4a2713aSLionel Sambuc // behavior isn't very desirable, however wee need it for GCC compatibility. 42*f4a2713aSLionel Sambuc NSRect r = [obj rect]; 43*f4a2713aSLionel Sambuc} 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc@interface NSObject @end 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambucextern Class NSClassFromObject(id object); 48*f4a2713aSLionel Sambuc 49*f4a2713aSLionel Sambuc@interface XX : NSObject 50*f4a2713aSLionel Sambuc@end 51*f4a2713aSLionel Sambuc 52*f4a2713aSLionel Sambuc@implementation XX 53*f4a2713aSLionel Sambuc 54*f4a2713aSLionel Sambuc+ _privateMethod { 55*f4a2713aSLionel Sambuc return self; 56*f4a2713aSLionel Sambuc} 57*f4a2713aSLionel Sambuc 58*f4a2713aSLionel Sambuc- (void) xx { 59*f4a2713aSLionel Sambuc [NSClassFromObject(self) _privateMethod]; 60*f4a2713aSLionel Sambuc} 61*f4a2713aSLionel Sambuc@end 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc@implementation XX (Private) 64*f4a2713aSLionel Sambuc- (void) yy { 65*f4a2713aSLionel Sambuc [NSClassFromObject(self) _privateMethod]; 66*f4a2713aSLionel Sambuc} 67*f4a2713aSLionel Sambuc@end 68*f4a2713aSLionel Sambuc 69*f4a2713aSLionel Sambuc@interface I0 70*f4a2713aSLionel Sambuc-(void) nonVararg: (int) x; 71*f4a2713aSLionel Sambuc@end 72*f4a2713aSLionel Sambuc 73*f4a2713aSLionel Sambucint f0(I0 *ob) { 74*f4a2713aSLionel Sambuc [ ob nonVararg: 0, 1, 2]; // expected-error {{too many arguments to method call}} 75*f4a2713aSLionel Sambuc} 76*f4a2713aSLionel Sambuc 77*f4a2713aSLionel Sambucint f2() { 78*f4a2713aSLionel Sambuc const id foo; 79*f4a2713aSLionel Sambuc [foo bar]; // expected-warning {{method '-bar' not found (return type defaults to 'id')}} 80*f4a2713aSLionel Sambuc return 0; 81*f4a2713aSLionel Sambuc} 82*f4a2713aSLionel Sambuc 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambuc// PR3766 85*f4a2713aSLionel Sambucstruct S { int X; } S; 86*f4a2713aSLionel Sambuc 87*f4a2713aSLionel Sambucint test5(int X) { 88*f4a2713aSLionel Sambuc int a = [X somemsg]; // expected-warning {{receiver type 'int' is not 'id'}} \ 89*f4a2713aSLionel Sambuc expected-warning {{method '-somemsg' not found}} \ 90*f4a2713aSLionel Sambuc expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'id'}} 91*f4a2713aSLionel Sambuc int b = [S somemsg]; // expected-error {{bad receiver type 'struct S'}} 92*f4a2713aSLionel Sambuc} 93*f4a2713aSLionel Sambuc 94*f4a2713aSLionel Sambuc// PR4021 95*f4a2713aSLionel Sambucvoid foo4() { 96*f4a2713aSLionel Sambuc struct objc_object X[10]; 97*f4a2713aSLionel Sambuc 98*f4a2713aSLionel Sambuc [X rect]; // expected-warning {{receiver type 'struct objc_object *' is not 'id' or interface pointer, consider casting it to 'id'}} 99*f4a2713aSLionel Sambuc} 100*f4a2713aSLionel Sambuc 101*f4a2713aSLionel Sambuc// rdar://13207886 102*f4a2713aSLionel Sambucvoid foo5(id p) { 103*f4a2713aSLionel Sambuc p 104*f4a2713aSLionel Sambuc [(id)(p) bar]; // expected-error {{missing '['}} \ 105*f4a2713aSLionel Sambuc // expected-error {{expected ']'}} \ 106*f4a2713aSLionel Sambuc // expected-note {{to match this '['}} \ 107*f4a2713aSLionel Sambuc // expected-warning {{instance method '-bar' not found}} 108*f4a2713aSLionel Sambuc} 109*f4a2713aSLionel Sambuc 110*f4a2713aSLionel Sambuc@interface I1 // expected-note {{receiver is instance of class declared here}} 111*f4a2713aSLionel Sambuc-(void)unavail_meth __attribute__((unavailable)); // expected-note {{marked unavailable here}} 112*f4a2713aSLionel Sambuc@end 113*f4a2713aSLionel Sambuc 114*f4a2713aSLionel Sambuc// rdar://13620447 115*f4a2713aSLionel Sambucvoid foo6(I1 *p) { 116*f4a2713aSLionel Sambuc [p 117*f4a2713aSLionel Sambuc bar]; // expected-warning {{instance method '-bar' not found}} 118*f4a2713aSLionel Sambuc [p 119*f4a2713aSLionel Sambuc unavail_meth]; // expected-error {{unavailable}} 120*f4a2713aSLionel Sambuc} 121