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   {long x[1];};
12 struct two   {long x[2];};
13 struct three {long x[3];};
14 struct four  {long x[4];};
15 struct five  {long x[5];};
16 struct six   {long x[6];};
17 struct seven {long x[7];};
18 struct eight {long 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 // 7 at a time
32 
33 one   sink_7_1234567(               A&);
34 two   sink_7_1234567(const          A&);
35 three sink_7_1234567(volatile       A&);
36 four  sink_7_1234567(const volatile A&);
37 five  sink_7_1234567(               A&&);
38 six   sink_7_1234567(const          A&&);
39 seven sink_7_1234567(volatile       A&&);
40 
41 int test7_1234567()
42 {
43                    A a;
44     const          A ca;
45           volatile A va;
46     const volatile A cva;
47     sa<sizeof(sink_7_1234567(a))           == 1 * sizeof(long)> t1;
48     sa<sizeof(sink_7_1234567(ca))          == 2 * sizeof(long)> t2;
49     sa<sizeof(sink_7_1234567(va))          == 3 * sizeof(long)> t3;
50     sa<sizeof(sink_7_1234567(cva))         == 4 * sizeof(long)> t4;
51     sa<sizeof(sink_7_1234567(source()))    == 5 * sizeof(long)> t5;
52     sa<sizeof(sink_7_1234567(c_source()))  == 6 * sizeof(long)> t6;
53     sa<sizeof(sink_7_1234567(v_source()))  == 7 * sizeof(long)> t7;
54     return 0;
55 }
56 
57 one   sink_7_1234568(               A&);
58 two   sink_7_1234568(const          A&);
59 three sink_7_1234568(volatile       A&);
60 four  sink_7_1234568(const volatile A&);
61 five  sink_7_1234568(               A&&);
62 six   sink_7_1234568(const          A&&);
63 eight sink_7_1234568(const volatile A&&);
64 
65 int test7_1234568()
66 {
67                    A a;
68     const          A ca;
69           volatile A va;
70     const volatile A cva;
71     sa<sizeof(sink_7_1234568(a))           == 1 * sizeof(long)> t1;
72     sa<sizeof(sink_7_1234568(ca))          == 2 * sizeof(long)> t2;
73     sa<sizeof(sink_7_1234568(va))          == 3 * sizeof(long)> t3;
74     sa<sizeof(sink_7_1234568(cva))         == 4 * sizeof(long)> t4;
75     sa<sizeof(sink_7_1234568(source()))    == 5 * sizeof(long)> t5;
76     sa<sizeof(sink_7_1234568(c_source()))  == 6 * sizeof(long)> t6;
77     sa<sizeof(sink_7_1234568(v_source()))  == 8 * sizeof(long)> t7;
78     sa<sizeof(sink_7_1234568(cv_source())) == 8 * sizeof(long)> t8;
79     return 0;
80 }
81 
82 one   sink_7_1234578(               A&);
83 two   sink_7_1234578(const          A&);
84 three sink_7_1234578(volatile       A&);
85 four  sink_7_1234578(const volatile A&);
86 five  sink_7_1234578(               A&&);
87 seven sink_7_1234578(volatile       A&&);
88 eight sink_7_1234578(const volatile A&&);
89 
90 int test7_1234578()
91 {
92                    A a;
93     const          A ca;
94           volatile A va;
95     const volatile A cva;
96     sa<sizeof(sink_7_1234578(a))           == 1 * sizeof(long)> t1;
97     sa<sizeof(sink_7_1234578(ca))          == 2 * sizeof(long)> t2;
98     sa<sizeof(sink_7_1234578(va))          == 3 * sizeof(long)> t3;
99     sa<sizeof(sink_7_1234578(cva))         == 4 * sizeof(long)> t4;
100     sa<sizeof(sink_7_1234578(source()))    == 5 * sizeof(long)> t5;
101     sa<sizeof(sink_7_1234578(c_source()))  == 8 * sizeof(long)> t6;
102     sa<sizeof(sink_7_1234578(v_source()))  == 7 * sizeof(long)> t7;
103     sa<sizeof(sink_7_1234578(cv_source())) == 8 * sizeof(long)> t8;
104     return 0;
105 }
106 
107 one   sink_7_1234678(               A&);
108 two   sink_7_1234678(const          A&);
109 three sink_7_1234678(volatile       A&);
110 four  sink_7_1234678(const volatile A&);
111 six   sink_7_1234678(const          A&&);
112 seven sink_7_1234678(volatile       A&&);
113 eight sink_7_1234678(const volatile A&&);
114 
115 int test7_1234678()
116 {
117                    A a;
118     const          A ca;
119           volatile A va;
120     const volatile A cva;
121     sa<sizeof(sink_7_1234678(a))           == 1 * sizeof(long)> t1;
122     sa<sizeof(sink_7_1234678(ca))          == 2 * sizeof(long)> t2;
123     sa<sizeof(sink_7_1234678(va))          == 3 * sizeof(long)> t3;
124     sa<sizeof(sink_7_1234678(cva))         == 4 * sizeof(long)> t4;
125     sa<sizeof(sink_7_1234678(c_source()))  == 6 * sizeof(long)> t6;
126     sa<sizeof(sink_7_1234678(v_source()))  == 7 * sizeof(long)> t7;
127     sa<sizeof(sink_7_1234678(cv_source())) == 8 * sizeof(long)> t8;
128     return 0;
129 }
130 
131 one   sink_7_1235678(               A&);
132 two   sink_7_1235678(const          A&);
133 three sink_7_1235678(volatile       A&);
134 five  sink_7_1235678(               A&&);
135 six   sink_7_1235678(const          A&&);
136 seven sink_7_1235678(volatile       A&&);
137 eight sink_7_1235678(const volatile A&&);
138 
139 int test7_1235678()
140 {
141                    A a;
142     const          A ca;
143           volatile A va;
144     const volatile A cva;
145     sa<sizeof(sink_7_1235678(a))           == 1 * sizeof(long)> t1;
146     sa<sizeof(sink_7_1235678(ca))          == 2 * sizeof(long)> t2;
147     sa<sizeof(sink_7_1235678(va))          == 3 * sizeof(long)> t3;
148     sa<sizeof(sink_7_1235678(source()))    == 5 * sizeof(long)> t5;
149     sa<sizeof(sink_7_1235678(c_source()))  == 6 * sizeof(long)> t6;
150     sa<sizeof(sink_7_1235678(v_source()))  == 7 * sizeof(long)> t7;
151     sa<sizeof(sink_7_1235678(cv_source())) == 8 * sizeof(long)> t8;
152     return 0;
153 }
154 
155 one   sink_7_1245678(               A&);
156 two   sink_7_1245678(const          A&);
157 four  sink_7_1245678(const volatile A&);
158 five  sink_7_1245678(               A&&);
159 six   sink_7_1245678(const          A&&);
160 seven sink_7_1245678(volatile       A&&);
161 eight sink_7_1245678(const volatile A&&);
162 
163 int test7_1245678()
164 {
165                    A a;
166     const          A ca;
167           volatile A va;
168     const volatile A cva;
169     sa<sizeof(sink_7_1245678(a))           == 1 * sizeof(long)> t1;
170     sa<sizeof(sink_7_1245678(ca))          == 2 * sizeof(long)> t2;
171     sa<sizeof(sink_7_1245678(va))          == 4 * sizeof(long)> t3;
172     sa<sizeof(sink_7_1245678(cva))         == 4 * sizeof(long)> t4;
173     sa<sizeof(sink_7_1245678(source()))    == 5 * sizeof(long)> t5;
174     sa<sizeof(sink_7_1245678(c_source()))  == 6 * sizeof(long)> t6;
175     sa<sizeof(sink_7_1245678(v_source()))  == 7 * sizeof(long)> t7;
176     sa<sizeof(sink_7_1245678(cv_source())) == 8 * sizeof(long)> t8;
177     return 0;
178 }
179 
180 one   sink_7_1345678(               A&);
181 three sink_7_1345678(volatile       A&);
182 four  sink_7_1345678(const volatile A&);
183 five  sink_7_1345678(               A&&);
184 six   sink_7_1345678(const          A&&);
185 seven sink_7_1345678(volatile       A&&);
186 eight sink_7_1345678(const volatile A&&);
187 
188 int test7_1345678()
189 {
190                    A a;
191     const          A ca;
192           volatile A va;
193     const volatile A cva;
194     sa<sizeof(sink_7_1345678(a))           == 1 * sizeof(long)> t1;
195     sa<sizeof(sink_7_1345678(ca))          == 4 * sizeof(long)> t2;
196     sa<sizeof(sink_7_1345678(va))          == 3 * sizeof(long)> t3;
197     sa<sizeof(sink_7_1345678(cva))         == 4 * sizeof(long)> t4;
198     sa<sizeof(sink_7_1345678(source()))    == 5 * sizeof(long)> t5;
199     sa<sizeof(sink_7_1345678(c_source()))  == 6 * sizeof(long)> t6;
200     sa<sizeof(sink_7_1345678(v_source()))  == 7 * sizeof(long)> t7;
201     sa<sizeof(sink_7_1345678(cv_source())) == 8 * sizeof(long)> t8;
202     return 0;
203 }
204 
205 two   sink_7_2345678(const          A&);
206 three sink_7_2345678(volatile       A&);
207 four  sink_7_2345678(const volatile A&);
208 five  sink_7_2345678(               A&&);
209 six   sink_7_2345678(const          A&&);
210 seven sink_7_2345678(volatile       A&&);
211 eight sink_7_2345678(const volatile A&&);
212 
213 int test7_2345678()
214 {
215                    A a;
216     const          A ca;
217           volatile A va;
218     const volatile A cva;
219     sa<sizeof(sink_7_2345678(ca))          == 2 * sizeof(long)> t2;
220     sa<sizeof(sink_7_2345678(va))          == 3 * sizeof(long)> t3;
221     sa<sizeof(sink_7_2345678(cva))         == 4 * sizeof(long)> t4;
222     sa<sizeof(sink_7_2345678(source()))    == 5 * sizeof(long)> t5;
223     sa<sizeof(sink_7_2345678(c_source()))  == 6 * sizeof(long)> t6;
224     sa<sizeof(sink_7_2345678(v_source()))  == 7 * sizeof(long)> t7;
225     sa<sizeof(sink_7_2345678(cv_source())) == 8 * sizeof(long)> t8;
226     return 0;
227 }
228 
229 int main()
230 {
231     return test7_1234567() + test7_1234568() + test7_1234578() + test7_1234678() +
232            test7_1235678() + test7_1245678() + test7_1345678() + test7_2345678();
233 }
234