1 // RUN: %clang_cc1 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks -Wno-objc-root-class %s
3 // Simple ownership conversions + diagnostics.
4 int &f0(id __strong const *); // expected-note{{candidate function not viable: 1st argument ('__weak id *') has __weak ownership, but parameter has __strong ownership}}
8 id __strong const *csip;
10 id __autoreleasing *aip;
11 id __unsafe_unretained *uip;
17 f0(wip); // expected-error{{no matching function for call to 'f0'}}
21 int &f1(id __strong const *);
22 float &f1(id __weak const *);
26 id __strong const *csip;
28 id __autoreleasing *aip;
29 id __unsafe_unretained *uip;
39 int &f2(id __strong const *); // expected-note{{candidate function}}
40 float &f2(id __autoreleasing const *); // expected-note{{candidate function}}
44 id __strong const *csip;
46 id __autoreleasing *aip;
47 id __unsafe_unretained *uip;
49 // Prefer non-ownership conversions to ownership conversions.
54 f2(uip); // expected-error{{call to 'f2' is ambiguous}}
57 // Writeback conversion
58 int &f3(id __autoreleasing *); // expected-note{{candidate function not viable: 1st argument ('__unsafe_unretained id *') has __unsafe_unretained ownership, but parameter has __autoreleasing ownership}}
63 id __autoreleasing aip;
64 id __unsafe_unretained uip;
69 f3(&uip); // expected-error{{no matching function for call to 'f3'}}
72 // Writeback conversion vs. no conversion
73 int &f4(id __autoreleasing *);
74 float &f4(id __strong *);
79 id __autoreleasing aip;
80 extern __weak id weak_global_ptr;
82 float &fr1 = f4(&sip);
85 int &ir3 = f4(&weak_global_ptr); // expected-error{{passing address of non-local object to __autoreleasing parameter for write-back}}
88 // Writeback conversion vs. other conversion.
89 int &f5(id __autoreleasing *);
90 float &f5(id const __unsafe_unretained *);
95 id __autoreleasing aip;
98 float &fr1 = f5(&sip);
105 int &f6(id __autoreleasing *);
106 float &f6(id const __unsafe_unretained *);
111 A* __autoreleasing aip;
114 float &fr1 = f6(&sip);
119 void 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}}
124 __strong id strong_id;
126 __autoreleasing id autoreleasing_id;
127 __unsafe_unretained id unsafe_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'}}
134 void f8(const __strong id&);
137 __strong id strong_id;
139 __autoreleasing id autoreleasing_id;
140 __unsafe_unretained id unsafe_id;
144 f8(autoreleasing_id);
148 int &f9(__strong id&);
149 float &f9(const __autoreleasing id&);
152 __strong id strong_id;
154 __autoreleasing id autoreleasing_id;
155 __unsafe_unretained id unsafe_id;
157 int &ir1 = f9(strong_id);
158 float &fr1 = f9(autoreleasing_id);
159 float &fr2 = f9(unsafe_id);
160 float &fr2a = f9(weak_id);
162 __strong A *strong_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);
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;
177 int &f10(__strong id *&); // expected-note 2{{not viable: no known conversion}}
178 float &f10(__autoreleasing id *&); // expected-note 2{{not viable: no known conversion}}
181 __strong id *strong_id;
183 __autoreleasing id *autoreleasing_id;
184 __unsafe_unretained id *unsafe_id;
186 int &ir1 = f10(strong_id);
187 float &fr1 = f10(autoreleasing_id);
188 float &fr2 = f10(unsafe_id); // expected-error {{no match}}
189 float &fr2a = f10(weak_id); // expected-error {{no match}}
192 int &f11(__strong id *const &); // expected-note {{not viable: 1st argument ('__weak id *') has __weak ownership, but parameter has __strong ownership}}
193 float &f11(const __autoreleasing id *const &); // expected-note {{not viable: 1st argument ('__weak id *') has __weak ownership, but parameter has __autoreleasing ownership}}
196 __strong id *strong_id;
198 __autoreleasing id *autoreleasing_id;
199 __unsafe_unretained id *unsafe_id;
201 int &ir1 = f11(strong_id);
202 float &fr1 = f11(autoreleasing_id);
203 float &fr2 = f11(unsafe_id);
204 float &fr2a = f11(weak_id); // expected-error {{no match}}
207 void 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}}
208 void f9790531_1(struct S*inClientData); // expected-note {{candidate function not viable}}
209 void f9790531_2(char * inClientData); // expected-note {{candidate function not viable}}
211 @class UIApplication;
213 @interface MixerEQGraphTestDelegate
214 - (void)applicationDidFinishLaunching;
217 @implementation MixerEQGraphTestDelegate
218 - (void)applicationDidFinishLaunching {
219 f9790531(self); // expected-error {{no matching function for call to 'f9790531'}}
220 f9790531_1(self); // expected-error {{no matching function for call to 'f9790531_1'}}
221 f9790531_2(self); // expected-error {{no matching function for call to 'f9790531_2'}}
226 id f() __attribute__((ns_returns_retained));
227 id g(); // expected-note{{previous declaration}}
230 id rdar10142572::f() { return 0; } // okay: merged down
231 id __attribute__((ns_returns_retained)) rdar10142572::g() { return 0; } // expected-error{{function declared with 'ns_returns_retained' attribute was previously declared without the 'ns_returns_retained' attribute}}