1// RUN: %clang_cc1 -fsyntax-only -verify %s 2 3#if !__has_feature(objc_class_property) 4#error does not support class property 5#endif 6 7@interface Root 8-(id) alloc; 9-(id) init; 10@end 11 12@interface A : Root { 13 int x; 14 int z; 15} 16@property int x; 17@property int y; 18@property int z; 19@property(readonly) int ro, ro2; 20@property (class) int c; 21@property (class) int c2; // expected-note {{property declared here}} \ 22 // expected-note {{property declared here}} 23@property (class) int x; 24@end 25 26@implementation A // expected-warning {{class property 'c2' requires method 'c2' to be defined}} \ 27 // expected-warning {{class property 'c2' requires method 'setC2:' to be defined}} 28@dynamic x; // refers to the instance property 29@dynamic (class) x; // refers to the class property 30@synthesize z, c2; // expected-error {{@synthesize not allowed on a class property 'c2'}} 31@dynamic c; // refers to the class property 32@end 33 34int test() { 35 A *a = [[A alloc] init]; 36 a.c; // expected-error {{property 'c' is a class property; did you mean to access it with class 'A'}} 37 return a.x + A.c; 38} 39 40void message_id(id me) { 41 [me y]; 42} 43 44void message_class(Class me) { 45 [me c2]; 46} 47 48@interface NSObject 49@end 50 51@interface MyClass : NSObject 52@property(class, readonly) int classProp; // expected-note {{property declared here}} 53@end 54 55@implementation MyClass // expected-warning {{class property 'classProp' requires method 'classProp' to be defined}} 56- (int)classProp { // Oops, mistakenly made this an instance method. 57 return 8; 58} 59@end 60