| 1 |
// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc -fblocks %s |
| 2 |
|
| 3 |
#if __has_feature(attribute_cf_returns_on_parameters) |
| 4 |
# error "okay!" |
| 5 |
// expected-error@-1 {{okay!}} |
| 6 |
#else |
| 7 |
# error "uh-oh" |
| 8 |
#endif |
| 9 |
|
| 10 |
#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) |
| 11 |
#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained)) |
| 12 |
|
| 13 |
int x CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to functions, methods, and parameters}} |
| 14 |
int y CF_RETURNS_NOT_RETAINED; // expected-warning{{'cf_returns_not_retained' attribute only applies to functions, methods, and parameters}} |
| 15 |
|
| 16 |
typedef struct __CFFoo *CFFooRef; |
| 17 |
|
| 18 |
int invalid1(void) CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to functions that return a pointer}} |
| 19 |
void invalid2(void) CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to functions that return a pointer}} |
| 20 |
|
| 21 |
CFFooRef valid1(void) CF_RETURNS_RETAINED; |
| 22 |
id valid2(void) CF_RETURNS_RETAINED; |
| 23 |
|
| 24 |
@interface Test |
| 25 |
- (int)invalid1 CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to methods that return a pointer}} |
| 26 |
- (void)invalid2 CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to methods that return a pointer}} |
| 27 |
|
| 28 |
- (CFFooRef)valid1 CF_RETURNS_RETAINED; |
| 29 |
- (id)valid2 CF_RETURNS_RETAINED; |
| 30 |
|
| 31 |
@property int invalidProp1 CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to properties that return a pointer}} |
| 32 |
@property void invalidProp2 CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to properties that return a pointer}} |
| 33 |
|
| 34 |
@property CFFooRef valid1 CF_RETURNS_RETAINED; |
| 35 |
@property id valid2 CF_RETURNS_RETAINED; |
| 36 |
@end |
| 37 |
|
| 38 |
void invalidParam(int a CF_RETURNS_RETAINED, // expected-warning{{'cf_returns_retained' attribute only applies to pointer-to-CF-pointer parameters}} |
| 39 |
int *b CF_RETURNS_RETAINED, // expected-warning{{'cf_returns_retained' attribute only applies to pointer-to-CF-pointer parameters}} |
| 40 |
id c CF_RETURNS_RETAINED, // expected-warning{{'cf_returns_retained' attribute only applies to pointer-to-CF-pointer parameters}} |
| 41 |
void *d CF_RETURNS_RETAINED, // expected-warning{{'cf_returns_retained' attribute only applies to pointer-to-CF-pointer parameters}} |
| 42 |
CFFooRef e CF_RETURNS_RETAINED); // expected-warning{{'cf_returns_retained' attribute only applies to pointer-to-CF-pointer parameters}} |
| 43 |
|
| 44 |
void validParam(id *a CF_RETURNS_RETAINED, |
| 45 |
CFFooRef *b CF_RETURNS_RETAINED, |
| 46 |
void **c CF_RETURNS_RETAINED); |
| 47 |
void validParam2(id *a CF_RETURNS_NOT_RETAINED, |
| 48 |
CFFooRef *b CF_RETURNS_NOT_RETAINED, |
| 49 |
void **c CF_RETURNS_NOT_RETAINED); |