• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
13int x CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to functions, methods, and parameters}}
14int y CF_RETURNS_NOT_RETAINED; // expected-warning{{'cf_returns_not_retained' attribute only applies to functions, methods, and parameters}}
15
16typedef struct __CFFoo *CFFooRef;
17
18int invalid1() CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to functions that return a pointer}}
19void invalid2() CF_RETURNS_RETAINED; // expected-warning{{'cf_returns_retained' attribute only applies to functions that return a pointer}}
20
21CFFooRef valid1() CF_RETURNS_RETAINED;
22id valid2() 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
38void 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
44void validParam(id *a CF_RETURNS_RETAINED,
45                CFFooRef *b CF_RETURNS_RETAINED,
46                void **c CF_RETURNS_RETAINED);
47void validParam2(id *a CF_RETURNS_NOT_RETAINED,
48                 CFFooRef *b CF_RETURNS_NOT_RETAINED,
49                 void **c CF_RETURNS_NOT_RETAINED);
50