• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks -Wno-objc-root-class %s
2
3// Simple ownership conversions + diagnostics.
4int &f0(id __strong const *); // expected-note{{candidate function not viable: 1st argument ('__weak id *') has __weak ownership, but parameter has __strong ownership}}
5
6void test_f0() {
7  id __strong *sip;
8  id __strong const *csip;
9  id __weak *wip;
10  id __autoreleasing *aip;
11  id __unsafe_unretained *uip;
12
13  int &ir1 = f0(sip);
14  int &ir2 = f0(csip);
15  int &ir3 = f0(aip);
16  int &ir4 = f0(uip);
17  f0(wip); // expected-error{{no matching function for call to 'f0'}}
18}
19
20// Simple overloading
21int &f1(id __strong const *);
22float &f1(id __weak const *);
23
24void test_f1() {
25  id __strong *sip;
26  id __strong const *csip;
27  id __weak *wip;
28  id __autoreleasing *aip;
29  id __unsafe_unretained *uip;
30
31  int &ir1 = f1(sip);
32  int &ir2 = f1(csip);
33  float &fr1 = f1(wip);
34  int &ir3 = f1(aip);
35  int &ir4 = f1(uip);
36}
37
38// Simple overloading
39int &f2(id __strong const *); // expected-note{{candidate function}}
40float &f2(id __autoreleasing const *); // expected-note{{candidate function}}
41
42void test_f2() {
43  id __strong *sip;
44  id __strong const *csip;
45  id __weak *wip;
46  id __autoreleasing *aip;
47  id __unsafe_unretained *uip;
48
49  // Prefer non-ownership conversions to ownership conversions.
50  int &ir1 = f2(sip);
51  int &ir2 = f2(csip);
52  float &fr1 = f2(aip);
53
54  f2(uip); // expected-error{{call to 'f2' is ambiguous}}
55}
56
57// Writeback conversion
58int &f3(id __autoreleasing *); // expected-note{{candidate function not viable: 1st argument ('__unsafe_unretained id *') has __unsafe_unretained ownership, but parameter has __autoreleasing ownership}}
59
60void test_f3() {
61  id __strong sip;
62  id __weak wip;
63  id __autoreleasing aip;
64  id __unsafe_unretained uip;
65
66  int &ir1 = f3(&sip);
67  int &ir2 = f3(&wip);
68  int &ir3 = f3(&aip);
69  f3(&uip); // expected-error{{no matching function for call to 'f3'}}
70}
71
72// Writeback conversion vs. no conversion
73int &f4(id __autoreleasing *);
74float &f4(id __strong *);
75
76void test_f4() {
77  id __strong sip;
78  id __weak wip;
79  id __autoreleasing aip;
80  extern __weak id weak_global_ptr;
81
82  float &fr1 = f4(&sip);
83  int &ir1 = f4(&wip);
84  int &ir2 = f4(&aip);
85  int &ir3 = f4(&weak_global_ptr); // expected-error{{passing address of non-local object to __autoreleasing parameter for write-back}}
86}
87
88// Writeback conversion vs. other conversion.
89int &f5(id __autoreleasing *);
90float &f5(id const __unsafe_unretained *);
91
92void test_f5() {
93  id __strong sip;
94  id __weak wip;
95  id __autoreleasing aip;
96
97  int &ir1 = f5(&wip);
98  float &fr1 = f5(&sip);
99  int &ir2 = f5(&aip);
100}
101
102@interface A
103@end
104
105int &f6(id __autoreleasing *);
106float &f6(id const __unsafe_unretained *);
107
108void test_f6() {
109  A* __strong sip;
110  A* __weak wip;
111  A* __autoreleasing aip;
112
113  int &ir1 = f6(&wip);
114  float &fr1 = f6(&sip);
115  int &ir2 = f6(&aip);
116}
117
118// Reference binding
119void f7(__strong id&); // expected-note{{candidate function not viable: 1st argument ('__weak id') has __weak ownership, but parameter has __strong ownership}} \
120 // expected-note{{candidate function not viable: 1st argument ('__autoreleasing id') has __autoreleasing ownership, but parameter has __strong ownership}} \
121 // expected-note{{candidate function not viable: 1st argument ('__unsafe_unretained id') has __unsafe_unretained ownership, but parameter has __strong ownership}}
122
123void test_f7() {
124  __strong id strong_id;
125  __weak id weak_id;
126  __autoreleasing id autoreleasing_id;
127  __unsafe_unretained id unsafe_id;
128  f7(strong_id);
129  f7(weak_id); // expected-error{{no matching function for call to 'f7'}}
130  f7(autoreleasing_id); // expected-error{{no matching function for call to 'f7'}}
131  f7(unsafe_id); // expected-error{{no matching function for call to 'f7'}}
132}
133
134void f8(const __strong id&);
135
136void test_f8() {
137  __strong id strong_id;
138  __weak id weak_id;
139  __autoreleasing id autoreleasing_id;
140  __unsafe_unretained id unsafe_id;
141
142  f8(strong_id);
143  f8(weak_id);
144  f8(autoreleasing_id);
145  f8(unsafe_id);
146}
147
148int &f9(__strong id&);
149float &f9(const __autoreleasing id&);
150
151void test_f9() {
152  __strong id strong_id;
153  __weak id weak_id;
154  __autoreleasing id autoreleasing_id;
155  __unsafe_unretained id unsafe_id;
156
157  int &ir1 = f9(strong_id);
158  float &fr1 = f9(autoreleasing_id);
159  float &fr2 = f9(unsafe_id);
160  float &fr2a = f9(weak_id);
161
162  __strong A *strong_a;
163  __weak A *weak_a;
164  __autoreleasing A *autoreleasing_a;
165  __unsafe_unretained A *unsafe_unretained_a;
166  float &fr3 = f9(strong_a);
167  float &fr4 = f9(autoreleasing_a);
168  float &fr5 = f9(unsafe_unretained_a);
169  float &fr6 = f9(weak_a);
170
171  const __autoreleasing id& ar1 = strong_a;
172  const __autoreleasing id& ar2 = autoreleasing_a;
173  const __autoreleasing id& ar3 = unsafe_unretained_a;
174  const __autoreleasing id& ar4 = weak_a;
175}
176
177// rdar://9790531
178void f9790531(void *inClientData); // expected-note {{candidate function not viable: cannot implicitly convert argument of type 'MixerEQGraphTestDelegate *const __strong' to 'void *' for 1st argument under ARC}}
179void f9790531_1(struct S*inClientData); // expected-note {{candidate function not viable}}
180void f9790531_2(char * inClientData); // expected-note {{candidate function not viable}}
181
182@class UIApplication;
183
184@interface MixerEQGraphTestDelegate
185- (void)applicationDidFinishLaunching;
186@end
187
188@implementation MixerEQGraphTestDelegate
189- (void)applicationDidFinishLaunching {
190    f9790531(self); // expected-error {{no matching function for call to 'f9790531'}}
191    f9790531_1(self); // expected-error {{no matching function for call to 'f9790531_1'}}
192    f9790531_2(self); // expected-error {{no matching function for call to 'f9790531_2'}}
193}
194@end
195
196class rdar10142572 {
197  id f() __attribute__((ns_returns_retained));
198  id g(); // expected-note{{previous declaration}}
199};
200
201id rdar10142572::f() { return 0; } // okay: merged down
202id __attribute__((ns_returns_retained)) rdar10142572::g() { return 0; } // expected-error{{function declared with the ns_returns_retained attribute was previously declared without the ns_returns_retained attribute}}
203