Commit | Line | Data |
---|---|---|
6a3c6ee4 PA |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
e2882c85 | 3 | Copyright 2017-2018 Free Software Foundation, Inc. |
6a3c6ee4 PA |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include <cstddef> | |
19 | ||
20 | /* Code for operator() tests. */ | |
21 | ||
22 | struct test_unique_op_call | |
23 | { | |
24 | void operator() (int); | |
25 | }; | |
26 | ||
27 | void | |
28 | test_unique_op_call::operator() (int) | |
29 | {} | |
30 | ||
31 | struct test_op_call | |
32 | { | |
33 | void operator() (); | |
34 | void operator() (int); | |
35 | void operator() (long); | |
36 | ||
37 | template<typename T> | |
38 | void operator() (T *); | |
39 | }; | |
40 | ||
41 | void | |
42 | test_op_call::operator() (int) | |
43 | {} | |
44 | ||
45 | void | |
46 | test_op_call::operator() () | |
47 | {} | |
48 | ||
49 | void | |
50 | test_op_call::operator() (long) | |
51 | {} | |
52 | ||
53 | template<typename T> | |
54 | void | |
55 | test_op_call::operator() (T *t) | |
56 | { | |
57 | } | |
58 | ||
59 | /* Code for operator[] tests. */ | |
60 | ||
61 | struct test_unique_op_array | |
62 | { | |
63 | void operator[] (int); | |
64 | }; | |
65 | ||
66 | void | |
67 | test_unique_op_array::operator[] (int) | |
68 | {} | |
69 | ||
70 | struct test_op_array | |
71 | { | |
72 | void operator[] (int); | |
73 | void operator[] (long); | |
74 | ||
75 | template<typename T> | |
76 | void operator[] (T *); | |
77 | }; | |
78 | ||
79 | void | |
80 | test_op_array::operator[] (int) | |
81 | {} | |
82 | ||
83 | void | |
84 | test_op_array::operator[] (long) | |
85 | {} | |
86 | ||
87 | template<typename T> | |
88 | void | |
89 | test_op_array::operator[] (T *t) | |
90 | {} | |
91 | ||
92 | /* Code for operator new tests. */ | |
93 | ||
94 | struct test_op_new | |
95 | { | |
96 | void *operator new (size_t); | |
97 | }; | |
98 | ||
99 | void * | |
100 | test_op_new::operator new (size_t) | |
101 | { | |
102 | return NULL; | |
103 | } | |
104 | ||
105 | /* Code for operator delete tests. */ | |
106 | ||
107 | struct test_op_delete | |
108 | { | |
109 | void operator delete (void *); | |
110 | }; | |
111 | ||
112 | void | |
113 | test_op_delete::operator delete (void *) | |
114 | { | |
115 | } | |
116 | ||
117 | /* Code for operator new[] tests. */ | |
118 | ||
119 | struct test_op_new_array | |
120 | { | |
121 | void *operator new[] (size_t); | |
122 | }; | |
123 | ||
124 | void * | |
125 | test_op_new_array::operator new[] (size_t) | |
126 | { | |
127 | return NULL; | |
128 | } | |
129 | ||
130 | /* Code for operator delete[] tests. */ | |
131 | ||
132 | struct test_op_delete_array | |
133 | { | |
134 | void operator delete[] (void *); | |
135 | }; | |
136 | ||
137 | void | |
138 | test_op_delete_array::operator delete[] (void *) | |
139 | { | |
140 | } | |
141 | ||
142 | /* Code for user-defined conversion tests. */ | |
143 | ||
144 | struct test_op_conversion_res; | |
145 | ||
146 | struct test_op_conversion | |
147 | { | |
148 | operator const volatile test_op_conversion_res **() const volatile; | |
149 | }; | |
150 | ||
151 | test_op_conversion::operator const volatile test_op_conversion_res **() | |
152 | const volatile | |
153 | { | |
154 | return NULL; | |
155 | } | |
156 | ||
157 | /* Code for the assignment operator tests. */ | |
158 | ||
159 | struct test_op_assign | |
160 | { | |
161 | test_op_assign operator= (const test_op_assign &); | |
162 | }; | |
163 | ||
164 | test_op_assign | |
165 | test_op_assign::operator= (const test_op_assign &) | |
166 | { | |
167 | return test_op_assign (); | |
168 | } | |
169 | ||
170 | /* Code for the arrow operator tests. */ | |
171 | ||
172 | struct test_op_arrow | |
173 | { | |
174 | test_op_arrow operator-> (); | |
175 | }; | |
176 | ||
177 | test_op_arrow | |
178 | test_op_arrow::operator-> () | |
179 | { | |
180 | return test_op_arrow (); | |
181 | } | |
182 | ||
183 | /* Code for the logical/arithmetic operators tests. */ | |
184 | ||
185 | struct E | |
186 | { | |
187 | }; | |
188 | ||
189 | #define GEN_OP(NS, ...) \ | |
190 | namespace test_ops { \ | |
191 | void operator __VA_ARGS__ {} \ | |
192 | } \ | |
193 | namespace test_op_ ## NS { \ | |
194 | void operator __VA_ARGS__ {} \ | |
195 | } | |
196 | ||
197 | GEN_OP (PLUS_A, += (E, E) ) | |
198 | GEN_OP (PLUS, + (E, E) ) | |
199 | GEN_OP (MINUS_A, -= (E, E) ) | |
200 | GEN_OP (MINUS, - (E, E) ) | |
201 | GEN_OP (MOD_A, %= (E, E) ) | |
202 | GEN_OP (MOD, % (E, E) ) | |
203 | GEN_OP (EQ, == (E, E) ) | |
204 | GEN_OP (NEQ, != (E, E) ) | |
205 | GEN_OP (LAND, && (E, E) ) | |
206 | GEN_OP (LOR, || (E, E) ) | |
207 | GEN_OP (SL_A, <<= (E, E) ) | |
208 | GEN_OP (SR_A, >>= (E, E) ) | |
209 | GEN_OP (SL, << (E, E) ) | |
210 | GEN_OP (SR, >> (E, E) ) | |
211 | GEN_OP (OE, |= (E, E) ) | |
212 | GEN_OP (BIT_O, | (E, E) ) | |
213 | GEN_OP (XOR_A, ^= (E, E) ) | |
214 | GEN_OP (XOR, ^ (E, E) ) | |
215 | GEN_OP (BIT_AND_A, &= (E, E) ) | |
216 | GEN_OP (BIT_AND, & (E, E) ) | |
217 | GEN_OP (LT, < (E, E) ) | |
218 | GEN_OP (LTE, <= (E, E) ) | |
219 | GEN_OP (GTE, >= (E, E) ) | |
220 | GEN_OP (GT, > (E, E) ) | |
221 | GEN_OP (MUL_A, *= (E, E) ) | |
222 | GEN_OP (MUL, * (E, E) ) | |
223 | GEN_OP (DIV_A, /= (E, E) ) | |
224 | GEN_OP (DIV, / (E, E) ) | |
225 | GEN_OP (NEG, ~ (E) ) | |
226 | GEN_OP (NOT, ! (E) ) | |
227 | GEN_OP (PRE_INC, ++ (E) ) | |
228 | GEN_OP (POST_INC, ++ (E, int) ) | |
229 | GEN_OP (PRE_DEC, -- (E) ) | |
230 | GEN_OP (POST_DEC, -- (E, int) ) | |
231 | GEN_OP (COMMA, , (E, E) ) | |
232 | ||
233 | int | |
234 | main () | |
235 | { | |
236 | test_op_call opcall; | |
237 | opcall (); | |
238 | opcall (1); | |
239 | opcall (1l); | |
240 | opcall ((int *) 0); | |
241 | ||
242 | test_unique_op_call opcall2; | |
243 | opcall2 (1); | |
244 | ||
245 | test_op_array op_array; | |
246 | op_array[1]; | |
247 | op_array[1l]; | |
248 | op_array[(int *) 0]; | |
249 | ||
250 | test_unique_op_array unique_op_array; | |
251 | unique_op_array[1]; | |
252 | ||
253 | return 0; | |
254 | } |