1 // I, Howard Hinnant, hereby place this code in the public domain.
2 
3 // Test overload resolution among reference types
4 
5 // { dg-do compile }
6 // { dg-options "-std=c++0x" }
7 
8 template <bool> struct sa;
9 template <> struct sa<true> {};
10 
11 struct one   {char x[1];};
12 struct two   {char x[2];};
13 struct three {char x[3];};
14 struct four  {char x[4];};
15 struct five  {char x[5];};
16 struct six   {char x[6];};
17 struct seven {char x[7];};
18 struct eight {char x[8];};
19 
20 struct A
21 {
22     A();
23     A(const volatile A&&);
24 };
25 
26                A    source();
27 const          A  c_source();
28       volatile A  v_source();
29 const volatile A cv_source();
30 
31 // 2 at a time
32 
33 one   sink_2_12(               A&);  // { dg-message "note|argument" }
34 two   sink_2_12(const          A&);  // { dg-message "note|argument" }
35 
36 int test2_12()
37 {
38                    A a;
39     const          A ca = a; // { dg-error "deleted" }
40           volatile A va;
41     const volatile A cva = a; // { dg-error "deleted" }
42     sink_2_12(va);           // { dg-error "no match" }
43     // { dg-message "candidate" "candidate note" { target *-*-* } 42 }
44     sink_2_12(cva);          // { dg-error "no match" }
45     // { dg-message "candidate" "candidate note" { target *-*-* } 44 }
46     sink_2_12(v_source());   // { dg-error "no match" }
47     // { dg-message "candidate" "candidate note" { target *-*-* } 46 }
48     sink_2_12(cv_source());  // { dg-error "no match" }
49     // { dg-message "candidate" "candidate note" { target *-*-* } 48 }
50     return 0;
51 }
52 
53 one   sink_2_13(               A&);  // { dg-message "note|argument" }
54 three sink_2_13(volatile       A&);  // { dg-message "note|argument" }
55 
56 int test2_13()
57 {
58                    A a;
59     const          A ca = a; // { dg-error "deleted" }
60           volatile A va;
61     const volatile A cva = a; // { dg-error "deleted" }
62     sink_2_13(ca);           // { dg-error "no match" }
63     // { dg-message "candidate" "candidate note" { target *-*-* } 62 }
64     sink_2_13(cva);          // { dg-error "no match" }
65     // { dg-message "candidate" "candidate note" { target *-*-* } 64 }
66     sink_2_13(source());     // { dg-error "no match" }
67     // { dg-message "candidate" "candidate note" { target *-*-* } 66 }
68     sink_2_13(c_source());   // { dg-error "no match" }
69     // { dg-message "candidate" "candidate note" { target *-*-* } 68 }
70     sink_2_13(v_source());   // { dg-error "no match" }
71     // { dg-message "candidate" "candidate note" { target *-*-* } 70 }
72     sink_2_13(cv_source());  // { dg-error "no match" }
73     // { dg-message "candidate" "candidate note" { target *-*-* } 72 }
74     return 0;
75 }
76 
77 one   sink_2_14(               A&);  // { dg-message "note|argument" }
78 four  sink_2_14(const volatile A&);  // { dg-message "note|argument" }
79 
80 int test2_14()
81 {
82                    A a;
83     const          A ca = a; // { dg-error "deleted" }
84           volatile A va;
85     const volatile A cva = a; // { dg-error "deleted" }
86     sink_2_14(source());     // { dg-error "no match" }
87     // { dg-message "candidate" "candidate note" { target *-*-* } 86 }
88     sink_2_14(c_source());   // { dg-error "no match" }
89     // { dg-message "candidate" "candidate note" { target *-*-* } 88 }
90     sink_2_14(v_source());   // { dg-error "no match" }
91     // { dg-message "candidate" "candidate note" { target *-*-* } 90 }
92     sink_2_14(cv_source());  // { dg-error "no match" }
93     // { dg-message "candidate" "candidate note" { target *-*-* } 92 }
94     return 0;
95 }
96 
97 one   sink_2_15(               A&);  // { dg-message "note|argument" }
98 five  sink_2_15(               A&&);  // { dg-message "note|argument" }
99 
100 int test2_15()
101 {
102                    A a;
103     const          A ca = a; // { dg-error "deleted" }
104           volatile A va;
105     const volatile A cva = a; // { dg-error "deleted" }
106    sink_2_15(ca);           // { dg-error "no match" }
107    // { dg-message "candidate" "candidate note" { target *-*-* } 106 }
108    sink_2_15(va);           // { dg-error "no match" }
109    // { dg-message "candidate" "candidate note" { target *-*-* } 108 }
110    sink_2_15(cva);          // { dg-error "no match" }
111    // { dg-message "candidate" "candidate note" { target *-*-* } 110 }
112    sink_2_15(c_source());   // { dg-error "no match" }
113    // { dg-message "candidate" "candidate note" { target *-*-* } 112 }
114    sink_2_15(v_source());   // { dg-error "no match" }
115    // { dg-message "candidate" "candidate note" { target *-*-* } 114 }
116    sink_2_15(cv_source());  // { dg-error "no match" }
117    // { dg-message "candidate" "candidate note" { target *-*-* } 116 }
118     return 0;
119 }
120 
121 one   sink_2_16(               A&);  // { dg-message "note|argument" }
122 six   sink_2_16(const          A&&);  // { dg-message "note|argument" }
123 
124 int test2_16()
125 {
126                    A a;
127     const          A ca = a; // { dg-error "deleted" }
128           volatile A va;
129     const volatile A cva = a; // { dg-error "deleted" }
130     sink_2_16(ca);	     // { dg-error "lvalue" }
131     sink_2_16(va);           // { dg-error "no match" }
132     // { dg-message "candidate" "candidate note" { target *-*-* } 131 }
133     sink_2_16(cva);          // { dg-error "no match" }
134     // { dg-message "candidate" "candidate note" { target *-*-* } 133 }
135     sink_2_16(v_source());   // { dg-error "no match" }
136     // { dg-message "candidate" "candidate note" { target *-*-* } 135 }
137     sink_2_16(cv_source());  // { dg-error "no match" }
138     // { dg-message "candidate" "candidate note" { target *-*-* } 137 }
139     return 0;
140 }
141 
142 one   sink_2_17(               A&);  // { dg-message "note|argument" }
143 seven sink_2_17(volatile       A&&);  // { dg-message "note|argument" }
144 
145 int test2_17()
146 {
147                    A a;
148     const          A ca = a; // { dg-error "deleted" }
149           volatile A va;
150     const volatile A cva = a; // { dg-error "deleted" }
151     sink_2_17(ca);           // { dg-error "no match" }
152     // { dg-message "candidate" "candidate note" { target *-*-* } 151 }
153     sink_2_17(va);           // { dg-error "lvalue" }
154     sink_2_17(cva);          // { dg-error "no match" }
155     // { dg-message "candidate" "candidate note" { target *-*-* } 154 }
156     sink_2_17(c_source());   // { dg-error "no match" }
157     // { dg-message "candidate" "candidate note" { target *-*-* } 156 }
158     sink_2_17(cv_source());  // { dg-error "no match" }
159     // { dg-message "candidate" "candidate note" { target *-*-* } 158 }
160     return 0;
161 }
162 
163 one   sink_2_18(               A&);
164 eight sink_2_18(const volatile A&&); // { dg-error "argument" }
165 
166 int test2_18()
167 {
168                    A a;
169     const          A ca = a; // { dg-error "deleted" }
170           volatile A va;
171     const volatile A cva = a; // { dg-error "deleted" }
172     sink_2_18(ca);		// { dg-error "lvalue" }
173     sink_2_18(va);		// { dg-error "lvalue" }
174     sink_2_18(cva);		// { dg-error "lvalue" }
175 }
176 
177 two   sink_2_23(const          A&);  // { dg-message "note|argument" }
178 three sink_2_23(volatile       A&);  // { dg-message "note|argument" }
179 
180 int test2_23()
181 {
182                    A a;
183     const          A ca = a; // { dg-error "deleted" }
184           volatile A va;
185     const volatile A cva = a; // { dg-error "deleted" }
186     sink_2_23(a);            // { dg-error "ambiguous" }
187     // { dg-message "candidate" "candidate note" { target *-*-* } 186 }
188     sink_2_23(cva);          // { dg-error "no match" }
189     // { dg-message "candidate" "candidate note" { target *-*-* } 188 }
190     sink_2_23(v_source());   // { dg-error "no match" }
191     // { dg-message "candidate" "candidate note" { target *-*-* } 190 }
192     sink_2_23(cv_source());  // { dg-error "no match" }
193     // { dg-message "candidate" "candidate note" { target *-*-* } 192 }
194     return 0;
195 }
196 
197 two   sink_2_24(const          A&);  // { dg-message "note|argument" }
198 four  sink_2_24(const volatile A&);  // { dg-message "note|argument" }
199 
200 int test2_24()
201 {
202                    A a;
203     const          A ca = a; // { dg-error "deleted" }
204           volatile A va;
205     const volatile A cva = a; // { dg-error "deleted" }
206     sink_2_24(v_source());   // { dg-error "no match" }
207     // { dg-message "candidate" "candidate note" { target *-*-* } 206 }
208     sink_2_24(cv_source());  // { dg-error "no match" }
209     // { dg-message "candidate" "candidate note" { target *-*-* } 208 }
210     return 0;
211 }
212 
213 three sink_2_34(volatile       A&);  // { dg-message "three sink_2_34|no known conversion" }
214 four  sink_2_34(const volatile A&);  // { dg-message "note|argument" }
215 
216 int test2_34()
217 {
218                    A a;
219     const          A ca = a; // { dg-error "deleted" }
220           volatile A va;
221     const volatile A cva = a; // { dg-error "deleted" }
222     sink_2_34(source());     // { dg-error "no match" }
223     // { dg-message "candidate" "candidate note" { target *-*-* } 222 }
224     sink_2_34(c_source());   // { dg-error "no match" }
225     // { dg-message "candidate" "candidate note" { target *-*-* } 224 }
226     sink_2_34(v_source());   // { dg-error "no match" }
227     // { dg-message "candidate" "candidate note" { target *-*-* } 226 }
228     sink_2_34(cv_source());  // { dg-error "no match" }
229     // { dg-message "candidate" "candidate note" { target *-*-* } 228 }
230     return 0;
231 }
232 
233 two   sink_2_25(const          A&);  // { dg-message "two sink_2_25|no known conversion" }
234 five  sink_2_25(               A&&);  // { dg-message "note|argument" }
235 
236 int test2_25()
237 {
238                    A a;
239     const          A ca = a; // { dg-error "deleted" }
240           volatile A va;
241     const volatile A cva = a; // { dg-error "deleted" }
242    sink_2_25(va);           // { dg-error "no match" }
243    // { dg-message "candidate" "candidate note" { target *-*-* } 242 }
244    sink_2_25(cva);          // { dg-error "no match" }
245    // { dg-message "candidate" "candidate note" { target *-*-* } 244 }
246    sink_2_25(v_source());   // { dg-error "no match" }
247    // { dg-message "candidate" "candidate note" { target *-*-* } 246 }
248    sink_2_25(cv_source());  // { dg-error "no match" }
249    // { dg-message "candidate" "candidate note" { target *-*-* } 248 }
250     return 0;
251 }
252 
253 two   sink_2_26(const          A&);  // { dg-message "two sink_2_26|no known conversion" }
254 six   sink_2_26(const          A&&);  // { dg-message "note|argument" }
255 
256 int test2_26()
257 {
258                    A a;
259     const          A ca = a; // { dg-error "deleted" }
260           volatile A va;
261     const volatile A cva = a; // { dg-error "deleted" }
262     sink_2_26(va);           // { dg-error "no match" }
263     // { dg-message "candidate" "candidate note" { target *-*-* } 262 }
264     sink_2_26(cva);          // { dg-error "no match" }
265     // { dg-message "candidate" "candidate note" { target *-*-* } 264 }
266     sink_2_26(v_source());   // { dg-error "no match" }
267     // { dg-message "candidate" "candidate note" { target *-*-* } 266 }
268     sink_2_26(cv_source());  // { dg-error "no match" }
269     // { dg-message "candidate" "candidate note" { target *-*-* } 268 }
270     return 0;
271 }
272 
273 two   sink_2_27(const          A&);  // { dg-message "two sink_2_27|no known conversion" }
274 seven sink_2_27(volatile       A&&);  // { dg-message "note|argument" }
275 
276 int test2_27()
277 {
278                    A a;
279     const          A ca = a; // { dg-error "deleted" }
280           volatile A va;
281     const volatile A cva = a; // { dg-error "deleted" }
282     sink_2_27(va);	     // { dg-error "lvalue" }
283     sink_2_27(cva);          // { dg-error "no match" }
284     // { dg-message "candidate" "candidate note" { target *-*-* } 283 }
285     sink_2_27(cv_source());  // { dg-error "no match" }
286     // { dg-message "candidate" "candidate note" { target *-*-* } 285 }
287     return 0;
288 }
289 
290 two   sink_2_28(const          A&);
291 eight sink_2_28(const volatile A&&); // { dg-error "argument" }
292 
293 int test2_28()
294 {
295                    A a;
296     const          A ca = a; // { dg-error "deleted" }
297           volatile A va;
298     const volatile A cva = a; // { dg-error "deleted" }
299     sink_2_28(va);		// { dg-error "lvalue" }
300     sink_2_28(cva);		// { dg-error "lvalue" }
301 }
302 
303 three sink_2_35(volatile       A&);  // { dg-message "three sink_2_35|no known conversion" }
304 five  sink_2_35(               A&&);  // { dg-message "note|argument" }
305 
306 int test2_35()
307 {
308                    A a;
309     const          A ca = a; // { dg-error "deleted" }
310           volatile A va;
311     const volatile A cva = a; // { dg-error "deleted" }
312     sink_2_35(ca);           // { dg-error "no match" }
313     // { dg-message "candidate" "candidate note" { target *-*-* } 312 }
314     sink_2_35(cva);          // { dg-error "no match" }
315     // { dg-message "candidate" "candidate note" { target *-*-* } 314 }
316     sink_2_35(c_source());   // { dg-error "no match" }
317     // { dg-message "candidate" "candidate note" { target *-*-* } 316 }
318     sink_2_35(v_source());   // { dg-error "no match" }
319     // { dg-message "candidate" "candidate note" { target *-*-* } 318 }
320     sink_2_35(cv_source());  // { dg-error "no match" }
321     // { dg-message "candidate" "candidate note" { target *-*-* } 320 }
322     return 0;
323 }
324 
325 three sink_2_36(volatile       A&);  // { dg-message "three sink_2_36|no known conversion" }
326 six   sink_2_36(const          A&&);  // { dg-message "note|argument" }
327 
328 int test2_36()
329 {
330                    A a;
331     const          A ca = a; // { dg-error "deleted" }
332           volatile A va;
333     const volatile A cva = a; // { dg-error "deleted" }
334     sink_2_36(ca);		// { dg-error "lvalue" }
335     sink_2_36(cva);          // { dg-error "no match" }
336     // { dg-message "candidate" "candidate note" { target *-*-* } 335 }
337     sink_2_36(v_source());   // { dg-error "no match" }
338     // { dg-message "candidate" "candidate note" { target *-*-* } 337 }
339     sink_2_36(cv_source());  // { dg-error "no match" }
340     // { dg-message "candidate" "candidate note" { target *-*-* } 339 }
341     return 0;
342 }
343 
344 three sink_2_37(volatile       A&);  // { dg-message "three sink_2_37|no known conversion" }
345 seven sink_2_37(volatile       A&&);  // { dg-message "note|argument" }
346 
347 int test2_37()
348 {
349                    A a;
350     const          A ca = a; // { dg-error "deleted" }
351           volatile A va;
352     const volatile A cva = a; // { dg-error "deleted" }
353     sink_2_37(ca);           // { dg-error "no match" }
354     // { dg-message "candidate" "candidate note" { target *-*-* } 353 }
355     sink_2_37(cva);          // { dg-error "no match" }
356     // { dg-message "candidate" "candidate note" { target *-*-* } 355 }
357     sink_2_37(c_source());   // { dg-error "no match" }
358     // { dg-message "candidate" "candidate note" { target *-*-* } 357 }
359     sink_2_37(cv_source());  // { dg-error "no match" }
360     // { dg-message "candidate" "candidate note" { target *-*-* } 359 }
361     return 0;
362 }
363 
364 three sink_2_38(volatile       A&);
365 eight sink_2_38(const volatile A&&); // { dg-error "argument" }
366 
367 int test2_38()
368 {
369                    A a;
370     const          A ca = a; // { dg-error "deleted" }
371           volatile A va;
372     const volatile A cva = a; // { dg-error "deleted" }
373     sink_2_38(ca);		// { dg-error "lvalue" }
374     sink_2_38(cva);		// { dg-error "lvalue" }
375 }
376 
377 four  sink_2_45(const volatile A&);   // { dg-message "note" }
378 five  sink_2_45(               A&&);  // { dg-message "note|argument" }
379 
380 int test2_45()
381 {
382                    A a;
383     const          A ca = a; // { dg-error "deleted" }
384           volatile A va;
385     const volatile A cva = a; // { dg-error "deleted" }
386     sink_2_45(c_source());   // { dg-error "no match" }
387     // { dg-message "candidate" "candidate note" { target *-*-* } 386 }
388     sink_2_45(v_source());   // { dg-error "no match" }
389     // { dg-message "candidate" "candidate note" { target *-*-* } 388 }
390     sink_2_45(cv_source());  // { dg-error "no match" }
391     // { dg-message "candidate" "candidate note" { target *-*-* } 390 }
392     return 0;
393 }
394 
395 four  sink_2_46(const volatile A&);   // { dg-message "note" }
396 six   sink_2_46(const          A&&);  // { dg-message "note|argument" }
397 
398 int test2_46()
399 {
400                    A a;
401     const          A ca = a; // { dg-error "deleted" }
402           volatile A va;
403     const volatile A cva = a; // { dg-error "deleted" }
404     sink_2_46(v_source());   // { dg-error "no match" }
405     // { dg-message "candidate" "candidate note" { target *-*-* } 404 }
406     sink_2_46(cv_source());  // { dg-error "no match" }
407     // { dg-message "candidate" "candidate note" { target *-*-* } 406 }
408     return 0;
409 }
410 
411 four  sink_2_47(const volatile A&);   // { dg-message "note" }
412 seven sink_2_47(volatile       A&&);  // { dg-message "note|argument" }
413 
414 int test2_47()
415 {
416                    A a;
417     const          A ca = a; // { dg-error "deleted" }
418           volatile A va;
419     const volatile A cva = a; // { dg-error "deleted" }
420     sink_2_47(c_source());   // { dg-error "no match" }
421     // { dg-message "candidate" "candidate note" { target *-*-* } 420 }
422     sink_2_47(cv_source());  // { dg-error "no match" }
423     // { dg-message "candidate" "candidate note" { target *-*-* } 422 }
424     return 0;
425 }
426 
427 five  sink_2_56(               A&&);  // { dg-message "note|argument" }
428 six   sink_2_56(const          A&&);  // { dg-message "note|argument" }
429 
430 int test2_56()
431 {
432                    A a;
433     const          A ca = a; // { dg-error "deleted" }
434           volatile A va;
435     const volatile A cva = a; // { dg-error "deleted" }
436     sink_2_56(a);		// { dg-error "lvalue" }
437     sink_2_56(ca);		// { dg-error "lvalue" }
438     sink_2_56(va);           // { dg-error "no match" }
439     // { dg-message "candidate" "candidate note" { target *-*-* } 438 }
440     sink_2_56(cva);          // { dg-error "no match" }
441     // { dg-message "candidate" "candidate note" { target *-*-* } 440 }
442     sink_2_56(v_source());   // { dg-error "no match" }
443     // { dg-message "candidate" "candidate note" { target *-*-* } 442 }
444     sink_2_56(cv_source());  // { dg-error "no match" }
445     // { dg-message "candidate" "candidate note" { target *-*-* } 444 }
446     return 0;
447 }
448 
449 five  sink_2_57(               A&&);  // { dg-message "note|argument" }
450 seven sink_2_57(volatile       A&&);  // { dg-message "note|argument" }
451 
452 int test2_57()
453 {
454                    A a;
455     const          A ca = a; // { dg-error "deleted" }
456           volatile A va;
457     const volatile A cva = a; // { dg-error "deleted" }
458     sink_2_57(a);		// { dg-error "lvalue" }
459     sink_2_57(va);		// { dg-error "lvalue" }
460     sink_2_57(ca);           // { dg-error "no match" }
461     // { dg-message "candidate" "candidate note" { target *-*-* } 460 }
462     sink_2_57(cva);          // { dg-error "no match" }
463     // { dg-message "candidate" "candidate note" { target *-*-* } 462 }
464     sink_2_57(c_source());   // { dg-error "no match" }
465     // { dg-message "candidate" "candidate note" { target *-*-* } 464 }
466     sink_2_57(cv_source());  // { dg-error "no match" }
467     // { dg-message "candidate" "candidate note" { target *-*-* } 466 }
468     return 0;
469 }
470 
471 five  sink_2_58(               A&&); // { dg-error "argument" }
472 eight sink_2_58(const volatile A&&); // { dg-error "argument" }
473 
474 int test2_58()
475 {
476                    A a;
477     const          A ca = a; // { dg-error "deleted" }
478           volatile A va;
479     const volatile A cva = a; // { dg-error "deleted" }
480     sink_2_58(a);		// { dg-error "lvalue" }
481     sink_2_58(ca);		// { dg-error "lvalue" }
482     sink_2_58(va);		// { dg-error "lvalue" }
483     sink_2_58(cva);		// { dg-error "lvalue" }
484 }
485 
486 six   sink_2_67(const          A&&);  // { dg-message "note|argument" }
487 seven sink_2_67(volatile       A&&);  // { dg-message "note|argument" }
488 
489 int test2_67()
490 {
491                    A a;
492     const          A ca = a; // { dg-error "deleted" }
493           volatile A va;
494     const volatile A cva = a; // { dg-error "deleted" }
495     sink_2_67(a);            // { dg-error "ambiguous" }
496     // { dg-message "candidate" "candidate note" { target *-*-* } 495 }
497     sink_2_67(ca);	     // { dg-error "lvalue" }
498     sink_2_67(va);	     // { dg-error "lvalue" }
499     sink_2_67(cva);          // { dg-error "no match" }
500     // { dg-message "candidate" "candidate note" { target *-*-* } 499 }
501     sink_2_67(source());     // { dg-error "ambiguous" }
502     // { dg-message "candidate" "candidate note" { target *-*-* } 501 }
503     sink_2_67(cv_source());  // { dg-error "no match" }
504     // { dg-message "candidate" "candidate note" { target *-*-* } 503 }
505     return 0;
506 }
507 
508 six   sink_2_68(const          A&&); // { dg-error "argument" }
509 eight sink_2_68(const volatile A&&); // { dg-error "argument" }
510 
511 int test2_68()
512 {
513                    A a;
514     const          A ca = a; // { dg-error "deleted" }
515           volatile A va;
516     const volatile A cva = a; // { dg-error "deleted" }
517     sink_2_68(a);		// { dg-error "lvalue" }
518     sink_2_68(ca);		// { dg-error "lvalue" }
519     sink_2_68(va);		// { dg-error "lvalue" }
520     sink_2_68(cva);		// { dg-error "lvalue" }
521 }
522 
523 seven sink_2_78(volatile       A&&); // { dg-error "argument" }
524 eight sink_2_78(const volatile A&&); // { dg-error "argument" }
525 
526 int test2_78()
527 {
528                    A a;
529     const          A ca = a; // { dg-error "deleted" }
530           volatile A va;
531     const volatile A cva = a; // { dg-error "deleted" }
532     sink_2_78(a);		// { dg-error "lvalue" }
533     sink_2_78(ca);		// { dg-error "lvalue" }
534     sink_2_78(va);		// { dg-error "lvalue" }
535     sink_2_78(cva);		// { dg-error "lvalue" }
536 }
537 
538 int main()
539 {
540     return test2_12() + test2_13() + test2_15() + test2_16() +
541            test2_17() + test2_23() + test2_25() + test2_26() +
542            test2_27() + test2_35() + test2_36() + test2_37() +
543            test2_56() + test2_57() + test2_67();
544 }
545