2016-01-28 04:10:32 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
|
2016-03-11 07:51:03 +08:00
|
|
|
#if !__has_feature(objc_class_property)
|
|
|
|
#error does not support class property
|
|
|
|
#endif
|
|
|
|
|
2016-01-28 04:10:32 +08:00
|
|
|
@interface Root
|
|
|
|
-(id) alloc;
|
|
|
|
-(id) init;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface A : Root {
|
|
|
|
int x;
|
|
|
|
int z;
|
|
|
|
}
|
|
|
|
@property int x;
|
|
|
|
@property int y;
|
|
|
|
@property int z;
|
|
|
|
@property(readonly) int ro, ro2;
|
|
|
|
@property (class) int c;
|
2016-04-13 07:01:55 +08:00
|
|
|
@property (class) int c2; // expected-note {{property declared here}} \
|
|
|
|
// expected-note {{property declared here}}
|
2016-01-29 02:49:28 +08:00
|
|
|
@property (class) int x;
|
2017-02-21 07:45:49 +08:00
|
|
|
@property (class, setter=customSet:) int customSetterProperty;
|
|
|
|
@property (class, getter=customGet) int customGetterProperty;
|
2016-01-28 04:10:32 +08:00
|
|
|
@end
|
|
|
|
|
2016-04-13 07:01:55 +08:00
|
|
|
@implementation A // expected-warning {{class property 'c2' requires method 'c2' to be defined}} \
|
|
|
|
// expected-warning {{class property 'c2' requires method 'setC2:' to be defined}}
|
2016-01-30 03:05:57 +08:00
|
|
|
@dynamic x; // refers to the instance property
|
|
|
|
@dynamic (class) x; // refers to the class property
|
2016-01-30 03:16:39 +08:00
|
|
|
@synthesize z, c2; // expected-error {{@synthesize not allowed on a class property 'c2'}}
|
2016-01-30 03:05:57 +08:00
|
|
|
@dynamic c; // refers to the class property
|
2017-02-21 07:45:49 +08:00
|
|
|
@dynamic customSetterProperty;
|
|
|
|
@dynamic customGetterProperty;
|
2016-01-28 04:10:32 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
int test() {
|
|
|
|
A *a = [[A alloc] init];
|
2016-06-29 07:01:49 +08:00
|
|
|
a.c; // expected-error {{property 'c' is a class property; did you mean to access it with class 'A'}}
|
2016-01-28 04:10:32 +08:00
|
|
|
return a.x + A.c;
|
|
|
|
}
|
2016-03-24 05:39:31 +08:00
|
|
|
|
2017-02-21 07:45:49 +08:00
|
|
|
void customSelectors() {
|
|
|
|
A.customSetterProperty = 1;
|
|
|
|
(void)A.customGetterProperty;
|
|
|
|
}
|
|
|
|
|
2016-03-24 05:39:31 +08:00
|
|
|
void message_id(id me) {
|
|
|
|
[me y];
|
|
|
|
}
|
|
|
|
|
|
|
|
void message_class(Class me) {
|
|
|
|
[me c2];
|
|
|
|
}
|
2016-05-19 02:12:34 +08:00
|
|
|
|
|
|
|
@interface NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MyClass : NSObject
|
|
|
|
@property(class, readonly) int classProp; // expected-note {{property declared here}}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MyClass // expected-warning {{class property 'classProp' requires method 'classProp' to be defined}}
|
|
|
|
- (int)classProp { // Oops, mistakenly made this an instance method.
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
@end
|