| 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. |
| 4 |
int &f0(id __strong const *); // expected-note{{candidate function not viable: 1st argument ('__weak id *') has __weak ownership, but parameter has __strong ownership}} |
| 5 |
|
| 6 |
void 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 |
| 21 |
int &f1(id __strong const *); |
| 22 |
float &f1(id __weak const *); |
| 23 |
|
| 24 |
void 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 |
| 39 |
int &f2(id __strong const *); // expected-note{{candidate function}} |
| 40 |
float &f2(id __autoreleasing const *); // expected-note{{candidate function}} |
| 41 |
|
| 42 |
void 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 |
| 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}} |
| 59 |
|
| 60 |
void 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 |
| 73 |
int &f4(id __autoreleasing *); |
| 74 |
float &f4(id __strong *); |
| 75 |
|
| 76 |
void 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. |
| 89 |
int &f5(id __autoreleasing *); |
| 90 |
float &f5(id const __unsafe_unretained *); |
| 91 |
|
| 92 |
void 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 |
|
| 105 |
int &f6(id __autoreleasing *); |
| 106 |
float &f6(id const __unsafe_unretained *); |
| 107 |
|
| 108 |
void 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 |
| 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}} |
| 122 |
|
| 123 |
void 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 |
|
| 134 |
void f8(const __strong id&); |
| 135 |
|
| 136 |
void 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 |
|
| 148 |
int &f9(__strong id&); |
| 149 |
float &f9(const __autoreleasing id&); |
| 150 |
|
| 151 |
void 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 |
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}} |
| 179 |
|
| 180 |
void test_f10() { |
| 181 |
__strong id *strong_id; |
| 182 |
__weak id *weak_id; |
| 183 |
__autoreleasing id *autoreleasing_id; |
| 184 |
__unsafe_unretained id *unsafe_id; |
| 185 |
|
| 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}} |
| 190 |
} |
| 191 |
|
| 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}} |
| 194 |
|
| 195 |
void test_f11() { |
| 196 |
__strong id *strong_id; |
| 197 |
__weak id *weak_id; |
| 198 |
__autoreleasing id *autoreleasing_id; |
| 199 |
__unsafe_unretained id *unsafe_id; |
| 200 |
|
| 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}} |
| 205 |
} |
| 206 |
|
| 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}} |
| 210 |
|
| 211 |
@class UIApplication; |
| 212 |
|
| 213 |
@interface MixerEQGraphTestDelegate |
| 214 |
- (void)applicationDidFinishLaunching; |
| 215 |
@end |
| 216 |
|
| 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'}} |
| 222 |
} |
| 223 |
@end |
| 224 |
|
| 225 |
class rdar10142572 { |
| 226 |
id f() __attribute__((ns_returns_retained)); |
| 227 |
id g(); // expected-note{{previous declaration}} |
| 228 |
}; |
| 229 |
|
| 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}} |