]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/init.c
Makefile.in: Rebuilt.
[thirdparty/gcc.git] / gcc / cp / init.c
CommitLineData
8d08fdba 1/* Handle initialization things in C++.
d6a8bdff
JL
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
8d08fdba
MS
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13GNU CC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
20the Free Software Foundation, 59 Temple Place - Suite 330,
21Boston, MA 02111-1307, USA. */
8d08fdba 22
e92cc029 23/* High-level class interface. */
8d08fdba
MS
24
25#include "config.h"
8d052bc7 26#include "system.h"
8d08fdba
MS
27#include "tree.h"
28#include "rtl.h"
29#include "cp-tree.h"
30#include "flags.h"
e8abc66f 31#include "output.h"
eb66be0e 32#include "except.h"
9f617717 33#include "expr.h"
54f92bfb 34#include "toplev.h"
fc6af6e3 35#include "ggc.h"
8d08fdba 36
158991b7
KG
37static void expand_aggr_vbase_init_1 PARAMS ((tree, tree, tree, tree));
38static void construct_virtual_bases PARAMS ((tree, tree, tree, tree, tree));
39static void expand_aggr_init_1 PARAMS ((tree, tree, tree, tree, int));
40static void expand_default_init PARAMS ((tree, tree, tree, tree, int));
41static tree build_vec_delete_1 PARAMS ((tree, tree, tree, tree, int));
42static void perform_member_init PARAMS ((tree, tree, tree, int));
43static void sort_base_init PARAMS ((tree, tree *, tree *));
44static tree build_builtin_delete_call PARAMS ((tree));
45static int member_init_ok_or_else PARAMS ((tree, tree, const char *));
46static void expand_virtual_init PARAMS ((tree, tree));
47static tree sort_member_init PARAMS ((tree));
48static tree initializing_context PARAMS ((tree));
158991b7
KG
49static void expand_cleanup_for_base PARAMS ((tree, tree));
50static tree get_temp_regvar PARAMS ((tree, tree));
51static tree dfs_initialize_vtbl_ptrs PARAMS ((tree, void *));
834c6dff
MM
52static tree build_new_1 PARAMS ((tree));
53static tree get_cookie_size PARAMS ((tree));
8d08fdba 54
8d08fdba
MS
55/* Set up local variable for this file. MUST BE CALLED AFTER
56 INIT_DECL_PROCESSING. */
57
5566b478 58static tree BI_header_type, BI_header_size;
8d08fdba
MS
59
60void init_init_processing ()
61{
62 tree fields[1];
63
9cd64686 64 minus_one_node = build_int_2 (-1, -1);
8d08fdba
MS
65
66 /* Define the structure that holds header information for
67 arrays allocated via operator new. */
33848bb0 68 BI_header_type = make_aggr_type (RECORD_TYPE);
9cd64686 69 fields[0] = build_lang_decl (FIELD_DECL, nelts_identifier, sizetype);
3ca7341a
DN
70
71 /* Use the biggest alignment supported by the target to prevent operator
72 new from returning misaligned pointers. */
73 TYPE_ALIGN (BI_header_type) = BIGGEST_ALIGNMENT;
8d08fdba 74 finish_builtin_type (BI_header_type, "__new_cookie", fields,
3ca7341a 75 0, BI_header_type);
8d08fdba 76 BI_header_size = size_in_bytes (BI_header_type);
fc6af6e3 77
9cd64686
MM
78 ggc_add_tree_root (&BI_header_type, 1);
79 ggc_add_tree_root (&BI_header_size, 1);
8d08fdba
MS
80}
81
d569399b 82/* Called from initialize_vtbl_ptrs via dfs_walk. */
7177d104 83
d569399b
MM
84static tree
85dfs_initialize_vtbl_ptrs (binfo, data)
86 tree binfo;
87 void *data;
88{
89 if (!BINFO_PRIMARY_MARKED_P (binfo)
90 && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
91 {
92 tree base_ptr = TREE_VALUE ((tree) data);
7177d104 93
d569399b
MM
94 if (TREE_VIA_VIRTUAL (binfo))
95 base_ptr = convert_pointer_to_vbase (BINFO_TYPE (binfo),
96 base_ptr);
97 else
98 base_ptr
99 = build_vbase_path (PLUS_EXPR,
100 build_pointer_type (BINFO_TYPE (binfo)),
101 base_ptr,
102 binfo,
103 /*nonnull=*/1);
104
105 expand_virtual_init (binfo, base_ptr);
106 }
7177d104 107
d569399b
MM
108 SET_BINFO_MARKED (binfo);
109
110 return NULL_TREE;
111}
112
113/* Initialize all the vtable pointers for the hierarchy dominated by
114 TYPE. */
e92cc029 115
8d08fdba 116void
d569399b
MM
117initialize_vtbl_ptrs (type, addr)
118 tree type;
119 tree addr;
8d08fdba 120{
d569399b
MM
121 tree list = build_tree_list (type, addr);
122
bbd15aac
MM
123 /* Walk through the hierarchy, initializing the vptr in each base
124 class. We do these in pre-order because under the new ABI we
125 can't find the virtual bases for a class until we've initialized
126 the vtbl for that class. */
127 dfs_walk_real (TYPE_BINFO (type), dfs_initialize_vtbl_ptrs,
128 NULL, dfs_unmarked_real_bases_queue_p, list);
d569399b
MM
129 dfs_walk (TYPE_BINFO (type), dfs_unmark,
130 dfs_marked_real_bases_queue_p, type);
131 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
132 expand_indirect_vtbls_init (TYPE_BINFO (type), addr);
8d08fdba 133}
d569399b 134
8d08fdba
MS
135\f
136/* 348 - 351 */
137/* Subroutine of emit_base_init. */
e92cc029 138
8d08fdba 139static void
9ffa2541 140perform_member_init (member, name, init, explicit)
6b5fbb55 141 tree member, name, init;
8d08fdba
MS
142 int explicit;
143{
144 tree decl;
145 tree type = TREE_TYPE (member);
eb66be0e 146
6bdb8141
JM
147 decl = build_component_ref (current_class_ref, name, NULL_TREE, explicit);
148
2fbfe9b8
MS
149 if (decl == error_mark_node)
150 return;
151
6bdb8141
JM
152 /* Deal with this here, as we will get confused if we try to call the
153 assignment op for an anonymous union. This can happen in a
154 synthesized copy constructor. */
155 if (ANON_AGGR_TYPE_P (type))
156 {
157 init = build (INIT_EXPR, type, decl, TREE_VALUE (init));
f1dedc31 158 finish_expr_stmt (init);
6bdb8141
JM
159 }
160 else if (TYPE_NEEDS_CONSTRUCTING (type)
161 || (init && TYPE_HAS_CONSTRUCTOR (type)))
8d08fdba
MS
162 {
163 /* Since `init' is already a TREE_LIST on the current_member_init_list,
164 only build it into one if we aren't already a list. */
165 if (init != NULL_TREE && TREE_CODE (init) != TREE_LIST)
051e6fd7 166 init = build_tree_list (NULL_TREE, init);
8d08fdba 167
8d08fdba
MS
168 if (explicit
169 && TREE_CODE (type) == ARRAY_TYPE
170 && init != NULL_TREE
171 && TREE_CHAIN (init) == NULL_TREE
172 && TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
173 {
174 /* Initialization of one array from another. */
f1dedc31
MM
175 finish_expr_stmt
176 (build_vec_init (TREE_OPERAND (decl, 1), decl,
177 array_type_nelts (type), TREE_VALUE (init), 1));
8d08fdba
MS
178 }
179 else
f1dedc31 180 finish_expr_stmt (build_aggr_init (decl, init, 0));
8d08fdba
MS
181 }
182 else
183 {
184 if (init == NULL_TREE)
185 {
186 if (explicit)
187 {
02020185
JM
188 /* default-initialization. */
189 if (AGGREGATE_TYPE_P (type))
316d4b54 190 {
4f0aa416
MM
191 /* This is a default initialization of an aggregate,
192 but not one of non-POD class type. We cleverly
193 notice that the initialization rules in such a
194 case are the same as for initialization with an
195 empty brace-initialization list. We don't want
196 to call build_modify_expr as that will go looking
197 for constructors and such. */
198 tree e = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
199 TREE_SIDE_EFFECTS (e) = 1;
f1dedc31 200 finish_expr_stmt (build (INIT_EXPR, type, decl, e));
316d4b54 201 }
4f0aa416
MM
202 else if (TREE_CODE (type) == REFERENCE_TYPE)
203 cp_error ("default-initialization of `%#D', which has reference type",
204 member);
02020185
JM
205 else
206 init = integer_zero_node;
8d08fdba
MS
207 }
208 /* member traversal: note it leaves init NULL */
209 else if (TREE_CODE (TREE_TYPE (member)) == REFERENCE_TYPE)
8251199e 210 cp_pedwarn ("uninitialized reference member `%D'", member);
8d08fdba
MS
211 }
212 else if (TREE_CODE (init) == TREE_LIST)
213 {
214 /* There was an explicit member initialization. Do some
215 work in that case. */
216 if (TREE_CHAIN (init))
217 {
8251199e 218 warning ("initializer list treated as compound expression");
8d08fdba
MS
219 init = build_compound_expr (init);
220 }
221 else
222 init = TREE_VALUE (init);
223 }
224
4f0aa416 225 if (init)
f1dedc31 226 finish_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
8d08fdba 227 }
eb66be0e 228
834c6dff 229 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
b7484fbe 230 {
de22184b
MS
231 tree expr;
232
02020185
JM
233 expr = build_component_ref (current_class_ref, name, NULL_TREE,
234 explicit);
b7484fbe
MS
235 expr = build_delete (type, expr, integer_zero_node,
236 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
237
238 if (expr != error_mark_node)
f1dedc31 239 finish_subobject (expr);
b7484fbe 240 }
8d08fdba
MS
241}
242
b7484fbe
MS
243extern int warn_reorder;
244
8d08fdba 245/* Subroutine of emit_member_init. */
e92cc029 246
8d08fdba
MS
247static tree
248sort_member_init (t)
249 tree t;
250{
5566b478 251 tree x, member, name, field;
8d08fdba 252 tree init_list = NULL_TREE;
00595019 253 int last_pos = 0;
a703fb38 254 tree last_field = NULL_TREE;
8d08fdba
MS
255
256 for (member = TYPE_FIELDS (t); member ; member = TREE_CHAIN (member))
257 {
00595019 258 int pos;
b7484fbe
MS
259
260 /* member could be, for example, a CONST_DECL for an enumerated
261 tag; we don't want to try to initialize that, since it already
262 has a value. */
263 if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member))
264 continue;
265
00595019 266 for (x = current_member_init_list, pos = 0; x; x = TREE_CHAIN (x), ++pos)
8d08fdba
MS
267 {
268 /* If we cleared this out, then pay no attention to it. */
269 if (TREE_PURPOSE (x) == NULL_TREE)
270 continue;
271 name = TREE_PURPOSE (x);
272
6bdb8141
JM
273 if (TREE_CODE (name) == IDENTIFIER_NODE)
274 field = IDENTIFIER_CLASS_VALUE (name);
275 else
276 {
277 my_friendly_assert (TREE_CODE (name) == FIELD_DECL, 348);
278 field = name;
279 }
8d08fdba
MS
280
281 /* If one member shadows another, get the outermost one. */
282 if (TREE_CODE (field) == TREE_LIST)
283 field = TREE_VALUE (field);
284
285 if (field == member)
286 {
b7484fbe 287 if (warn_reorder)
00595019 288 {
b7484fbe 289 if (pos < last_pos)
00595019 290 {
8251199e
JM
291 cp_warning_at ("member initializers for `%#D'", last_field);
292 cp_warning_at (" and `%#D'", field);
293 warning (" will be re-ordered to match declaration order");
00595019
MS
294 }
295 last_pos = pos;
296 last_field = field;
297 }
8d08fdba 298
8d08fdba
MS
299 /* Make sure we won't try to work on this init again. */
300 TREE_PURPOSE (x) = NULL_TREE;
b7484fbe
MS
301 x = build_tree_list (name, TREE_VALUE (x));
302 goto got_it;
8d08fdba
MS
303 }
304 }
305
306 /* If we didn't find MEMBER in the list, create a dummy entry
307 so the two lists (INIT_LIST and the list of members) will be
308 symmetrical. */
b7484fbe
MS
309 x = build_tree_list (NULL_TREE, NULL_TREE);
310 got_it:
311 init_list = chainon (init_list, x);
8d08fdba
MS
312 }
313
b7484fbe 314 /* Initializers for base members go at the end. */
8d08fdba
MS
315 for (x = current_member_init_list ; x ; x = TREE_CHAIN (x))
316 {
b7484fbe
MS
317 name = TREE_PURPOSE (x);
318 if (name)
8d08fdba 319 {
b7484fbe 320 if (purpose_member (name, init_list))
8d08fdba 321 {
8251199e 322 cp_error ("multiple initializations given for member `%D'",
b7484fbe
MS
323 IDENTIFIER_CLASS_VALUE (name));
324 continue;
8d08fdba 325 }
b7484fbe
MS
326
327 init_list = chainon (init_list,
328 build_tree_list (name, TREE_VALUE (x)));
329 TREE_PURPOSE (x) = NULL_TREE;
330 }
331 }
8d08fdba 332
b7484fbe
MS
333 return init_list;
334}
8d08fdba 335
b7484fbe
MS
336static void
337sort_base_init (t, rbase_ptr, vbase_ptr)
338 tree t, *rbase_ptr, *vbase_ptr;
339{
340 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
341 int n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
342
343 int i;
344 tree x;
345 tree last;
346
347 /* For warn_reorder. */
348 int last_pos = 0;
349 tree last_base = NULL_TREE;
350
351 tree rbases = NULL_TREE;
352 tree vbases = NULL_TREE;
8d08fdba 353
b7484fbe
MS
354 /* First walk through and splice out vbase and invalid initializers.
355 Also replace names with binfos. */
356
357 last = tree_cons (NULL_TREE, NULL_TREE, current_base_init_list);
358 for (x = TREE_CHAIN (last); x; x = TREE_CHAIN (x))
359 {
be99da77 360 tree basetype = TREE_PURPOSE (x);
a703fb38 361 tree binfo = NULL_TREE;
b7484fbe 362
be99da77 363 if (basetype == NULL_TREE)
b7484fbe
MS
364 {
365 /* Initializer for single base class. Must not
366 use multiple inheritance or this is ambiguous. */
367 switch (n_baseclasses)
8d08fdba 368 {
b7484fbe 369 case 0:
8251199e 370 cp_error ("`%T' does not have a base class to initialize",
b7484fbe
MS
371 current_class_type);
372 return;
373 case 1:
374 break;
375 default:
8251199e 376 cp_error ("unnamed initializer ambiguous for `%T' which uses multiple inheritance",
b7484fbe
MS
377 current_class_type);
378 return;
8d08fdba 379 }
b7484fbe
MS
380 binfo = TREE_VEC_ELT (binfos, 0);
381 }
be99da77 382 else if (is_aggr_type (basetype, 1))
b7484fbe 383 {
be99da77 384 binfo = binfo_or_else (basetype, t);
b7484fbe
MS
385 if (binfo == NULL_TREE)
386 continue;
8d08fdba 387
b7484fbe
MS
388 /* Virtual base classes are special cases. Their initializers
389 are recorded with this constructor, and they are used when
390 this constructor is the top-level constructor called. */
391 if (TREE_VIA_VIRTUAL (binfo))
392 {
23381155 393 tree v = BINFO_FOR_VBASE (BINFO_TYPE (binfo), t);
b7484fbe
MS
394 vbases = tree_cons (v, TREE_VALUE (x), vbases);
395 continue;
396 }
397 else
398 {
399 /* Otherwise, if it is not an immediate base class, complain. */
400 for (i = n_baseclasses-1; i >= 0; i--)
401 if (BINFO_TYPE (binfo) == BINFO_TYPE (TREE_VEC_ELT (binfos, i)))
402 break;
403 if (i < 0)
404 {
8251199e 405 cp_error ("`%T' is not an immediate base class of `%T'",
be99da77 406 basetype, current_class_type);
b7484fbe
MS
407 continue;
408 }
409 }
8d08fdba 410 }
b7484fbe
MS
411 else
412 my_friendly_abort (365);
413
414 TREE_PURPOSE (x) = binfo;
415 TREE_CHAIN (last) = x;
416 last = x;
8d08fdba 417 }
b7484fbe 418 TREE_CHAIN (last) = NULL_TREE;
8d08fdba 419
b7484fbe
MS
420 /* Now walk through our regular bases and make sure they're initialized. */
421
422 for (i = 0; i < n_baseclasses; ++i)
8d08fdba 423 {
b7484fbe
MS
424 tree base_binfo = TREE_VEC_ELT (binfos, i);
425 int pos;
426
427 if (TREE_VIA_VIRTUAL (base_binfo))
428 continue;
429
430 for (x = current_base_init_list, pos = 0; x; x = TREE_CHAIN (x), ++pos)
431 {
432 tree binfo = TREE_PURPOSE (x);
433
434 if (binfo == NULL_TREE)
435 continue;
436
437 if (binfo == base_binfo)
438 {
439 if (warn_reorder)
440 {
441 if (pos < last_pos)
442 {
8251199e
JM
443 cp_warning_at ("base initializers for `%#T'", last_base);
444 cp_warning_at (" and `%#T'", BINFO_TYPE (binfo));
445 warning (" will be re-ordered to match inheritance order");
b7484fbe
MS
446 }
447 last_pos = pos;
448 last_base = BINFO_TYPE (binfo);
449 }
450
451 /* Make sure we won't try to work on this init again. */
452 TREE_PURPOSE (x) = NULL_TREE;
453 x = build_tree_list (binfo, TREE_VALUE (x));
454 goto got_it;
455 }
456 }
457
458 /* If we didn't find BASE_BINFO in the list, create a dummy entry
459 so the two lists (RBASES and the list of bases) will be
460 symmetrical. */
461 x = build_tree_list (NULL_TREE, NULL_TREE);
462 got_it:
463 rbases = chainon (rbases, x);
8d08fdba
MS
464 }
465
b7484fbe
MS
466 *rbase_ptr = rbases;
467 *vbase_ptr = vbases;
468}
469
8d08fdba
MS
470/* Perform whatever initializations have yet to be done on the base
471 class of the class variable. These actions are in the global
472 variable CURRENT_BASE_INIT_LIST. Such an action could be
473 NULL_TREE, meaning that the user has explicitly called the base
474 class constructor with no arguments.
475
476 If there is a need for a call to a constructor, we must surround
477 that call with a pushlevel/poplevel pair, since we are technically
478 at the PARM level of scope.
479
480 Argument IMMEDIATELY, if zero, forces a new sequence to be
481 generated to contain these new insns, so it can be emitted later.
a9aedbc2 482 This sequence is saved in the global variable BASE_INIT_EXPR.
8d08fdba
MS
483 Otherwise, the insns are emitted into the current sequence.
484
485 Note that emit_base_init does *not* initialize virtual base
486 classes. That is done specially, elsewhere. */
a9aedbc2 487
9bfadf57 488tree
f1dedc31 489emit_base_init (t)
8d08fdba 490 tree t;
8d08fdba 491{
5566b478 492 tree member;
b7484fbe
MS
493 tree mem_init_list;
494 tree rbase_init_list, vbase_init_list;
8d08fdba
MS
495 tree t_binfo = TYPE_BINFO (t);
496 tree binfos = BINFO_BASETYPES (t_binfo);
497 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
f1dedc31
MM
498 tree stmt_expr;
499 tree compound_stmt;
8d08fdba 500
b7484fbe
MS
501 mem_init_list = sort_member_init (t);
502 current_member_init_list = NULL_TREE;
8d08fdba 503
b7484fbe
MS
504 sort_base_init (t, &rbase_init_list, &vbase_init_list);
505 current_base_init_list = NULL_TREE;
8d08fdba 506
f1dedc31
MM
507 begin_init_stmts (&stmt_expr, &compound_stmt);
508
69f00f01
MM
509 /* First, initialize the virtual base classes, if we are
510 constructing the most-derived object. */
b7484fbe
MS
511 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
512 {
513 tree first_arg = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl));
69f00f01
MM
514 construct_virtual_bases (t, current_class_ref, current_class_ptr,
515 vbase_init_list, first_arg);
8d08fdba 516 }
8d08fdba 517
b7484fbe 518 /* Now, perform initialization of non-virtual base classes. */
8d08fdba
MS
519 for (i = 0; i < n_baseclasses; i++)
520 {
8d08fdba 521 tree base_binfo = TREE_VEC_ELT (binfos, i);
b7484fbe
MS
522 tree init = void_list_node;
523
524 if (TREE_VIA_VIRTUAL (base_binfo))
525 continue;
8d08fdba 526
dfbcd65a
JM
527 my_friendly_assert (BINFO_INHERITANCE_CHAIN (base_binfo) == t_binfo,
528 999);
8ccc31eb 529
b7484fbe
MS
530 if (TREE_PURPOSE (rbase_init_list))
531 init = TREE_VALUE (rbase_init_list);
532 else if (TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (base_binfo)))
824b9a4c
MS
533 {
534 init = NULL_TREE;
535 if (extra_warnings && copy_args_p (current_function_decl))
8251199e 536 cp_warning ("base class `%#T' should be explicitly initialized in the copy constructor",
824b9a4c
MS
537 BINFO_TYPE (base_binfo));
538 }
8d08fdba 539
b7484fbe
MS
540 if (init != void_list_node)
541 {
4ac14744 542 member = convert_pointer_to_real (base_binfo, current_class_ptr);
fc378698 543 expand_aggr_init_1 (base_binfo, NULL_TREE,
b7484fbe 544 build_indirect_ref (member, NULL_PTR), init,
b370501f 545 LOOKUP_NORMAL);
8d08fdba 546 }
8d08fdba 547
0b8a1e58 548 expand_cleanup_for_base (base_binfo, NULL_TREE);
b7484fbe 549 rbase_init_list = TREE_CHAIN (rbase_init_list);
8d08fdba
MS
550 }
551
d569399b
MM
552 /* Initialize the vtable pointers for the class. */
553 initialize_vtbl_ptrs (t, current_class_ptr);
8d08fdba 554
8d08fdba
MS
555 for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
556 {
557 tree init, name;
b7484fbe
MS
558 int from_init_list;
559
560 /* member could be, for example, a CONST_DECL for an enumerated
561 tag; we don't want to try to initialize that, since it already
562 has a value. */
563 if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member))
564 continue;
8d08fdba
MS
565
566 /* See if we had a user-specified member initialization. */
b7484fbe 567 if (TREE_PURPOSE (mem_init_list))
8d08fdba 568 {
b7484fbe
MS
569 name = TREE_PURPOSE (mem_init_list);
570 init = TREE_VALUE (mem_init_list);
571 from_init_list = 1;
8d08fdba 572
6bdb8141
JM
573 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE
574 || TREE_CODE (name) == FIELD_DECL, 349);
8d08fdba 575 }
b7484fbe 576 else
8d08fdba 577 {
8d08fdba
MS
578 name = DECL_NAME (member);
579 init = DECL_INITIAL (member);
b7484fbe
MS
580
581 from_init_list = 0;
824b9a4c
MS
582
583 /* Effective C++ rule 12. */
eb448459
MS
584 if (warn_ecpp && init == NULL_TREE
585 && !DECL_ARTIFICIAL (member)
824b9a4c 586 && TREE_CODE (TREE_TYPE (member)) != ARRAY_TYPE)
8251199e 587 cp_warning ("`%D' should be initialized in the member initialization list", member);
8d08fdba
MS
588 }
589
9ffa2541 590 perform_member_init (member, name, init, from_init_list);
b7484fbe 591 mem_init_list = TREE_CHAIN (mem_init_list);
8d08fdba
MS
592 }
593
b7484fbe
MS
594 /* Now initialize any members from our bases. */
595 while (mem_init_list)
596 {
597 tree name, init, field;
598
599 if (TREE_PURPOSE (mem_init_list))
600 {
601 name = TREE_PURPOSE (mem_init_list);
602 init = TREE_VALUE (mem_init_list);
6bdb8141
JM
603
604 if (TREE_CODE (name) == IDENTIFIER_NODE)
605 field = IDENTIFIER_CLASS_VALUE (name);
606 else
607 field = name;
b7484fbe
MS
608
609 /* If one member shadows another, get the outermost one. */
610 if (TREE_CODE (field) == TREE_LIST)
611 {
612 field = TREE_VALUE (field);
613 if (decl_type_context (field) != current_class_type)
8251199e 614 cp_error ("field `%D' not in immediate context", field);
b7484fbe
MS
615 }
616
9ffa2541 617 perform_member_init (field, name, init, 1);
b7484fbe
MS
618 }
619 mem_init_list = TREE_CHAIN (mem_init_list);
620 }
8d08fdba 621
8d08fdba
MS
622 /* All the implicit try blocks we built up will be zapped
623 when we come to a real binding contour boundary. */
9bfadf57 624 return finish_init_stmts (stmt_expr, compound_stmt);
8d08fdba
MS
625}
626
627/* Check that all fields are properly initialized after
6f1b4c42
JM
628 an assignment to `this'. Called only when such an assignment
629 is actually noted. */
e92cc029 630
8d08fdba
MS
631void
632check_base_init (t)
633 tree t;
634{
635 tree member;
636 for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
637 if (DECL_NAME (member) && TREE_USED (member))
8251199e 638 cp_error ("field `%D' used before initialized (after assignment to `this')",
8d08fdba
MS
639 member);
640}
641
642/* This code sets up the virtual function tables appropriate for
643 the pointer DECL. It is a one-ply initialization.
644
645 BINFO is the exact type that DECL is supposed to be. In
646 multiple inheritance, this might mean "C's A" if C : A, B. */
e92cc029 647
8926095f 648static void
7177d104
MS
649expand_virtual_init (binfo, decl)
650 tree binfo, decl;
8d08fdba 651{
7177d104 652 tree type = BINFO_TYPE (binfo);
8d08fdba
MS
653 tree vtbl, vtbl_ptr;
654 tree vtype, vtype_binfo;
c35cce41 655 tree b;
8d08fdba 656
70ae3201 657 /* Compute the location of the vtable. */
d3a3fb6a 658 vtype = DECL_CONTEXT (TYPE_VFIELD (type));
8d08fdba 659 vtype_binfo = get_binfo (vtype, TREE_TYPE (TREE_TYPE (decl)), 0);
c35cce41 660 b = binfo_value (DECL_FIELD_CONTEXT (TYPE_VFIELD (type)), binfo);
8d7a5379 661
c35cce41
MM
662 /* Figure out what vtable BINFO's vtable is based on, and mark it as
663 used. */
664 vtbl = get_vtbl_decl_for_binfo (b);
665 assemble_external (vtbl);
666 TREE_USED (vtbl) = 1;
667
668 /* Now compute the address to use when initializing the vptr. */
669 vtbl = BINFO_VTABLE (b);
8d7a5379 670 if (TREE_CODE (vtbl) == VAR_DECL)
c35cce41 671 vtbl = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (vtbl)), vtbl);
70ae3201
MM
672
673 /* Compute the location of the vtpr. */
8d08fdba
MS
674 decl = convert_pointer_to_real (vtype_binfo, decl);
675 vtbl_ptr = build_vfield_ref (build_indirect_ref (decl, NULL_PTR), vtype);
676 if (vtbl_ptr == error_mark_node)
8926095f 677 return;
8d08fdba 678
70ae3201 679 /* Assign the vtable to the vptr. */
6060a796 680 vtbl = convert_force (TREE_TYPE (vtbl_ptr), vtbl, 0);
f1dedc31 681 finish_expr_stmt (build_modify_expr (vtbl_ptr, NOP_EXPR, vtbl));
8d08fdba
MS
682}
683
f33e32a8
MM
684/* If an exception is thrown in a constructor, those base classes already
685 constructed must be destroyed. This function creates the cleanup
0b8a1e58
MM
686 for BINFO, which has just been constructed. If FLAG is non-NULL,
687 it is a DECL which is non-zero when this base needs to be
688 destroyed. */
f33e32a8
MM
689
690static void
0b8a1e58 691expand_cleanup_for_base (binfo, flag)
f33e32a8 692 tree binfo;
0b8a1e58 693 tree flag;
f33e32a8
MM
694{
695 tree expr;
696
834c6dff 697 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (BINFO_TYPE (binfo)))
f33e32a8
MM
698 return;
699
0b8a1e58
MM
700 /* Call the destructor. */
701 expr = (build_scoped_method_call
702 (current_class_ref, binfo, dtor_identifier,
051e6fd7 703 build_tree_list (NULL_TREE, integer_zero_node)));
0b8a1e58
MM
704 if (flag)
705 expr = fold (build (COND_EXPR, void_type_node,
706 truthvalue_conversion (flag),
707 expr, integer_zero_node));
708
f1dedc31 709 finish_subobject (expr);
f33e32a8
MM
710}
711
8d08fdba
MS
712/* Subroutine of `expand_aggr_vbase_init'.
713 BINFO is the binfo of the type that is being initialized.
714 INIT_LIST is the list of initializers for the virtual baseclass. */
e92cc029 715
8d08fdba
MS
716static void
717expand_aggr_vbase_init_1 (binfo, exp, addr, init_list)
718 tree binfo, exp, addr, init_list;
719{
b7484fbe 720 tree init = purpose_member (binfo, init_list);
8d08fdba 721 tree ref = build_indirect_ref (addr, NULL_PTR);
72b7eeff 722
8d08fdba 723 if (init)
b7484fbe 724 init = TREE_VALUE (init);
8d08fdba 725 /* Call constructors, but don't set up vtables. */
b370501f 726 expand_aggr_init_1 (binfo, exp, ref, init, LOOKUP_COMPLAIN);
8d08fdba
MS
727}
728
69f00f01
MM
729/* Construct the virtual base-classes of THIS_REF (whose address is
730 THIS_PTR). The object has the indicated TYPE. The construction
731 actually takes place only if FLAG is non-zero. INIT_LIST is list
bbd15aac 732 of initializations for constructors to perform. */
e92cc029 733
8d08fdba 734static void
69f00f01
MM
735construct_virtual_bases (type, this_ref, this_ptr, init_list, flag)
736 tree type;
737 tree this_ref;
738 tree this_ptr;
8d08fdba 739 tree init_list;
0b8a1e58 740 tree flag;
8d08fdba 741{
69f00f01 742 tree vbases;
69f00f01
MM
743
744 /* If there are no virtual baseclasses, we shouldn't even be here. */
745 my_friendly_assert (TYPE_USES_VIRTUAL_BASECLASSES (type), 19990621);
746
747 /* First set the pointers in our object that tell us where to find
748 our virtual baseclasses. */
bbd15aac
MM
749 if (!vbase_offsets_in_vtable_p ())
750 {
751 tree if_stmt;
752 tree result;
753
754 if_stmt = begin_if_stmt ();
755 finish_if_stmt_cond (flag, if_stmt);
756 result = init_vbase_pointers (type, this_ptr);
757 if (result)
758 finish_expr_stmt (build_compound_expr (result));
759 finish_then_clause (if_stmt);
760 finish_if_stmt ();
761 }
69f00f01
MM
762
763 /* Now, run through the baseclasses, initializing each. */
764 for (vbases = CLASSTYPE_VBASECLASSES (type); vbases;
765 vbases = TREE_CHAIN (vbases))
8d08fdba 766 {
f1dedc31
MM
767 tree inner_if_stmt;
768 tree compound_stmt;
a6786148 769 tree exp;
f1dedc31 770
69f00f01
MM
771 /* If there are virtual base classes with destructors, we need to
772 emit cleanups to destroy them if an exception is thrown during
773 the construction process. These exception regions (i.e., the
774 period during which the cleanups must occur) begin from the time
775 the construction is complete to the end of the function. If we
776 create a conditional block in which to initialize the
777 base-classes, then the cleanup region for the virtual base begins
778 inside a block, and ends outside of that block. This situation
779 confuses the sjlj exception-handling code. Therefore, we do not
780 create a single conditional block, but one for each
781 initialization. (That way the cleanup regions always begin
782 in the outer block.) We trust the back-end to figure out
783 that the FLAG will not change across initializations, and
784 avoid doing multiple tests. */
f1dedc31
MM
785 inner_if_stmt = begin_if_stmt ();
786 finish_if_stmt_cond (flag, inner_if_stmt);
787 compound_stmt = begin_compound_stmt (/*has_no_scope=*/1);
a6786148
MM
788
789 /* Compute the location of the virtual base. If we're
790 constructing virtual bases, then we must be the most derived
791 class. Therefore, we don't have to look up the virtual base;
792 we already know where it is. */
793 exp = build (PLUS_EXPR,
794 TREE_TYPE (this_ptr),
795 this_ptr,
aa1e6de6
JM
796 fold (build1 (NOP_EXPR, TREE_TYPE (this_ptr),
797 BINFO_OFFSET (vbases))));
a6786148
MM
798 exp = build1 (NOP_EXPR,
799 build_pointer_type (BINFO_TYPE (vbases)),
800 exp);
801
802 expand_aggr_vbase_init_1 (vbases, this_ref, exp, init_list);
f1dedc31 803 finish_compound_stmt (/*has_no_scope=*/1, compound_stmt);
9bfadf57 804 finish_then_clause (inner_if_stmt);
f1dedc31 805 finish_if_stmt ();
69f00f01
MM
806
807 expand_cleanup_for_base (vbases, flag);
8d08fdba
MS
808 }
809}
810
2ee887f2 811/* Find the context in which this FIELD can be initialized. */
e92cc029 812
2ee887f2
MS
813static tree
814initializing_context (field)
815 tree field;
816{
817 tree t = DECL_CONTEXT (field);
818
819 /* Anonymous union members can be initialized in the first enclosing
820 non-anonymous union context. */
6bdb8141 821 while (t && ANON_AGGR_TYPE_P (t))
2ee887f2
MS
822 t = TYPE_CONTEXT (t);
823 return t;
824}
825
8d08fdba
MS
826/* Function to give error message if member initialization specification
827 is erroneous. FIELD is the member we decided to initialize.
828 TYPE is the type for which the initialization is being performed.
72b7eeff 829 FIELD must be a member of TYPE.
8d08fdba
MS
830
831 MEMBER_NAME is the name of the member. */
832
833static int
834member_init_ok_or_else (field, type, member_name)
835 tree field;
836 tree type;
d8e178a0 837 const char *member_name;
8d08fdba
MS
838{
839 if (field == error_mark_node)
840 return 0;
2ee887f2 841 if (field == NULL_TREE || initializing_context (field) != type)
8d08fdba 842 {
8251199e 843 cp_error ("class `%T' does not have any field named `%s'", type,
b7484fbe 844 member_name);
8d08fdba
MS
845 return 0;
846 }
b7484fbe
MS
847 if (TREE_STATIC (field))
848 {
8251199e 849 cp_error ("field `%#D' is static; only point of initialization is its declaration",
b7484fbe
MS
850 field);
851 return 0;
852 }
853
8d08fdba
MS
854 return 1;
855}
856
857/* If NAME is a viable field name for the aggregate DECL,
858 and PARMS is a viable parameter list, then expand an _EXPR
859 which describes this initialization.
860
861 Note that we do not need to chase through the class's base classes
862 to look for NAME, because if it's in that list, it will be handled
863 by the constructor for that base class.
864
865 We do not yet have a fixed-point finder to instantiate types
866 being fed to overloaded constructors. If there is a unique
867 constructor, then argument types can be got from that one.
868
869 If INIT is non-NULL, then it the initialization should
870 be placed in `current_base_init_list', where it will be processed
871 by `emit_base_init'. */
e92cc029 872
8d08fdba
MS
873void
874expand_member_init (exp, name, init)
875 tree exp, name, init;
876{
8d08fdba 877 tree basetype = NULL_TREE, field;
63d088b7 878 tree type;
8d08fdba
MS
879
880 if (exp == NULL_TREE)
881 return; /* complain about this later */
882
883 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
884
6b5fbb55 885 if (name && TREE_CODE (name) == TYPE_DECL)
be99da77 886 {
94c82a77 887 basetype = TYPE_MAIN_VARIANT (TREE_TYPE (name));
45537677 888 name = DECL_NAME (name);
be99da77
MS
889 }
890
8d08fdba
MS
891 if (name == NULL_TREE && IS_AGGR_TYPE (type))
892 switch (CLASSTYPE_N_BASECLASSES (type))
893 {
894 case 0:
8251199e 895 error ("base class initializer specified, but no base class to initialize");
8d08fdba
MS
896 return;
897 case 1:
898 basetype = TYPE_BINFO_BASETYPE (type, 0);
899 break;
900 default:
8251199e
JM
901 error ("initializer for unnamed base class ambiguous");
902 cp_error ("(type `%T' uses multiple inheritance)", type);
8d08fdba
MS
903 return;
904 }
905
41efda8f 906 my_friendly_assert (init != NULL_TREE, 0);
8d08fdba 907
41efda8f
MM
908 /* The grammar should not allow fields which have names that are
909 TYPENAMEs. Therefore, if the field has a non-NULL TREE_TYPE, we
910 may assume that this is an attempt to initialize a base class
911 member of the current type. Otherwise, it is an attempt to
912 initialize a member field. */
8d08fdba 913
41efda8f
MM
914 if (init == void_type_node)
915 init = NULL_TREE;
8d08fdba 916
41efda8f
MM
917 if (name == NULL_TREE || basetype)
918 {
919 tree base_init;
8d08fdba 920
41efda8f
MM
921 if (name == NULL_TREE)
922 {
923#if 0
924 if (basetype)
925 name = TYPE_IDENTIFIER (basetype);
926 else
8d08fdba 927 {
8251199e 928 error ("no base class to initialize");
8d08fdba
MS
929 return;
930 }
41efda8f 931#endif
8d08fdba 932 }
41efda8f
MM
933 else if (basetype != type
934 && ! current_template_parms
935 && ! vec_binfo_member (basetype,
936 TYPE_BINFO_BASETYPES (type))
23381155 937 && ! BINFO_FOR_VBASE (basetype, type))
8d08fdba 938 {
41efda8f
MM
939 if (IDENTIFIER_CLASS_VALUE (name))
940 goto try_member;
941 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
8251199e 942 cp_error ("type `%T' is not an immediate or virtual basetype for `%T'",
41efda8f
MM
943 basetype, type);
944 else
8251199e 945 cp_error ("type `%T' is not an immediate basetype for `%T'",
41efda8f
MM
946 basetype, type);
947 return;
8d08fdba 948 }
8d08fdba 949
41efda8f 950 if (purpose_member (basetype, current_base_init_list))
8d08fdba 951 {
8251199e 952 cp_error ("base class `%T' already initialized", basetype);
41efda8f 953 return;
8d08fdba 954 }
8d08fdba 955
41efda8f
MM
956 if (warn_reorder && current_member_init_list)
957 {
8251199e
JM
958 cp_warning ("base initializer for `%T'", basetype);
959 warning (" will be re-ordered to precede member initializations");
41efda8f 960 }
8d08fdba 961
41efda8f
MM
962 base_init = build_tree_list (basetype, init);
963 current_base_init_list = chainon (current_base_init_list, base_init);
964 }
965 else
966 {
967 tree member_init;
8d08fdba 968
41efda8f
MM
969 try_member:
970 field = lookup_field (type, name, 1, 0);
8d08fdba 971
41efda8f 972 if (! member_init_ok_or_else (field, type, IDENTIFIER_POINTER (name)))
8d08fdba
MS
973 return;
974
41efda8f 975 if (purpose_member (name, current_member_init_list))
8d08fdba 976 {
8251199e 977 cp_error ("field `%D' already initialized", field);
41efda8f 978 return;
8d08fdba 979 }
8d08fdba 980
41efda8f
MM
981 member_init = build_tree_list (name, init);
982 current_member_init_list = chainon (current_member_init_list, member_init);
983 }
8d08fdba
MS
984}
985
f1dedc31
MM
986/* We are about to generate some complex initialization code.
987 Conceptually, it is all a single expression. However, we may want
988 to include conditionals, loops, and other such statement-level
989 constructs. Therefore, we build the initialization code inside a
990 statement-expression. This function starts such an expression.
991 STMT_EXPR_P and COMPOUND_STMT_P are filled in by this function;
992 pass them back to finish_init_stmts when the expression is
993 complete. */
994
8d1e67c6 995void
f1dedc31
MM
996begin_init_stmts (stmt_expr_p, compound_stmt_p)
997 tree *stmt_expr_p;
998 tree *compound_stmt_p;
999{
f1dedc31
MM
1000 *stmt_expr_p = begin_stmt_expr ();
1001 *compound_stmt_p = begin_compound_stmt (/*has_no_scope=*/1);
1002}
1003
1004/* Finish out the statement-expression begun by the previous call to
1005 begin_init_stmts. Returns the statement-expression itself. */
1006
8d1e67c6 1007tree
f1dedc31
MM
1008finish_init_stmts (stmt_expr, compound_stmt)
1009 tree stmt_expr;
1010 tree compound_stmt;
1011{
447cfcb9
MM
1012 finish_compound_stmt (/*has_no_scope=*/1, compound_stmt);
1013 stmt_expr = finish_stmt_expr (stmt_expr);
62409b39
MM
1014
1015 /* To avoid spurious warnings about unused values, we set
1016 TREE_USED. */
1017 if (stmt_expr)
1018 TREE_USED (stmt_expr) = 1;
1019
1020 return stmt_expr;
f1dedc31
MM
1021}
1022
8d08fdba
MS
1023/* This is like `expand_member_init', only it stores one aggregate
1024 value into another.
1025
1026 INIT comes in two flavors: it is either a value which
1027 is to be stored in EXP, or it is a parameter list
1028 to go to a constructor, which will operate on EXP.
f30432d7
MS
1029 If INIT is not a parameter list for a constructor, then set
1030 LOOKUP_ONLYCONVERTING.
6060a796
MS
1031 If FLAGS is LOOKUP_ONLYCONVERTING then it is the = init form of
1032 the initializer, if FLAGS is 0, then it is the (init) form.
8d08fdba 1033 If `init' is a CONSTRUCTOR, then we emit a warning message,
59be0cdd 1034 explaining that such initializations are invalid.
8d08fdba 1035
8d08fdba
MS
1036 If INIT resolves to a CALL_EXPR which happens to return
1037 something of the type we are looking for, then we know
1038 that we can safely use that call to perform the
1039 initialization.
1040
1041 The virtual function table pointer cannot be set up here, because
1042 we do not really know its type.
1043
1044 Virtual baseclass pointers are also set up here.
1045
1046 This never calls operator=().
1047
1048 When initializing, nothing is CONST.
1049
1050 A default copy constructor may have to be used to perform the
1051 initialization.
1052
1053 A constructor or a conversion operator may have to be used to
e92cc029 1054 perform the initialization, but not both, as it would be ambiguous. */
8d08fdba 1055
f1dedc31
MM
1056tree
1057build_aggr_init (exp, init, flags)
8d08fdba 1058 tree exp, init;
6060a796 1059 int flags;
8d08fdba 1060{
f1dedc31
MM
1061 tree stmt_expr;
1062 tree compound_stmt;
1063 int destroy_temps;
8d08fdba
MS
1064 tree type = TREE_TYPE (exp);
1065 int was_const = TREE_READONLY (exp);
f30432d7 1066 int was_volatile = TREE_THIS_VOLATILE (exp);
8d08fdba
MS
1067
1068 if (init == error_mark_node)
f1dedc31 1069 return error_mark_node;
8d08fdba
MS
1070
1071 TREE_READONLY (exp) = 0;
f30432d7
MS
1072 TREE_THIS_VOLATILE (exp) = 0;
1073
1074 if (init && TREE_CODE (init) != TREE_LIST)
1075 flags |= LOOKUP_ONLYCONVERTING;
8d08fdba
MS
1076
1077 if (TREE_CODE (type) == ARRAY_TYPE)
1078 {
1079 /* Must arrange to initialize each element of EXP
1080 from elements of INIT. */
8d08fdba 1081 tree itype = init ? TREE_TYPE (init) : NULL_TREE;
91063b51 1082 if (CP_TYPE_QUALS (type) != TYPE_UNQUALIFIED)
f376e137
MS
1083 {
1084 TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
1085 if (init)
1086 TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype);
1087 }
8d08fdba
MS
1088 if (init && TREE_TYPE (init) == NULL_TREE)
1089 {
1090 /* Handle bad initializers like:
1091 class COMPLEX {
1092 public:
1093 double re, im;
1094 COMPLEX(double r = 0.0, double i = 0.0) {re = r; im = i;};
1095 ~COMPLEX() {};
1096 };
1097
1098 int main(int argc, char **argv) {
1099 COMPLEX zees(1.0, 0.0)[10];
1100 }
1101 */
8251199e 1102 error ("bad array initializer");
f1dedc31 1103 return error_mark_node;
8d08fdba 1104 }
f1dedc31
MM
1105 stmt_expr = build_vec_init (exp, exp, array_type_nelts (type), init,
1106 init && same_type_p (TREE_TYPE (init),
1107 TREE_TYPE (exp)));
8d08fdba 1108 TREE_READONLY (exp) = was_const;
f30432d7 1109 TREE_THIS_VOLATILE (exp) = was_volatile;
8d08fdba 1110 TREE_TYPE (exp) = type;
f376e137
MS
1111 if (init)
1112 TREE_TYPE (init) = itype;
f1dedc31 1113 return stmt_expr;
8d08fdba
MS
1114 }
1115
1116 if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL)
1117 /* just know that we've seen something for this node */
1118 TREE_USED (exp) = 1;
1119
e7843f33 1120 TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
f1dedc31
MM
1121 begin_init_stmts (&stmt_expr, &compound_stmt);
1122 destroy_temps = stmts_are_full_exprs_p;
1123 stmts_are_full_exprs_p = 0;
8d08fdba 1124 expand_aggr_init_1 (TYPE_BINFO (type), exp, exp,
b370501f 1125 init, LOOKUP_NORMAL|flags);
f1dedc31
MM
1126 stmt_expr = finish_init_stmts (stmt_expr, compound_stmt);
1127 stmts_are_full_exprs_p = destroy_temps;
e7843f33 1128 TREE_TYPE (exp) = type;
8d08fdba 1129 TREE_READONLY (exp) = was_const;
f30432d7 1130 TREE_THIS_VOLATILE (exp) = was_volatile;
f1dedc31
MM
1131
1132 return stmt_expr;
8d08fdba
MS
1133}
1134
1135static void
b370501f 1136expand_default_init (binfo, true_exp, exp, init, flags)
8d08fdba
MS
1137 tree binfo;
1138 tree true_exp, exp;
8d08fdba 1139 tree init;
8d08fdba
MS
1140 int flags;
1141{
fc378698
MS
1142 tree type = TREE_TYPE (exp);
1143
8d08fdba
MS
1144 /* It fails because there may not be a constructor which takes
1145 its own type as the first (or only parameter), but which does
1146 take other types via a conversion. So, if the thing initializing
1147 the expression is a unit element of type X, first try X(X&),
1148 followed by initialization by X. If neither of these work
1149 out, then look hard. */
1150 tree rval;
1151 tree parms;
8d08fdba 1152
277294d7 1153 if (init && TREE_CODE (init) != TREE_LIST
faf5394a
MS
1154 && (flags & LOOKUP_ONLYCONVERTING))
1155 {
1156 /* Base subobjects should only get direct-initialization. */
1157 if (true_exp != exp)
1158 abort ();
1159
c37dc68e
JM
1160 if (flags & DIRECT_BIND)
1161 /* Do nothing. We hit this in two cases: Reference initialization,
1162 where we aren't initializing a real variable, so we don't want
1163 to run a new constructor; and catching an exception, where we
1164 have already built up the constructor call so we could wrap it
1165 in an exception region. */;
27b8d0cd
MM
1166 else if (TREE_CODE (init) == CONSTRUCTOR)
1167 /* A brace-enclosed initializer has whatever type is
1168 required. There's no need to convert it. */
1169 ;
c37dc68e 1170 else
37c46b43 1171 init = ocp_convert (type, init, CONV_IMPLICIT|CONV_FORCE_TEMP, flags);
faf5394a 1172
c7ae64f2
JM
1173 if (TREE_CODE (init) == TRY_CATCH_EXPR)
1174 /* We need to protect the initialization of a catch parm
1175 with a call to terminate(), which shows up as a TRY_CATCH_EXPR
1176 around the TARGET_EXPR for the copy constructor. See
1177 expand_start_catch_block. */
1178 TREE_OPERAND (init, 0) = build (INIT_EXPR, TREE_TYPE (exp), exp,
1179 TREE_OPERAND (init, 0));
1180 else
1181 init = build (INIT_EXPR, TREE_TYPE (exp), exp, init);
1182 TREE_SIDE_EFFECTS (init) = 1;
f1dedc31 1183 finish_expr_stmt (init);
faf5394a
MS
1184 return;
1185 }
1186
b7484fbe
MS
1187 if (init == NULL_TREE
1188 || (TREE_CODE (init) == TREE_LIST && ! TREE_TYPE (init)))
8d08fdba
MS
1189 {
1190 parms = init;
db5ae43f
MS
1191 if (parms)
1192 init = TREE_VALUE (parms);
8d08fdba 1193 }
8d08fdba 1194 else
051e6fd7 1195 parms = build_tree_list (NULL_TREE, init);
8d08fdba 1196
8d08fdba
MS
1197 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
1198 {
1199 if (true_exp == exp)
e1b3e07d 1200 parms = tree_cons (NULL_TREE, integer_one_node, parms);
8d08fdba 1201 else
e1b3e07d 1202 parms = tree_cons (NULL_TREE, integer_zero_node, parms);
8d08fdba
MS
1203 flags |= LOOKUP_HAS_IN_CHARGE;
1204 }
1205
277294d7
JM
1206 rval = build_method_call (exp, ctor_identifier,
1207 parms, binfo, flags);
25eb19ff 1208 if (TREE_SIDE_EFFECTS (rval))
f1dedc31 1209 finish_expr_stmt (rval);
8d08fdba
MS
1210}
1211
1212/* This function is responsible for initializing EXP with INIT
1213 (if any).
1214
1215 BINFO is the binfo of the type for who we are performing the
1216 initialization. For example, if W is a virtual base class of A and B,
1217 and C : A, B.
1218 If we are initializing B, then W must contain B's W vtable, whereas
1219 were we initializing C, W must contain C's W vtable.
1220
1221 TRUE_EXP is nonzero if it is the true expression being initialized.
1222 In this case, it may be EXP, or may just contain EXP. The reason we
1223 need this is because if EXP is a base element of TRUE_EXP, we
1224 don't necessarily know by looking at EXP where its virtual
1225 baseclass fields should really be pointing. But we do know
1226 from TRUE_EXP. In constructors, we don't know anything about
1227 the value being initialized.
1228
8d08fdba
MS
1229 FLAGS is just passes to `build_method_call'. See that function for
1230 its description. */
1231
1232static void
b370501f 1233expand_aggr_init_1 (binfo, true_exp, exp, init, flags)
8d08fdba
MS
1234 tree binfo;
1235 tree true_exp, exp;
1236 tree init;
8d08fdba
MS
1237 int flags;
1238{
1239 tree type = TREE_TYPE (exp);
8d08fdba
MS
1240
1241 my_friendly_assert (init != error_mark_node && type != error_mark_node, 211);
1242
1243 /* Use a function returning the desired type to initialize EXP for us.
1244 If the function is a constructor, and its first argument is
1245 NULL_TREE, know that it was meant for us--just slide exp on
1246 in and expand the constructor. Constructors now come
1247 as TARGET_EXPRs. */
faf5394a
MS
1248
1249 if (init && TREE_CODE (exp) == VAR_DECL
1250 && TREE_CODE (init) == CONSTRUCTOR
1251 && TREE_HAS_CONSTRUCTOR (init))
1252 {
f1dedc31
MM
1253 /* If store_init_value returns NULL_TREE, the INIT has been
1254 record in the DECL_INITIAL for EXP. That means there's
1255 nothing more we have to do. */
1256 if (!store_init_value (exp, init))
faf5394a 1257 {
f1dedc31
MM
1258 if (!building_stmt_tree ())
1259 expand_decl_init (exp);
1260 }
1261 else
c557501d 1262 finish_expr_stmt (build (INIT_EXPR, type, exp, init));
faf5394a
MS
1263 return;
1264 }
1265
9e9ff709
MS
1266 /* We know that expand_default_init can handle everything we want
1267 at this point. */
b370501f 1268 expand_default_init (binfo, true_exp, exp, init, flags);
8d08fdba
MS
1269}
1270
1271/* Report an error if NAME is not the name of a user-defined,
1272 aggregate type. If OR_ELSE is nonzero, give an error message. */
e92cc029 1273
8d08fdba
MS
1274int
1275is_aggr_typedef (name, or_else)
1276 tree name;
1277 int or_else;
1278{
1279 tree type;
1280
1281 if (name == error_mark_node)
1282 return 0;
1283
1284 if (IDENTIFIER_HAS_TYPE_VALUE (name))
1285 type = IDENTIFIER_TYPE_VALUE (name);
8d08fdba
MS
1286 else
1287 {
1288 if (or_else)
8251199e 1289 cp_error ("`%T' is not an aggregate typedef", name);
8d08fdba
MS
1290 return 0;
1291 }
1292
1293 if (! IS_AGGR_TYPE (type)
73b0fce8
KL
1294 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1295 && TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM)
8d08fdba
MS
1296 {
1297 if (or_else)
8251199e 1298 cp_error ("`%T' is not an aggregate type", type);
8d08fdba
MS
1299 return 0;
1300 }
1301 return 1;
1302}
1303
be99da77
MS
1304/* Report an error if TYPE is not a user-defined, aggregate type. If
1305 OR_ELSE is nonzero, give an error message. */
e92cc029 1306
be99da77
MS
1307int
1308is_aggr_type (type, or_else)
1309 tree type;
1310 int or_else;
1311{
1312 if (type == error_mark_node)
1313 return 0;
1314
1315 if (! IS_AGGR_TYPE (type)
73b0fce8
KL
1316 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1317 && TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM)
be99da77
MS
1318 {
1319 if (or_else)
8251199e 1320 cp_error ("`%T' is not an aggregate type", type);
be99da77
MS
1321 return 0;
1322 }
1323 return 1;
1324}
1325
8d08fdba 1326/* Like is_aggr_typedef, but returns typedef if successful. */
e92cc029 1327
8d08fdba
MS
1328tree
1329get_aggr_from_typedef (name, or_else)
1330 tree name;
1331 int or_else;
1332{
1333 tree type;
1334
1335 if (name == error_mark_node)
1336 return NULL_TREE;
1337
1338 if (IDENTIFIER_HAS_TYPE_VALUE (name))
1339 type = IDENTIFIER_TYPE_VALUE (name);
8d08fdba
MS
1340 else
1341 {
1342 if (or_else)
8251199e 1343 cp_error ("`%T' fails to be an aggregate typedef", name);
8d08fdba
MS
1344 return NULL_TREE;
1345 }
1346
1347 if (! IS_AGGR_TYPE (type)
73b0fce8
KL
1348 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1349 && TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM)
8d08fdba
MS
1350 {
1351 if (or_else)
8251199e 1352 cp_error ("type `%T' is of non-aggregate type", type);
8d08fdba
MS
1353 return NULL_TREE;
1354 }
1355 return type;
1356}
1357
1358tree
1359get_type_value (name)
1360 tree name;
1361{
8d08fdba
MS
1362 if (name == error_mark_node)
1363 return NULL_TREE;
1364
1365 if (IDENTIFIER_HAS_TYPE_VALUE (name))
1366 return IDENTIFIER_TYPE_VALUE (name);
8d08fdba
MS
1367 else
1368 return NULL_TREE;
1369}
051e6fd7 1370
8d08fdba 1371\f
51c184be 1372/* This code could just as well go in `class.c', but is placed here for
8d08fdba
MS
1373 modularity. */
1374
be99da77 1375/* For an expression of the form TYPE :: NAME (PARMLIST), build
8d08fdba 1376 the appropriate function call. */
e92cc029 1377
8d08fdba 1378tree
be99da77
MS
1379build_member_call (type, name, parmlist)
1380 tree type, name, parmlist;
8d08fdba 1381{
be99da77 1382 tree t;
386b8a85 1383 tree method_name;
8d08fdba 1384 int dtor = 0;
8d08fdba
MS
1385 tree basetype_path, decl;
1386
72e61a07
JM
1387 if (TREE_CODE (name) == TEMPLATE_ID_EXPR
1388 && TREE_CODE (type) == NAMESPACE_DECL)
1389 {
18c32f69
JM
1390 /* 'name' already refers to the decls from the namespace, since we
1391 hit do_identifier for template_ids. */
c2e63b4c
ML
1392 method_name = TREE_OPERAND (name, 0);
1393 /* FIXME: Since we don't do independent names right yet, the
1394 name might also be a LOOKUP_EXPR. Once we resolve this to a
1395 real decl earlier, this can go. This may happen during
1396 tsubst'ing. */
1397 if (TREE_CODE (method_name) == LOOKUP_EXPR)
1398 {
1399 method_name = lookup_namespace_name
1400 (type, TREE_OPERAND (method_name, 0));
1401 TREE_OPERAND (name, 0) = method_name;
1402 }
1403 my_friendly_assert (is_overloaded_fn (method_name), 980519);
72e61a07
JM
1404 return build_x_function_call (name, parmlist, current_class_ref);
1405 }
1406
6633d636
MS
1407 if (type == std_node)
1408 return build_x_function_call (do_scoped_id (name, 0), parmlist,
1409 current_class_ref);
30394414
JM
1410 if (TREE_CODE (type) == NAMESPACE_DECL)
1411 return build_x_function_call (lookup_namespace_name (type, name),
1412 parmlist, current_class_ref);
6633d636 1413
8f032717 1414 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
b03a08ee
MM
1415 {
1416 method_name = TREE_OPERAND (name, 0);
8f032717
MM
1417 if (TREE_CODE (method_name) == COMPONENT_REF)
1418 method_name = TREE_OPERAND (method_name, 1);
b03a08ee
MM
1419 if (is_overloaded_fn (method_name))
1420 method_name = DECL_NAME (OVL_CURRENT (method_name));
8f032717 1421 TREE_OPERAND (name, 0) = method_name;
b03a08ee 1422 }
8f032717
MM
1423 else
1424 method_name = name;
386b8a85 1425
8d08fdba
MS
1426 if (TREE_CODE (method_name) == BIT_NOT_EXPR)
1427 {
1428 method_name = TREE_OPERAND (method_name, 0);
1429 dtor = 1;
1430 }
1431
a9aedbc2
MS
1432 /* This shouldn't be here, and build_member_call shouldn't appear in
1433 parse.y! (mrs) */
be99da77
MS
1434 if (type && TREE_CODE (type) == IDENTIFIER_NODE
1435 && get_aggr_from_typedef (type, 0) == 0)
a9aedbc2 1436 {
be99da77 1437 tree ns = lookup_name (type, 0);
a9aedbc2
MS
1438 if (ns && TREE_CODE (ns) == NAMESPACE_DECL)
1439 {
4ac14744 1440 return build_x_function_call (build_offset_ref (type, name), parmlist, current_class_ref);
a9aedbc2
MS
1441 }
1442 }
1443
be99da77 1444 if (type == NULL_TREE || ! is_aggr_type (type, 1))
8d08fdba
MS
1445 return error_mark_node;
1446
1447 /* An operator we did not like. */
1448 if (name == NULL_TREE)
1449 return error_mark_node;
1450
1451 if (dtor)
1452 {
8251199e 1453 cp_error ("cannot call destructor `%T::~%T' without object", type,
8d08fdba
MS
1454 method_name);
1455 return error_mark_node;
1456 }
1457
51924768 1458 decl = maybe_dummy_object (type, &basetype_path);
8d08fdba 1459
51924768 1460 /* Convert 'this' to the specified type to disambiguate conversion
879fb1de
JM
1461 to the function's context. Apparently Standard C++ says that we
1462 shouldn't do this. */
1463 if (decl == current_class_ref
1464 && ! pedantic
1465 && ACCESSIBLY_UNIQUELY_DERIVED_P (type, current_class_type))
8d08fdba 1466 {
4ac14744 1467 tree olddecl = current_class_ptr;
8d08fdba
MS
1468 tree oldtype = TREE_TYPE (TREE_TYPE (olddecl));
1469 if (oldtype != type)
1470 {
91063b51 1471 tree newtype = build_qualified_type (type, TYPE_QUALS (oldtype));
6060a796 1472 decl = convert_force (build_pointer_type (newtype), olddecl, 0);
51924768 1473 decl = build_indirect_ref (decl, NULL_PTR);
8d08fdba 1474 }
8d08fdba
MS
1475 }
1476
71851aaa
MS
1477 if (method_name == constructor_name (type)
1478 || method_name == constructor_name_full (type))
1479 return build_functional_cast (type, parmlist);
4bb0968f 1480 if (lookup_fnfields (basetype_path, method_name, 0))
386b8a85
JM
1481 return build_method_call (decl,
1482 TREE_CODE (name) == TEMPLATE_ID_EXPR
1483 ? name : method_name,
1484 parmlist, basetype_path,
8d08fdba
MS
1485 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
1486 if (TREE_CODE (name) == IDENTIFIER_NODE
8926095f 1487 && ((t = lookup_field (TYPE_BINFO (type), name, 1, 0))))
8d08fdba
MS
1488 {
1489 if (t == error_mark_node)
1490 return error_mark_node;
1491 if (TREE_CODE (t) == FIELD_DECL)
1492 {
51924768 1493 if (is_dummy_object (decl))
8d08fdba 1494 {
8251199e 1495 cp_error ("invalid use of non-static field `%D'", t);
8d08fdba
MS
1496 return error_mark_node;
1497 }
1498 decl = build (COMPONENT_REF, TREE_TYPE (t), decl, t);
1499 }
1500 else if (TREE_CODE (t) == VAR_DECL)
1501 decl = t;
1502 else
1503 {
8251199e 1504 cp_error ("invalid use of member `%D'", t);
8d08fdba
MS
1505 return error_mark_node;
1506 }
3c215895
JM
1507 if (TYPE_LANG_SPECIFIC (TREE_TYPE (decl)))
1508 return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, decl,
1509 parmlist, NULL_TREE);
8d08fdba
MS
1510 return build_function_call (decl, parmlist);
1511 }
1512 else
1513 {
8251199e 1514 cp_error ("no method `%T::%D'", type, name);
8d08fdba
MS
1515 return error_mark_node;
1516 }
1517}
1518
1519/* Build a reference to a member of an aggregate. This is not a
1520 C++ `&', but really something which can have its address taken,
be99da77
MS
1521 and then act as a pointer to member, for example TYPE :: FIELD
1522 can have its address taken by saying & TYPE :: FIELD.
8d08fdba
MS
1523
1524 @@ Prints out lousy diagnostics for operator <typename>
1525 @@ fields.
1526
51c184be 1527 @@ This function should be rewritten and placed in search.c. */
e92cc029 1528
8d08fdba 1529tree
be99da77
MS
1530build_offset_ref (type, name)
1531 tree type, name;
8d08fdba 1532{
d6479fe7
MM
1533 tree decl, t = error_mark_node;
1534 tree member;
fc378698 1535 tree basebinfo = NULL_TREE;
2a238a97 1536 tree orig_name = name;
8d08fdba 1537
5f311aec 1538 /* class templates can come in as TEMPLATE_DECLs here. */
874503bc 1539 if (TREE_CODE (name) == TEMPLATE_DECL)
93cdc044
JM
1540 return name;
1541
6633d636
MS
1542 if (type == std_node)
1543 return do_scoped_id (name, 0);
1544
53b22f3d
MM
1545 if (processing_template_decl || uses_template_parms (type))
1546 return build_min_nt (SCOPE_REF, type, name);
5566b478 1547
a9aedbc2 1548 /* Handle namespace names fully here. */
30394414 1549 if (TREE_CODE (type) == NAMESPACE_DECL)
9a68c51f
JM
1550 {
1551 t = lookup_namespace_name (type, name);
287662c5 1552 if (t != error_mark_node && ! type_unknown_p (t))
1c35f5b6
JM
1553 {
1554 mark_used (t);
1555 t = convert_from_reference (t);
1556 }
1557 return t;
9a68c51f 1558 }
a9aedbc2 1559
be99da77 1560 if (type == NULL_TREE || ! is_aggr_type (type, 1))
8d08fdba
MS
1561 return error_mark_node;
1562
2a238a97
MM
1563 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
1564 {
1565 /* If the NAME is a TEMPLATE_ID_EXPR, we are looking at
1566 something like `a.template f<int>' or the like. For the most
1567 part, we treat this just like a.f. We do remember, however,
1568 the template-id that was used. */
1569 name = TREE_OPERAND (orig_name, 0);
e4a84209 1570
c65a922c
TP
1571 if (DECL_P (name))
1572 name = DECL_NAME (name);
1573 else
1574 {
1575 if (TREE_CODE (name) == LOOKUP_EXPR)
1576 /* This can happen during tsubst'ing. */
1577 name = TREE_OPERAND (name, 0);
1578 else
1579 {
1580 if (TREE_CODE (name) == COMPONENT_REF)
1581 name = TREE_OPERAND (name, 1);
1582 if (TREE_CODE (name) == OVERLOAD)
1583 name = DECL_NAME (OVL_CURRENT (name));
1584 }
1585 }
e4a84209 1586
2a238a97
MM
1587 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 0);
1588 }
1589
8d08fdba
MS
1590 if (TREE_CODE (name) == BIT_NOT_EXPR)
1591 {
1c2c08a5 1592 if (! check_dtor_name (type, name))
8251199e 1593 cp_error ("qualified type `%T' does not match destructor name `~%T'",
1c2c08a5
JM
1594 type, TREE_OPERAND (name, 0));
1595 name = dtor_identifier;
8d08fdba 1596 }
be99da77 1597
d0f062fb 1598 if (!COMPLETE_TYPE_P (complete_type (type))
61a127b3 1599 && !TYPE_BEING_DEFINED (type))
8d08fdba 1600 {
61a127b3
MM
1601 cp_error ("incomplete type `%T' does not have member `%D'", type,
1602 name);
8d08fdba
MS
1603 return error_mark_node;
1604 }
1605
51924768 1606 decl = maybe_dummy_object (type, &basebinfo);
8d08fdba 1607
d6479fe7 1608 member = lookup_member (basebinfo, name, 1, 0);
00595019 1609
d6479fe7 1610 if (member == error_mark_node)
00595019
MS
1611 return error_mark_node;
1612
aa52c1ff 1613 /* A lot of this logic is now handled in lookup_member. */
3fc5037b 1614 if (member && BASELINK_P (member))
8d08fdba 1615 {
8d08fdba 1616 /* Go from the TREE_BASELINK to the member function info. */
d6479fe7 1617 tree fnfields = member;
8d08fdba
MS
1618 t = TREE_VALUE (fnfields);
1619
2a238a97
MM
1620 if (TREE_CODE (orig_name) == TEMPLATE_ID_EXPR)
1621 {
1622 /* The FNFIELDS are going to contain functions that aren't
1623 necessarily templates, and templates that don't
1624 necessarily match the explicit template parameters. We
1625 save all the functions, and the explicit parameters, and
1626 then figure out exactly what to instantiate with what
1627 arguments in instantiate_type. */
1628
1629 if (TREE_CODE (t) != OVERLOAD)
1630 /* The code in instantiate_type which will process this
1631 expects to encounter OVERLOADs, not raw functions. */
1632 t = ovl_cons (t, NULL_TREE);
051e6fd7 1633
2a238a97 1634 return build (OFFSET_REF,
05e0b2f4 1635 unknown_type_node,
2a238a97
MM
1636 decl,
1637 build (TEMPLATE_ID_EXPR,
1638 TREE_TYPE (t),
1639 t,
1640 TREE_OPERAND (orig_name, 1)));
1641 }
1642
2c73f9f5 1643 if (!really_overloaded_fn (t))
8d08fdba 1644 {
2c73f9f5
ML
1645 /* Get rid of a potential OVERLOAD around it */
1646 t = OVL_CURRENT (t);
1647
fc378698 1648 /* unique functions are handled easily. */
d6479fe7
MM
1649 if (!enforce_access (basebinfo, t))
1650 return error_mark_node;
fc378698 1651 mark_used (t);
848b92e1
JM
1652 if (DECL_STATIC_FUNCTION_P (t))
1653 return t;
fc378698 1654 return build (OFFSET_REF, TREE_TYPE (t), decl, t);
8d08fdba
MS
1655 }
1656
05e0b2f4
JM
1657 TREE_TYPE (fnfields) = unknown_type_node;
1658 return build (OFFSET_REF, unknown_type_node, decl, fnfields);
8d08fdba
MS
1659 }
1660
d6479fe7 1661 t = member;
8d08fdba
MS
1662
1663 if (t == NULL_TREE)
1664 {
8251199e 1665 cp_error ("`%D' is not a member of type `%T'", name, type);
8d08fdba
MS
1666 return error_mark_node;
1667 }
1668
1669 if (TREE_CODE (t) == TYPE_DECL)
1670 {
51c184be
MS
1671 TREE_USED (t) = 1;
1672 return t;
8d08fdba
MS
1673 }
1674 /* static class members and class-specific enum
1675 values can be returned without further ado. */
1676 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL)
1677 {
72b7eeff 1678 mark_used (t);
42976354 1679 return convert_from_reference (t);
8d08fdba
MS
1680 }
1681
162bc98d 1682 if (TREE_CODE (t) == FIELD_DECL && DECL_C_BIT_FIELD (t))
b7484fbe 1683 {
8251199e 1684 cp_error ("illegal pointer to bit field `%D'", t);
b7484fbe
MS
1685 return error_mark_node;
1686 }
1687
8d08fdba 1688 /* static class functions too. */
be99da77
MS
1689 if (TREE_CODE (t) == FUNCTION_DECL
1690 && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
8d08fdba
MS
1691 my_friendly_abort (53);
1692
be99da77
MS
1693 /* In member functions, the form `type::name' is no longer
1694 equivalent to `this->type::name', at least not until
1695 resolve_offset_ref. */
8d08fdba
MS
1696 return build (OFFSET_REF, build_offset_type (type, TREE_TYPE (t)), decl, t);
1697}
1698
8d08fdba
MS
1699/* If a OFFSET_REF made it through to here, then it did
1700 not have its address taken. */
1701
1702tree
1703resolve_offset_ref (exp)
1704 tree exp;
1705{
1706 tree type = TREE_TYPE (exp);
1707 tree base = NULL_TREE;
1708 tree member;
1709 tree basetype, addr;
1710
4ac14744
MS
1711 if (TREE_CODE (exp) == OFFSET_REF)
1712 {
1713 member = TREE_OPERAND (exp, 1);
1714 base = TREE_OPERAND (exp, 0);
1715 }
1716 else
8d08fdba
MS
1717 {
1718 my_friendly_assert (TREE_CODE (type) == OFFSET_TYPE, 214);
1719 if (TYPE_OFFSET_BASETYPE (type) != current_class_type)
1720 {
8251199e 1721 error ("object missing in use of pointer-to-member construct");
8d08fdba
MS
1722 return error_mark_node;
1723 }
1724 member = exp;
1725 type = TREE_TYPE (type);
4ac14744 1726 base = current_class_ref;
8d08fdba
MS
1727 }
1728
05e0b2f4
JM
1729 if (BASELINK_P (member))
1730 {
d2c192ad
JM
1731 if (! flag_ms_extensions)
1732 cp_pedwarn ("assuming & on overloaded member function");
05e0b2f4
JM
1733 return build_unary_op (ADDR_EXPR, exp, 0);
1734 }
1735
1736 if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
1737 {
d2c192ad
JM
1738 if (! flag_ms_extensions)
1739 cp_pedwarn ("assuming & on `%E'", member);
05e0b2f4
JM
1740 return build_unary_op (ADDR_EXPR, exp, 0);
1741 }
1742
8d08fdba 1743 if ((TREE_CODE (member) == VAR_DECL
162bc98d
JM
1744 && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member))
1745 && ! TYPE_PTRMEM_P (TREE_TYPE (member)))
a359be75 1746 || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE)
8d08fdba
MS
1747 {
1748 /* These were static members. */
1749 if (mark_addressable (member) == 0)
1750 return error_mark_node;
1751 return member;
1752 }
1753
faf5394a
MS
1754 if (TREE_CODE (TREE_TYPE (member)) == POINTER_TYPE
1755 && TREE_CODE (TREE_TYPE (TREE_TYPE (member))) == METHOD_TYPE)
1756 return member;
1757
8d08fdba
MS
1758 /* Syntax error can cause a member which should
1759 have been seen as static to be grok'd as non-static. */
4ac14744 1760 if (TREE_CODE (member) == FIELD_DECL && current_class_ref == NULL_TREE)
8d08fdba
MS
1761 {
1762 if (TREE_ADDRESSABLE (member) == 0)
1763 {
8251199e 1764 cp_error_at ("member `%D' is non-static but referenced as a static member",
f30432d7 1765 member);
8251199e 1766 error ("at this point in file");
8d08fdba
MS
1767 TREE_ADDRESSABLE (member) = 1;
1768 }
1769 return error_mark_node;
1770 }
1771
1772 /* The first case is really just a reference to a member of `this'. */
1773 if (TREE_CODE (member) == FIELD_DECL
51924768 1774 && (base == current_class_ref || is_dummy_object (base)))
8d08fdba 1775 {
5bb1b569 1776 tree expr;
8d08fdba 1777
aa52c1ff
JM
1778 basetype = DECL_CONTEXT (member);
1779
1780 /* Try to get to basetype from 'this'; if that doesn't work,
1781 nothing will. */
1782 base = current_class_ref;
1783
1784 /* First convert to the intermediate base specified, if appropriate. */
8d08fdba 1785 if (TREE_CODE (exp) == OFFSET_REF && TREE_CODE (type) == OFFSET_TYPE)
aa52c1ff 1786 base = build_scoped_ref (base, TYPE_OFFSET_BASETYPE (type));
39211cd5 1787
aa52c1ff
JM
1788 addr = build_unary_op (ADDR_EXPR, base, 0);
1789 addr = convert_pointer_to (basetype, addr);
1790
1791 if (addr == error_mark_node)
1792 return error_mark_node;
051e6fd7 1793
5bb1b569
MM
1794 expr = build (COMPONENT_REF, TREE_TYPE (member),
1795 build_indirect_ref (addr, NULL_PTR), member);
1796 return convert_from_reference (expr);
8d08fdba
MS
1797 }
1798
f49422da 1799 /* Ensure that we have an object. */
51924768 1800 if (is_dummy_object (base))
f49422da
MS
1801 addr = error_mark_node;
1802 else
5bb1b569
MM
1803 /* If this is a reference to a member function, then return the
1804 address of the member function (which may involve going
1805 through the object's vtable), otherwise, return an expression
1806 for the dereferenced pointer-to-member construct. */
1807 addr = build_unary_op (ADDR_EXPR, base, 0);
8d08fdba 1808
162bc98d 1809 if (TYPE_PTRMEM_P (TREE_TYPE (member)))
8d08fdba 1810 {
f49422da
MS
1811 if (addr == error_mark_node)
1812 {
8251199e 1813 cp_error ("object missing in `%E'", exp);
f49422da
MS
1814 return error_mark_node;
1815 }
1816
162bc98d 1817 basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (TREE_TYPE (member)));
8d08fdba 1818 addr = convert_pointer_to (basetype, addr);
162bc98d 1819 member = cp_convert (ptrdiff_type_node, member);
051e6fd7 1820
cd8ed629
MM
1821 if (!flag_new_abi)
1822 /* Pointer to data members are offset by one, so that a null
1823 pointer with a real value of 0 is distinguishable from an
1824 offset of the first member of a structure. */
1825 member = build_binary_op (MINUS_EXPR, member,
1826 cp_convert (ptrdiff_type_node,
1827 integer_one_node));
c91a56d2 1828
8d08fdba 1829 return build1 (INDIRECT_REF, type,
fef71f9d
JM
1830 build (PLUS_EXPR, build_pointer_type (type),
1831 addr, member));
8d08fdba
MS
1832 }
1833 else if (TYPE_PTRMEMFUNC_P (TREE_TYPE (member)))
1834 {
b7484fbe 1835 return get_member_function_from_ptrfunc (&addr, member);
8d08fdba
MS
1836 }
1837 my_friendly_abort (56);
1838 /* NOTREACHED */
1839 return NULL_TREE;
1840}
1841
1842/* Return either DECL or its known constant value (if it has one). */
1843
1844tree
1845decl_constant_value (decl)
1846 tree decl;
1847{
1848 if (! TREE_THIS_VOLATILE (decl)
61a127b3 1849 && DECL_INITIAL (decl)
bd6dd845 1850 && DECL_INITIAL (decl) != error_mark_node
8d08fdba
MS
1851 /* This is invalid if initial value is not constant.
1852 If it has either a function call, a memory reference,
1853 or a variable, then re-evaluating it could give different results. */
1854 && TREE_CONSTANT (DECL_INITIAL (decl))
1855 /* Check for cases where this is sub-optimal, even though valid. */
61a127b3 1856 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
8d08fdba
MS
1857 return DECL_INITIAL (decl);
1858 return decl;
1859}
1860\f
8d08fdba
MS
1861/* Common subroutines of build_new and build_vec_delete. */
1862
c787dd82 1863/* Call the global __builtin_delete to delete ADDR. */
8d08fdba 1864
bd6dd845 1865static tree
c787dd82
JM
1866build_builtin_delete_call (addr)
1867 tree addr;
8d08fdba 1868{
a6ecf8b6 1869 mark_used (global_delete_fndecl);
0c11ada6 1870 return build_call (global_delete_fndecl, build_tree_list (NULL_TREE, addr));
8d08fdba
MS
1871}
1872\f
1873/* Generate a C++ "new" expression. DECL is either a TREE_LIST
1874 (which needs to go through some sort of groktypename) or it
1875 is the name of the class we are newing. INIT is an initialization value.
1876 It is either an EXPRLIST, an EXPR_NO_COMMAS, or something in braces.
1877 If INIT is void_type_node, it means do *not* call a constructor
1878 for this instance.
1879
1880 For types with constructors, the data returned is initialized
1881 by the appropriate constructor.
1882
1883 Whether the type has a constructor or not, if it has a pointer
1884 to a virtual function table, then that pointer is set up
1885 here.
1886
1887 Unless I am mistaken, a call to new () will return initialized
1888 data regardless of whether the constructor itself is private or
8926095f 1889 not. NOPE; new fails if the constructor is private (jcm).
8d08fdba
MS
1890
1891 Note that build_new does nothing to assure that any special
1892 alignment requirements of the type are met. Rather, it leaves
1893 it up to malloc to do the right thing. Otherwise, folding to
1894 the right alignment cal cause problems if the user tries to later
1895 free the memory returned by `new'.
1896
1897 PLACEMENT is the `placement' list for user-defined operator new (). */
1898
d18c083e
MS
1899extern int flag_check_new;
1900
8d08fdba
MS
1901tree
1902build_new (placement, decl, init, use_global_new)
1903 tree placement;
1904 tree decl, init;
1905 int use_global_new;
1906{
a0d5fba7 1907 tree type, rval;
a703fb38 1908 tree nelts = NULL_TREE, t;
8926095f 1909 int has_array = 0;
8d08fdba 1910
8d08fdba
MS
1911 if (decl == error_mark_node)
1912 return error_mark_node;
1913
1914 if (TREE_CODE (decl) == TREE_LIST)
1915 {
1916 tree absdcl = TREE_VALUE (decl);
1917 tree last_absdcl = NULL_TREE;
8d08fdba
MS
1918
1919 if (current_function_decl
1920 && DECL_CONSTRUCTOR_P (current_function_decl))
2aa3110a 1921 my_friendly_assert (immediate_size_expand == 0, 19990926);
8d08fdba
MS
1922
1923 nelts = integer_one_node;
1924
1925 if (absdcl && TREE_CODE (absdcl) == CALL_EXPR)
8926095f 1926 my_friendly_abort (215);
8d08fdba
MS
1927 while (absdcl && TREE_CODE (absdcl) == INDIRECT_REF)
1928 {
1929 last_absdcl = absdcl;
1930 absdcl = TREE_OPERAND (absdcl, 0);
1931 }
1932
1933 if (absdcl && TREE_CODE (absdcl) == ARRAY_REF)
1934 {
1935 /* probably meant to be a vec new */
1936 tree this_nelts;
1937
51c184be
MS
1938 while (TREE_OPERAND (absdcl, 0)
1939 && TREE_CODE (TREE_OPERAND (absdcl, 0)) == ARRAY_REF)
1940 {
1941 last_absdcl = absdcl;
1942 absdcl = TREE_OPERAND (absdcl, 0);
1943 }
1944
8d08fdba
MS
1945 has_array = 1;
1946 this_nelts = TREE_OPERAND (absdcl, 1);
1947 if (this_nelts != error_mark_node)
1948 {
1949 if (this_nelts == NULL_TREE)
8251199e 1950 error ("new of array type fails to specify size");
5156628f 1951 else if (processing_template_decl)
5566b478
MS
1952 {
1953 nelts = this_nelts;
1954 absdcl = TREE_OPERAND (absdcl, 0);
1955 }
8d08fdba
MS
1956 else
1957 {
6a8f78d5
JM
1958 int flags = pedantic ? WANT_INT : (WANT_INT | WANT_ENUM);
1959 if (build_expr_type_conversion (flags, this_nelts, 0)
1960 == NULL_TREE)
1961 pedwarn ("size in array new must have integral type");
1962
37c46b43 1963 this_nelts = save_expr (cp_convert (sizetype, this_nelts));
8d08fdba
MS
1964 absdcl = TREE_OPERAND (absdcl, 0);
1965 if (this_nelts == integer_zero_node)
1966 {
8251199e 1967 warning ("zero size array reserves no space");
8d08fdba
MS
1968 nelts = integer_zero_node;
1969 }
1970 else
337c90cc 1971 nelts = build_binary_op (MULT_EXPR, nelts, this_nelts);
8d08fdba
MS
1972 }
1973 }
1974 else
1975 nelts = integer_zero_node;
1976 }
1977
1978 if (last_absdcl)
1979 TREE_OPERAND (last_absdcl, 0) = absdcl;
1980 else
1981 TREE_VALUE (decl) = absdcl;
1982
a0d5fba7 1983 type = groktypename (decl);
8926095f 1984 if (! type || type == error_mark_node)
2aa3110a 1985 return error_mark_node;
8d08fdba
MS
1986 }
1987 else if (TREE_CODE (decl) == IDENTIFIER_NODE)
1988 {
1989 if (IDENTIFIER_HAS_TYPE_VALUE (decl))
1990 {
1991 /* An aggregate type. */
1992 type = IDENTIFIER_TYPE_VALUE (decl);
d2e5ee5c 1993 decl = TYPE_MAIN_DECL (type);
8d08fdba
MS
1994 }
1995 else
1996 {
1997 /* A builtin type. */
1998 decl = lookup_name (decl, 1);
1999 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 215);
2000 type = TREE_TYPE (decl);
2001 }
8d08fdba
MS
2002 }
2003 else if (TREE_CODE (decl) == TYPE_DECL)
2004 {
2005 type = TREE_TYPE (decl);
8d08fdba
MS
2006 }
2007 else
2008 {
2009 type = decl;
d2e5ee5c 2010 decl = TYPE_MAIN_DECL (type);
8d08fdba
MS
2011 }
2012
5156628f 2013 if (processing_template_decl)
5566b478 2014 {
5566b478 2015 if (has_array)
a09ba2e0
MM
2016 t = tree_cons (tree_cons (NULL_TREE, type, NULL_TREE),
2017 build_min_nt (ARRAY_REF, NULL_TREE, nelts),
2018 NULL_TREE);
5566b478
MS
2019 else
2020 t = type;
2021
2022 rval = build_min_nt (NEW_EXPR, placement, t, init);
2023 NEW_EXPR_USE_GLOBAL (rval) = use_global_new;
2024 return rval;
2025 }
2026
8926095f
MS
2027 /* ``A reference cannot be created by the new operator. A reference
2028 is not an object (8.2.2, 8.4.3), so a pointer to it could not be
2029 returned by new.'' ARM 5.3.3 */
2030 if (TREE_CODE (type) == REFERENCE_TYPE)
8d08fdba 2031 {
8251199e 2032 error ("new cannot be applied to a reference type");
a0d5fba7 2033 type = TREE_TYPE (type);
8d08fdba
MS
2034 }
2035
b7484fbe
MS
2036 if (TREE_CODE (type) == FUNCTION_TYPE)
2037 {
8251199e 2038 error ("new cannot be applied to a function type");
b7484fbe
MS
2039 return error_mark_node;
2040 }
2041
8926095f
MS
2042 /* When the object being created is an array, the new-expression yields a
2043 pointer to the initial element (if any) of the array. For example,
2044 both new int and new int[10] return an int*. 5.3.4. */
2045 if (TREE_CODE (type) == ARRAY_TYPE && has_array == 0)
8d08fdba 2046 {
8926095f
MS
2047 nelts = array_type_nelts_top (type);
2048 has_array = 1;
a0d5fba7 2049 type = TREE_TYPE (type);
8d08fdba
MS
2050 }
2051
a0d5fba7
JM
2052 if (has_array)
2053 t = build_nt (ARRAY_REF, type, nelts);
2054 else
2055 t = type;
2056
2057 rval = build (NEW_EXPR, build_pointer_type (type), placement, t, init);
2058 NEW_EXPR_USE_GLOBAL (rval) = use_global_new;
2059 TREE_SIDE_EFFECTS (rval) = 1;
b3ab27f3
MM
2060 rval = build_new_1 (rval);
2061 if (rval == error_mark_node)
2062 return error_mark_node;
a0d5fba7
JM
2063
2064 /* Wrap it in a NOP_EXPR so warn_if_unused_value doesn't complain. */
2065 rval = build1 (NOP_EXPR, TREE_TYPE (rval), rval);
2066 TREE_NO_UNUSED_WARNING (rval) = 1;
2067
a0d5fba7
JM
2068 return rval;
2069}
2070
743f140d
PB
2071/* Given a Java class, return a decl for the corresponding java.lang.Class. */
2072
e97f22c9 2073tree
743f140d
PB
2074build_java_class_ref (type)
2075 tree type;
2076{
2077 tree name, class_decl;
2078 static tree CL_prefix = NULL_TREE;
743f140d
PB
2079 if (CL_prefix == NULL_TREE)
2080 CL_prefix = get_identifier("_CL_");
2081 if (jclass_node == NULL_TREE)
2082 {
2083 jclass_node = IDENTIFIER_GLOBAL_VALUE (get_identifier("jclass"));
2084 if (jclass_node == NULL_TREE)
2085 fatal("call to Java constructor, while `jclass' undefined");
2086 jclass_node = TREE_TYPE (jclass_node);
2087 }
2088 name = build_overload_with_type (CL_prefix, type);
2089 class_decl = IDENTIFIER_GLOBAL_VALUE (name);
2090 if (class_decl == NULL_TREE)
2091 {
743f140d
PB
2092 class_decl = build_decl (VAR_DECL, name, TREE_TYPE (jclass_node));
2093 TREE_STATIC (class_decl) = 1;
2094 DECL_EXTERNAL (class_decl) = 1;
2095 TREE_PUBLIC (class_decl) = 1;
2096 DECL_ARTIFICIAL (class_decl) = 1;
2097 DECL_IGNORED_P (class_decl) = 1;
2098 pushdecl_top_level (class_decl);
2099 make_decl_rtl (class_decl, NULL_PTR, 1);
743f140d
PB
2100 }
2101 return class_decl;
2102}
2103
834c6dff
MM
2104/* Returns teh size of the cookie to use when allocating an array
2105 whose elements have the indicated TYPE. Assumes that it is already
2106 known that a cookie is needed. */
2107
2108static tree
2109get_cookie_size (type)
2110 tree type;
2111{
2112 tree cookie_size;
2113
2114 if (flag_new_abi)
2115 {
2116 /* Under the new ABI, we need to allocate an additional max
2117 (sizeof (size_t), alignof (true_type)) bytes. */
2118 tree sizetype_size;
2119 tree type_align;
2120
2121 sizetype_size = size_in_bytes (sizetype);
2122 type_align = size_int (TYPE_ALIGN_UNIT (type));
2123 if (INT_CST_LT_UNSIGNED (type_align, sizetype_size))
2124 cookie_size = sizetype_size;
2125 else
2126 cookie_size = type_align;
2127 }
2128 else
2129 cookie_size = BI_header_size;
2130
2131 return cookie_size;
2132}
2133
a0d5fba7
JM
2134/* Called from cplus_expand_expr when expanding a NEW_EXPR. The return
2135 value is immediately handed to expand_expr. */
2136
834c6dff 2137static tree
a0d5fba7
JM
2138build_new_1 (exp)
2139 tree exp;
2140{
56c5d8bf 2141 tree placement, init;
a0d5fba7 2142 tree type, true_type, size, rval;
a703fb38
KG
2143 tree nelts = NULL_TREE;
2144 tree alloc_expr, alloc_node = NULL_TREE;
a0d5fba7 2145 int has_array = 0;
834c6dff 2146 enum tree_code code;
a0d5fba7 2147 int use_cookie, nothrow, check_new;
834c6dff
MM
2148 /* Nonzero if the user wrote `::new' rather than just `new'. */
2149 int globally_qualified_p;
2150 /* Nonzero if we're going to call a global operator new, rather than
2151 a class-specific version. */
a0d5fba7 2152 int use_global_new;
743f140d 2153 int use_java_new = 0;
834c6dff
MM
2154 /* If non-NULL, the number of extra bytes to allocate at the
2155 beginning of the storage allocated for an array-new expression in
2156 order to store the number of elements. */
2157 tree cookie_size = NULL_TREE;
a0d5fba7
JM
2158
2159 placement = TREE_OPERAND (exp, 0);
2160 type = TREE_OPERAND (exp, 1);
2161 init = TREE_OPERAND (exp, 2);
834c6dff 2162 globally_qualified_p = NEW_EXPR_USE_GLOBAL (exp);
a0d5fba7
JM
2163
2164 if (TREE_CODE (type) == ARRAY_REF)
2165 {
2166 has_array = 1;
2167 nelts = TREE_OPERAND (type, 1);
2168 type = TREE_OPERAND (type, 0);
2169 }
2170 true_type = type;
2171
834c6dff
MM
2172 code = has_array ? VEC_NEW_EXPR : NEW_EXPR;
2173
91063b51 2174 if (CP_TYPE_QUALS (type))
8ccc31eb
MS
2175 type = TYPE_MAIN_VARIANT (type);
2176
8d08fdba
MS
2177 /* If our base type is an array, then make sure we know how many elements
2178 it has. */
2179 while (TREE_CODE (true_type) == ARRAY_TYPE)
2180 {
2181 tree this_nelts = array_type_nelts_top (true_type);
337c90cc 2182 nelts = build_binary_op (MULT_EXPR, nelts, this_nelts);
8d08fdba
MS
2183 true_type = TREE_TYPE (true_type);
2184 }
5566b478 2185
66543169 2186 if (!complete_type_or_else (true_type, exp))
8f259df3 2187 return error_mark_node;
5566b478 2188
8d08fdba
MS
2189 if (has_array)
2190 size = fold (build_binary_op (MULT_EXPR, size_in_bytes (true_type),
337c90cc 2191 nelts));
8d08fdba
MS
2192 else
2193 size = size_in_bytes (type);
2194
cc600f33 2195 if (TREE_CODE (true_type) == VOID_TYPE)
e1cd6e56 2196 {
8251199e 2197 error ("invalid type `void' for new");
e1cd6e56
MS
2198 return error_mark_node;
2199 }
2200
a7a64a77
MM
2201 if (abstract_virtuals_error (NULL_TREE, true_type))
2202 return error_mark_node;
8926095f 2203
834c6dff
MM
2204 /* Figure out whether or not we're going to use the global operator
2205 new. */
2206 if (!globally_qualified_p
2207 && IS_AGGR_TYPE (true_type)
2208 && ((!has_array && TYPE_HAS_NEW_OPERATOR (true_type))
2209 || (has_array && TYPE_HAS_ARRAY_NEW_OPERATOR (true_type))))
2210 use_global_new = 0;
2211 else
2212 use_global_new = 1;
2213
2214 /* We only need cookies for arrays containing types for which we
2215 need cookies. */
2216 if (!has_array || !TYPE_VEC_NEW_USES_COOKIE (true_type))
2217 use_cookie = 0;
2218 /* When using placement new, users may not realize that they need
2219 the extra storage. Under the old ABI, we don't allocate the
2220 cookie whenever they use one placement argument of type `void
2221 *'. Under the new ABI, we require that the operator called be
2222 the global placement operator delete[]. */
2223 else if (placement && !TREE_CHAIN (placement)
2224 && same_type_p (TREE_TYPE (TREE_VALUE (placement)),
2225 ptr_type_node))
2226 use_cookie = (!flag_new_abi || !use_global_new);
2227 /* Otherwise, we need the cookie. */
2228 else
2229 use_cookie = 1;
5156628f 2230
834c6dff
MM
2231 /* Compute the number of extra bytes to allocate, now that we know
2232 whether or not we need the cookie. */
5156628f 2233 if (use_cookie)
fc378698 2234 {
834c6dff
MM
2235 cookie_size = get_cookie_size (true_type);
2236 size = size_binop (PLUS_EXPR, size, cookie_size);
fc378698 2237 }
a28e3c7f 2238
834c6dff
MM
2239 if (has_array && init && pedantic)
2240 cp_pedwarn ("initialization in array new");
2241
e92cc029 2242 /* Allocate the object. */
da4768fe 2243
9bfadf57 2244 if (! placement && TYPE_FOR_JAVA (true_type))
743f140d 2245 {
8c1bd4f5 2246 tree class_addr, alloc_decl;
743f140d
PB
2247 tree class_decl = build_java_class_ref (true_type);
2248 tree class_size = size_in_bytes (true_type);
2249 static char alloc_name[] = "_Jv_AllocObject";
2250 use_java_new = 1;
2251 alloc_decl = IDENTIFIER_GLOBAL_VALUE (get_identifier (alloc_name));
2252 if (alloc_decl == NULL_TREE)
2253 fatal("call to Java constructor, while `%s' undefined", alloc_name);
2254 class_addr = build1 (ADDR_EXPR, jclass_node, class_decl);
2255 rval = build_function_call (alloc_decl,
2256 tree_cons (NULL_TREE, class_addr,
2257 build_tree_list (NULL_TREE,
2258 class_size)));
2259 rval = cp_convert (build_pointer_type (true_type), rval);
2260 }
8d08fdba
MS
2261 else
2262 {
834c6dff
MM
2263 tree fnname;
2264 tree args;
2265
2266 args = tree_cons (NULL_TREE, size, placement);
2267 fnname = ansi_opname[code];
2268
2269 if (use_global_new)
2270 rval = (build_new_function_call
2271 (lookup_function_nonclass (fnname, args),
2272 args));
2273 else
2274 rval = build_method_call (build_dummy_object (true_type),
2275 fnname, args, NULL_TREE,
2276 LOOKUP_NORMAL);
da4768fe 2277 rval = cp_convert (build_pointer_type (true_type), rval);
8d08fdba
MS
2278 }
2279
047f64a3
JM
2280 /* unless an allocation function is declared with an empty excep-
2281 tion-specification (_except.spec_), throw(), it indicates failure to
2282 allocate storage by throwing a bad_alloc exception (clause _except_,
2283 _lib.bad.alloc_); it returns a non-null pointer otherwise If the allo-
2284 cation function is declared with an empty exception-specification,
2285 throw(), it returns null to indicate failure to allocate storage and a
2286 non-null pointer otherwise.
2287
2288 So check for a null exception spec on the op new we just called. */
2289
2290 nothrow = 0;
2291 if (rval)
2292 {
2293 /* The CALL_EXPR. */
2294 tree t = TREE_OPERAND (rval, 0);
2295 /* The function. */
2296 t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
7f477e81 2297 nothrow = TYPE_NOTHROW_P (TREE_TYPE (t));
047f64a3 2298 }
743f140d 2299 check_new = (flag_check_new || nothrow) && ! use_java_new;
047f64a3 2300
2face519 2301 if ((check_new || flag_exceptions) && rval)
2bb14213 2302 {
2face519
JM
2303 alloc_expr = get_target_expr (rval);
2304 alloc_node = rval = TREE_OPERAND (alloc_expr, 0);
2bb14213 2305 }
b7484fbe
MS
2306 else
2307 alloc_expr = NULL_TREE;
d18c083e 2308
8d08fdba
MS
2309 /* if rval is NULL_TREE I don't have to allocate it, but are we totally
2310 sure we have some extra bytes in that case for the BI_header_size
2311 cookies? And how does that interact with the code below? (mrs) */
2312 /* Finish up some magic for new'ed arrays */
5156628f 2313 if (use_cookie && rval != NULL_TREE)
8d08fdba 2314 {
8d08fdba 2315 tree cookie, exp1;
a0d5fba7 2316 rval = convert (string_type_node, rval); /* for ptr arithmetic */
834c6dff
MM
2317 rval = save_expr (build_binary_op (PLUS_EXPR, rval, cookie_size));
2318 /* Store the number of bytes allocated so that we can know how
2319 many elements to destroy later. */
2320 if (flag_new_abi)
2321 {
2322 /* Under the new ABI, we use the last sizeof (size_t) bytes
2323 to store the number of elements. */
2324 cookie = build_indirect_ref (build (MINUS_EXPR,
2325 build_pointer_type (sizetype),
2326 rval,
2327 size_in_bytes (sizetype)),
2328 NULL_PTR);
2329 exp1 = build (MODIFY_EXPR, void_type_node, cookie, nelts);
2330 }
2331 else
2332 {
2333 cookie
2334 = build_indirect_ref (build (MINUS_EXPR,
2335 build_pointer_type (BI_header_type),
2336 rval, cookie_size), NULL_PTR);
2337 exp1 = build (MODIFY_EXPR, void_type_node,
2338 build_component_ref (cookie, nelts_identifier,
2339 NULL_TREE, 0),
2340 nelts);
2341 }
2342
2343 /* Build `(cookie = nelts, rval)' and use that as the complete
2344 expression. */
37c46b43 2345 rval = cp_convert (build_pointer_type (true_type), rval);
a0d5fba7 2346 rval = build_compound_expr
e1b3e07d 2347 (tree_cons (NULL_TREE, exp1,
051e6fd7 2348 build_tree_list (NULL_TREE, rval)));
8d08fdba
MS
2349 }
2350
8d08fdba
MS
2351 if (rval == error_mark_node)
2352 return error_mark_node;
8d08fdba
MS
2353
2354 /* Don't call any constructors or do any initialization. */
2355 if (init == void_type_node)
2356 goto done;
2357
8926095f 2358 if (TYPE_NEEDS_CONSTRUCTING (type) || init)
8d08fdba 2359 {
b19b4a78
MS
2360 if (! TYPE_NEEDS_CONSTRUCTING (type)
2361 && ! IS_AGGR_TYPE (type) && ! has_array)
8d08fdba 2362 {
01240200
MM
2363 /* We are processing something like `new int (10)', which
2364 means allocate an int, and initialize it with 10. */
8ccc31eb 2365 tree deref;
01240200 2366 tree deref_type;
8ccc31eb 2367
01240200
MM
2368 /* At present RVAL is a temporary variable, created to hold
2369 the value from the call to `operator new'. We transform
2370 it to (*RVAL = INIT, RVAL). */
8ccc31eb
MS
2371 rval = save_expr (rval);
2372 deref = build_indirect_ref (rval, NULL_PTR);
01240200
MM
2373
2374 /* Even for something like `new const int (10)' we must
2375 allow the expression to be non-const while we do the
2376 initialization. */
2377 deref_type = TREE_TYPE (deref);
91063b51 2378 if (CP_TYPE_CONST_P (deref_type))
01240200 2379 TREE_TYPE (deref)
91063b51
MM
2380 = cp_build_qualified_type (deref_type,
2381 CP_TYPE_QUALS (deref_type)
2382 & ~TYPE_QUAL_CONST);
8ccc31eb 2383 TREE_READONLY (deref) = 0;
8d08fdba 2384
8ccc31eb 2385 if (TREE_CHAIN (init) != NULL_TREE)
8251199e 2386 pedwarn ("initializer list being treated as compound expression");
7215f9a0
MS
2387 else if (TREE_CODE (init) == CONSTRUCTOR)
2388 {
8251199e 2389 pedwarn ("initializer list appears where operand should be used");
7215f9a0
MS
2390 init = TREE_OPERAND (init, 1);
2391 }
8ccc31eb
MS
2392 init = build_compound_expr (init);
2393
2394 init = convert_for_initialization (deref, type, init, LOOKUP_NORMAL,
2395 "new", NULL_TREE, 0);
8d08fdba 2396 rval = build (COMPOUND_EXPR, TREE_TYPE (rval),
8ccc31eb 2397 build_modify_expr (deref, NOP_EXPR, init),
8d08fdba 2398 rval);
e3417fcd 2399 TREE_NO_UNUSED_WARNING (rval) = 1;
8d08fdba 2400 TREE_SIDE_EFFECTS (rval) = 1;
8d08fdba 2401 }
8ccc31eb
MS
2402 else if (! has_array)
2403 {
2404 tree newrval;
2405 /* Constructors are never virtual. If it has an initialization, we
2406 need to complain if we aren't allowed to use the ctor that took
2407 that argument. */
2408 int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_COMPLAIN;
2409
2410 if (rval && TYPE_USES_VIRTUAL_BASECLASSES (true_type))
2411 {
e1b3e07d 2412 init = tree_cons (NULL_TREE, integer_one_node, init);
8ccc31eb
MS
2413 flags |= LOOKUP_HAS_IN_CHARGE;
2414 }
2415
743f140d
PB
2416 if (use_java_new)
2417 rval = save_expr (rval);
8ccc31eb
MS
2418 newrval = rval;
2419
2420 if (newrval && TREE_CODE (TREE_TYPE (newrval)) == POINTER_TYPE)
2421 newrval = build_indirect_ref (newrval, NULL_PTR);
2422
fc378698
MS
2423 newrval = build_method_call (newrval, ctor_identifier,
2424 init, TYPE_BINFO (true_type), flags);
8ccc31eb 2425
80170791
MS
2426 if (newrval == NULL_TREE || newrval == error_mark_node)
2427 return error_mark_node;
2428
743f140d
PB
2429 /* Java constructors compiled by jc1 do not return this. */
2430 if (use_java_new)
2431 newrval = build (COMPOUND_EXPR, TREE_TYPE (newrval),
2432 newrval, rval);
80170791
MS
2433 rval = newrval;
2434 TREE_HAS_CONSTRUCTOR (rval) = 1;
8ccc31eb 2435 }
6f80451c 2436 else
b3ab27f3
MM
2437 rval = (build_vec_init
2438 (NULL_TREE,
2439 save_expr (rval),
2440 build_binary_op (MINUS_EXPR, nelts, integer_one_node),
2441 init,
2442 /*from_array=*/0));
1f109f0f 2443
20c39572
JM
2444 /* If any part of the object initialization terminates by throwing an
2445 exception and a suitable deallocation function can be found, the
2446 deallocation function is called to free the memory in which the
2447 object was being constructed, after which the exception continues
2448 to propagate in the context of the new-expression. If no
2449 unambiguous matching deallocation function can be found,
2450 propagating the exception does not cause the object's memory to be
2451 freed. */
743f140d 2452 if (flag_exceptions && alloc_expr && ! use_java_new)
1f109f0f 2453 {
2face519 2454 enum tree_code dcode = has_array ? VEC_DELETE_EXPR : DELETE_EXPR;
519ebd1e 2455 tree cleanup, fn = NULL_TREE;
834c6dff
MM
2456 int flags = (LOOKUP_NORMAL
2457 | (globally_qualified_p * LOOKUP_GLOBAL));
a7d87521 2458
5355deec
AO
2459 /* The Standard is unclear here, but the right thing to do
2460 is to use the same method for finding deallocation
2461 functions that we use for finding allocation functions. */
2462 flags |= LOOKUP_SPECULATIVELY;
2463
2464 /* We expect alloc_expr to look like a TARGET_EXPR around
2465 a NOP_EXPR around the CALL_EXPR we want. */
2466 fn = TREE_OPERAND (alloc_expr, 1);
2467 fn = TREE_OPERAND (fn, 0);
da4768fe 2468
519ebd1e 2469 cleanup = build_op_delete_call (dcode, alloc_node, size, flags, fn);
2bb14213 2470
2face519
JM
2471 /* Ack! First we allocate the memory. Then we set our sentry
2472 variable to true, and expand a cleanup that deletes the memory
2473 if sentry is true. Then we run the constructor and store the
2474 returned pointer in buf. Then we clear sentry and return buf. */
2475
da4768fe
JM
2476 if (cleanup)
2477 {
2face519
JM
2478 tree end, sentry, begin, buf, t = TREE_TYPE (rval);
2479
2480 begin = get_target_expr (boolean_true_node);
2481 sentry = TREE_OPERAND (begin, 0);
2482
2face519
JM
2483 TREE_OPERAND (begin, 2)
2484 = build (COND_EXPR, void_type_node, sentry,
2485 cleanup, void_zero_node);
2face519
JM
2486
2487 rval = get_target_expr (rval);
2488
2489 end = build (MODIFY_EXPR, TREE_TYPE (sentry),
2490 sentry, boolean_false_node);
2face519
JM
2491
2492 buf = TREE_OPERAND (rval, 0);
2493
2494 rval = build (COMPOUND_EXPR, t, begin,
2495 build (COMPOUND_EXPR, t, rval,
2496 build (COMPOUND_EXPR, t, end, buf)));
da4768fe 2497 }
1f109f0f 2498 }
8d08fdba 2499 }
91063b51 2500 else if (CP_TYPE_CONST_P (true_type))
8251199e 2501 cp_error ("uninitialized const in `new' of `%#T'", true_type);
8ccc31eb 2502
8d08fdba 2503 done:
d18c083e 2504
2face519
JM
2505 if (alloc_expr && rval == alloc_node)
2506 {
2507 rval = TREE_OPERAND (alloc_expr, 1);
2508 alloc_expr = NULL_TREE;
2509 }
2510
2511 if (check_new && alloc_expr)
d18c083e 2512 {
b7484fbe 2513 /* Did we modify the storage? */
2face519 2514 tree ifexp = build_binary_op (NE_EXPR, alloc_node,
337c90cc 2515 integer_zero_node);
2face519 2516 rval = build_conditional_expr (ifexp, rval, alloc_node);
d18c083e
MS
2517 }
2518
2face519
JM
2519 if (alloc_expr)
2520 rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
2521
51c184be
MS
2522 if (rval && TREE_TYPE (rval) != build_pointer_type (type))
2523 {
2524 /* The type of new int [3][3] is not int *, but int [3] * */
faf5394a 2525 rval = build_c_cast (build_pointer_type (type), rval);
51c184be
MS
2526 }
2527
00595019 2528 return rval;
8d08fdba
MS
2529}
2530\f
f30432d7 2531static tree
c7edeea3 2532build_vec_delete_1 (base, maxindex, type, auto_delete_vec, use_global_delete)
f30432d7 2533 tree base, maxindex, type;
c7edeea3 2534 tree auto_delete_vec;
f30432d7
MS
2535 int use_global_delete;
2536{
2537 tree virtual_size;
e92cc029 2538 tree ptype = build_pointer_type (type = complete_type (type));
f30432d7
MS
2539 tree size_exp = size_in_bytes (type);
2540
2541 /* Temporary variables used by the loop. */
2542 tree tbase, tbase_init;
2543
2544 /* This is the body of the loop that implements the deletion of a
2545 single element, and moves temp variables to next elements. */
2546 tree body;
2547
2548 /* This is the LOOP_EXPR that governs the deletion of the elements. */
2549 tree loop;
2550
2551 /* This is the thing that governs what to do after the loop has run. */
2552 tree deallocate_expr = 0;
2553
2554 /* This is the BIND_EXPR which holds the outermost iterator of the
2555 loop. It is convenient to set this variable up and test it before
2556 executing any other code in the loop.
2557 This is also the containing expression returned by this function. */
2558 tree controller = NULL_TREE;
2559
834c6dff 2560 if (! IS_AGGR_TYPE (type) || TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
f30432d7
MS
2561 {
2562 loop = integer_zero_node;
2563 goto no_destructor;
2564 }
2565
2566 /* The below is short by BI_header_size */
fed3cef0
RK
2567 virtual_size = size_binop (MULT_EXPR, size_exp,
2568 convert (sizetype, maxindex));
f30432d7 2569
46e8c075 2570 tbase = create_temporary_var (ptype);
f30432d7
MS
2571 tbase_init = build_modify_expr (tbase, NOP_EXPR,
2572 fold (build (PLUS_EXPR, ptype,
2573 base,
2574 virtual_size)));
2575 DECL_REGISTER (tbase) = 1;
4dabb379 2576 controller = build (BIND_EXPR, void_type_node, tbase, NULL_TREE, NULL_TREE);
f30432d7 2577 TREE_SIDE_EFFECTS (controller) = 1;
f30432d7 2578
c7edeea3 2579 body = NULL_TREE;
f30432d7 2580
e1b3e07d 2581 body = tree_cons (NULL_TREE,
c7edeea3 2582 build_delete (ptype, tbase, integer_two_node,
f30432d7
MS
2583 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1),
2584 body);
2585
e1b3e07d 2586 body = tree_cons (NULL_TREE,
f30432d7
MS
2587 build_modify_expr (tbase, NOP_EXPR, build (MINUS_EXPR, ptype, tbase, size_exp)),
2588 body);
2589
e1b3e07d 2590 body = tree_cons (NULL_TREE,
f30432d7
MS
2591 build (EXIT_EXPR, void_type_node,
2592 build (EQ_EXPR, boolean_type_node, base, tbase)),
2593 body);
2594
2595 loop = build (LOOP_EXPR, void_type_node, build_compound_expr (body));
2596
e1b3e07d
MM
2597 loop = tree_cons (NULL_TREE, tbase_init,
2598 tree_cons (NULL_TREE, loop, NULL_TREE));
f30432d7
MS
2599 loop = build_compound_expr (loop);
2600
2601 no_destructor:
2602 /* If the delete flag is one, or anything else with the low bit set,
2603 delete the storage. */
8a72a046 2604 if (auto_delete_vec == integer_zero_node)
f30432d7
MS
2605 deallocate_expr = integer_zero_node;
2606 else
2607 {
2608 tree base_tbd;
2609
2610 /* The below is short by BI_header_size */
fed3cef0
RK
2611 virtual_size = size_binop (MULT_EXPR, size_exp,
2612 convert (sizetype, maxindex));
f30432d7
MS
2613
2614 if (! TYPE_VEC_NEW_USES_COOKIE (type))
2615 /* no header */
2616 base_tbd = base;
2617 else
2618 {
834c6dff
MM
2619 tree cookie_size;
2620
2621 cookie_size = get_cookie_size (type);
2622 base_tbd
2623 = cp_convert (ptype,
2624 build_binary_op (MINUS_EXPR,
2625 cp_convert (string_type_node, base),
2626 cookie_size));
e92cc029 2627 /* True size with header. */
834c6dff 2628 virtual_size = size_binop (PLUS_EXPR, virtual_size, cookie_size);
f30432d7 2629 }
b370501f 2630 deallocate_expr = build_x_delete (base_tbd,
f30432d7
MS
2631 2 | use_global_delete,
2632 virtual_size);
37f88e3e
JM
2633 deallocate_expr = fold (build (COND_EXPR, void_type_node,
2634 fold (build (BIT_AND_EXPR,
2635 integer_type_node,
2636 auto_delete_vec,
2637 integer_one_node)),
2638 deallocate_expr, integer_zero_node));
f30432d7
MS
2639 }
2640
2641 if (loop && deallocate_expr != integer_zero_node)
2642 {
e1b3e07d
MM
2643 body = tree_cons (NULL_TREE, loop,
2644 tree_cons (NULL_TREE, deallocate_expr, NULL_TREE));
f30432d7
MS
2645 body = build_compound_expr (body);
2646 }
2647 else
2648 body = loop;
2649
2650 /* Outermost wrapper: If pointer is null, punt. */
37f88e3e
JM
2651 body = fold (build (COND_EXPR, void_type_node,
2652 fold (build (NE_EXPR, boolean_type_node, base,
2653 integer_zero_node)),
2654 body, integer_zero_node));
f30432d7
MS
2655 body = build1 (NOP_EXPR, void_type_node, body);
2656
2657 if (controller)
2658 {
2659 TREE_OPERAND (controller, 1) = body;
2660 return controller;
2661 }
2662 else
37c46b43 2663 return cp_convert (void_type_node, body);
f30432d7
MS
2664}
2665
f1dedc31
MM
2666tree
2667create_temporary_var (type)
8a72a046
MM
2668 tree type;
2669{
f1dedc31
MM
2670 tree decl;
2671
2672 decl = build_decl (VAR_DECL, NULL_TREE, type);
2673 TREE_USED (decl) = 1;
2674 DECL_ARTIFICIAL (decl) = 1;
2675 DECL_SOURCE_FILE (decl) = input_filename;
2676 DECL_SOURCE_LINE (decl) = lineno;
2677 DECL_IGNORED_P (decl) = 1;
b35d4555 2678 DECL_CONTEXT (decl) = current_function_decl;
f1dedc31 2679
f1dedc31 2680 return decl;
8a72a046
MM
2681}
2682
f1dedc31
MM
2683/* Create a new temporary variable of the indicated TYPE, initialized
2684 to INIT.
8a72a046 2685
f1dedc31
MM
2686 It is not entered into current_binding_level, because that breaks
2687 things when it comes time to do final cleanups (which take place
2688 "outside" the binding contour of the function). */
2689
2690static tree
2691get_temp_regvar (type, init)
2692 tree type, init;
f30432d7 2693{
f1dedc31 2694 tree decl;
8a72a046 2695
f1dedc31 2696 decl = create_temporary_var (type);
24bef158
MM
2697 if (building_stmt_tree ())
2698 add_decl_stmt (decl);
b7b8bcd2
MM
2699 if (!building_stmt_tree ())
2700 DECL_RTL (decl) = assign_temp (type, 2, 0, 1);
f1dedc31 2701 finish_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
8a72a046 2702
f1dedc31 2703 return decl;
f30432d7
MS
2704}
2705
f1dedc31
MM
2706/* `build_vec_init' returns tree structure that performs
2707 initialization of a vector of aggregate types.
8d08fdba
MS
2708
2709 DECL is passed only for error reporting, and provides line number
2710 and source file name information.
f1dedc31
MM
2711 BASE is the space where the vector will be. For a vector of Ts,
2712 the type of BASE is `T*'.
8d08fdba
MS
2713 MAXINDEX is the maximum index of the array (one less than the
2714 number of elements).
2715 INIT is the (possibly NULL) initializer.
2716
2717 FROM_ARRAY is 0 if we should init everything with INIT
2718 (i.e., every element initialized from INIT).
2719 FROM_ARRAY is 1 if we should index into INIT in parallel
2720 with initialization of DECL.
2721 FROM_ARRAY is 2 if we should index into INIT in parallel,
2722 but use assignment instead of initialization. */
2723
2724tree
f1dedc31 2725build_vec_init (decl, base, maxindex, init, from_array)
8d08fdba
MS
2726 tree decl, base, maxindex, init;
2727 int from_array;
2728{
2729 tree rval;
8a72a046 2730 tree base2 = NULL_TREE;
8d08fdba 2731 tree size;
e833cb11 2732 tree itype = NULL_TREE;
8a72a046 2733 tree iterator;
f1dedc31
MM
2734 /* The type of an element in the array. */
2735 tree type;
2736 /* The type of a pointer to an element in the array. */
2737 tree ptype;
2738 tree stmt_expr;
2739 tree compound_stmt;
2740 int destroy_temps;
f5984164 2741 tree try_block = NULL_TREE;
486837a7 2742 tree try_body = NULL_TREE;
8a72a046 2743 int num_initialized_elts = 0;
8d08fdba 2744
37c46b43 2745 maxindex = cp_convert (ptrdiff_type_node, maxindex);
8d08fdba
MS
2746 if (maxindex == error_mark_node)
2747 return error_mark_node;
2748
f1dedc31
MM
2749 type = TREE_TYPE (TREE_TYPE (base));
2750 ptype = build_pointer_type (type);
8d08fdba
MS
2751 size = size_in_bytes (type);
2752
f1dedc31
MM
2753 /* The code we are generating looks like:
2754
2755 T* t1 = (T*) base;
2756 T* rval = base;
2757 ptrdiff_t iterator = maxindex;
2758 try {
2759 ... initializations from CONSTRUCTOR ...
2760 if (iterator != -1) {
2761 do {
2762 ... initialize *base ...
2763 ++base;
2764 } while (--iterator != -1);
2765 }
2766 } catch (...) {
2767 ... destroy elements that were constructed ...
2768 }
2769
2770 We can omit the try and catch blocks if we know that the
2771 initialization will never throw an exception, or if the array
2772 elements do not have destructors. If we have a CONSTRUCTOR to
2773 give us initialization information, we emit code to initialize
2774 each of the elements before the loop in the try block, and then
2775 iterate over fewer elements. We can omit the loop completely if
2776 the elements of the array do not have constructors.
2777
2778 We actually wrap the entire body of the above in a STMT_EXPR, for
2779 tidiness.
2780
2781 When copying from array to another, when the array elements have
2782 only trivial copy constructors, we should use __builtin_memcpy
2783 rather than generating a loop. That way, we could take advantage
2784 of whatever cleverness the back-end has for dealing with copies
2785 of blocks of memory. */
2786
2787 begin_init_stmts (&stmt_expr, &compound_stmt);
2788 destroy_temps = stmts_are_full_exprs_p;
2789 stmts_are_full_exprs_p = 0;
2790 rval = get_temp_regvar (ptype,
2791 cp_convert (ptype, default_conversion (base)));
2792 base = get_temp_regvar (ptype, rval);
8a72a046 2793 iterator = get_temp_regvar (ptrdiff_type_node, maxindex);
8d08fdba 2794
8a72a046
MM
2795 /* Protect the entire array initialization so that we can destroy
2796 the partially constructed array if an exception is thrown. */
834c6dff 2797 if (flag_exceptions && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
ed5511d9
MM
2798 {
2799 try_block = begin_try_block ();
2800 try_body = begin_compound_stmt (/*has_no_scope=*/1);
2801 }
8a72a046
MM
2802
2803 if (init != NULL_TREE && TREE_CODE (init) == CONSTRUCTOR
3bfdc719 2804 && (!decl || same_type_p (TREE_TYPE (init), TREE_TYPE (decl))))
8d08fdba 2805 {
8a72a046
MM
2806 /* Do non-default initialization resulting from brace-enclosed
2807 initializers. */
2808
2809 tree elts;
094fe153
JM
2810 from_array = 0;
2811
8a72a046 2812 for (elts = CONSTRUCTOR_ELTS (init); elts; elts = TREE_CHAIN (elts))
8d08fdba 2813 {
8a72a046 2814 tree elt = TREE_VALUE (elts);
f1dedc31 2815 tree baseref = build1 (INDIRECT_REF, type, base);
8d08fdba 2816
8a72a046 2817 num_initialized_elts++;
8d08fdba 2818
8a72a046 2819 if (IS_AGGR_TYPE (type) || TREE_CODE (type) == ARRAY_TYPE)
f1dedc31 2820 finish_expr_stmt (build_aggr_init (baseref, elt, 0));
8a72a046 2821 else
f1dedc31
MM
2822 finish_expr_stmt (build_modify_expr (baseref, NOP_EXPR,
2823 elt));
8a72a046 2824
f1dedc31
MM
2825 finish_expr_stmt (build_modify_expr
2826 (base,
2827 NOP_EXPR,
8a72a046 2828 build (PLUS_EXPR, build_pointer_type (type),
f1dedc31
MM
2829 base, size)));
2830 finish_expr_stmt (build_modify_expr
2831 (iterator,
2832 NOP_EXPR,
8a72a046 2833 build (MINUS_EXPR, ptrdiff_type_node,
f1dedc31 2834 iterator, integer_one_node)));
8d08fdba 2835 }
8d08fdba 2836
8a72a046
MM
2837 /* Clear out INIT so that we don't get confused below. */
2838 init = NULL_TREE;
8d08fdba 2839 }
8a72a046 2840 else if (from_array)
8d08fdba 2841 {
8a72a046
MM
2842 /* If initializing one array from another, initialize element by
2843 element. We rely upon the below calls the do argument
2844 checking. */
2845 if (decl == NULL_TREE)
8d08fdba 2846 {
8a72a046
MM
2847 sorry ("initialization of array from dissimilar array type");
2848 return error_mark_node;
8d08fdba 2849 }
8a72a046
MM
2850 if (init)
2851 {
2852 base2 = default_conversion (init);
2853 itype = TREE_TYPE (base2);
2854 base2 = get_temp_regvar (itype, base2);
2855 itype = TREE_TYPE (itype);
2856 }
2857 else if (TYPE_LANG_SPECIFIC (type)
2858 && TYPE_NEEDS_CONSTRUCTING (type)
2859 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
2860 {
2861 error ("initializer ends prematurely");
2862 return error_mark_node;
2863 }
2864 }
8d08fdba 2865
8a72a046
MM
2866 /* Now, default-initialize any remaining elements. We don't need to
2867 do that if a) the type does not need constructing, or b) we've
094fe153
JM
2868 already initialized all the elements.
2869
2870 We do need to keep going if we're copying an array. */
2871
2872 if (from_array
2873 || (TYPE_NEEDS_CONSTRUCTING (type)
665f2503 2874 && ! (host_integerp (maxindex, 0)
05bccae2 2875 && (num_initialized_elts
665f2503 2876 == tree_low_cst (maxindex, 0) + 1))))
8a72a046 2877 {
37e05cd5 2878 /* If the ITERATOR is equal to -1, then we don't have to loop;
8a72a046 2879 we've already initialized all the elements. */
f1dedc31
MM
2880 tree if_stmt;
2881 tree do_stmt;
2882 tree do_body;
2883 tree elt_init;
2884
2885 if_stmt = begin_if_stmt ();
2886 finish_if_stmt_cond (build (NE_EXPR, boolean_type_node,
9cd64686 2887 iterator, minus_one_node),
f1dedc31 2888 if_stmt);
8d08fdba 2889
8a72a046 2890 /* Otherwise, loop through the elements. */
f1dedc31
MM
2891 do_stmt = begin_do_stmt ();
2892 do_body = begin_compound_stmt (/*has_no_scope=*/1);
2893
2894 /* When we're not building a statement-tree, things are a little
2895 complicated. If, when we recursively call build_aggr_init,
2896 an expression containing a TARGET_EXPR is expanded, then it
2897 may get a cleanup. Then, the result of that expression is
2898 passed to finish_expr_stmt, which will call
2899 expand_start_target_temps/expand_end_target_temps. However,
2900 the latter call will not cause the cleanup to run because
2901 that block will still be on the block stack. So, we call
2902 expand_start_target_temps here manually; the corresponding
2903 call to expand_end_target_temps below will cause the cleanup
2904 to be performed. */
2905 if (!building_stmt_tree ())
2906 expand_start_target_temps ();
0fac6b0b 2907
8d08fdba
MS
2908 if (from_array)
2909 {
2910 tree to = build1 (INDIRECT_REF, type, base);
2911 tree from;
2912
2913 if (base2)
2914 from = build1 (INDIRECT_REF, itype, base2);
2915 else
2916 from = NULL_TREE;
2917
2918 if (from_array == 2)
f1dedc31 2919 elt_init = build_modify_expr (to, NOP_EXPR, from);
8d08fdba 2920 else if (TYPE_NEEDS_CONSTRUCTING (type))
f1dedc31 2921 elt_init = build_aggr_init (to, from, 0);
8d08fdba 2922 else if (from)
f1dedc31 2923 elt_init = build_modify_expr (to, NOP_EXPR, from);
8d08fdba
MS
2924 else
2925 my_friendly_abort (57);
2926 }
2927 else if (TREE_CODE (type) == ARRAY_TYPE)
2928 {
2929 if (init != 0)
2930 sorry ("cannot initialize multi-dimensional array with initializer");
f1dedc31
MM
2931 elt_init = (build_vec_init
2932 (decl,
2933 build1 (NOP_EXPR,
2934 build_pointer_type (TREE_TYPE (type)),
2935 base),
2936 array_type_nelts (type), 0, 0));
2937 }
2938 else
2939 elt_init = build_aggr_init (build1 (INDIRECT_REF, type, base),
2940 init, 0);
2941
2942 /* The initialization of each array element is a
2943 full-expression. */
2944 if (!building_stmt_tree ())
2945 {
2946 finish_expr_stmt (elt_init);
2947 expand_end_target_temps ();
8d08fdba
MS
2948 }
2949 else
f1dedc31
MM
2950 {
2951 stmts_are_full_exprs_p = 1;
2952 finish_expr_stmt (elt_init);
2953 stmts_are_full_exprs_p = 0;
2954 }
8d08fdba 2955
f1dedc31
MM
2956 finish_expr_stmt (build_modify_expr
2957 (base,
2958 NOP_EXPR,
8a72a046 2959 build (PLUS_EXPR, build_pointer_type (type),
f1dedc31 2960 base, size)));
8d08fdba 2961 if (base2)
f1dedc31
MM
2962 finish_expr_stmt (build_modify_expr
2963 (base2,
2964 NOP_EXPR,
8a72a046 2965 build (PLUS_EXPR, build_pointer_type (type),
f1dedc31 2966 base2, size)));
0fac6b0b 2967
f1dedc31
MM
2968 finish_compound_stmt (/*has_no_scope=*/1, do_body);
2969 finish_do_body (do_stmt);
2970 finish_do_stmt (build (NE_EXPR, boolean_type_node,
2971 build (PREDECREMENT_EXPR,
2972 ptrdiff_type_node,
2973 iterator,
2974 integer_one_node),
9cd64686 2975 minus_one_node),
f1dedc31
MM
2976 do_stmt);
2977
2978 finish_then_clause (if_stmt);
2979 finish_if_stmt ();
8d08fdba 2980 }
8a72a046
MM
2981
2982 /* Make sure to cleanup any partially constructed elements. */
834c6dff 2983 if (flag_exceptions && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
f1dedc31
MM
2984 {
2985 tree e;
8d08fdba 2986
ed5511d9
MM
2987 finish_compound_stmt (/*has_no_scope=*/1, try_body);
2988 finish_cleanup_try_block (try_block);
f1dedc31
MM
2989 e = build_vec_delete_1 (rval,
2990 build_binary_op (MINUS_EXPR, maxindex,
2991 iterator),
2992 type,
2993 /*auto_delete_vec=*/integer_zero_node,
f1dedc31 2994 /*use_global_delete=*/0);
f1dedc31
MM
2995 finish_cleanup (e, try_block);
2996 }
2997
f1dedc31
MM
2998 /* The value of the array initialization is the address of the
2999 first element in the array. */
3000 finish_expr_stmt (rval);
3001
3002 stmt_expr = finish_init_stmts (stmt_expr, compound_stmt);
3003 stmts_are_full_exprs_p = destroy_temps;
3004 return stmt_expr;
8d08fdba
MS
3005}
3006
3007/* Free up storage of type TYPE, at address ADDR.
3008
3009 TYPE is a POINTER_TYPE and can be ptr_type_node for no special type
3010 of pointer.
3011
3012 VIRTUAL_SIZE is the amount of storage that was allocated, and is
3013 used as the second argument to operator delete. It can include
3014 things like padding and magic size cookies. It has virtual in it,
3015 because if you have a base pointer and you delete through a virtual
3016 destructor, it should be the size of the dynamic object, not the
cab1f180 3017 static object, see Free Store 12.5 ISO C++.
8d08fdba
MS
3018
3019 This does not call any destructors. */
e92cc029 3020
8d08fdba 3021tree
b370501f
KG
3022build_x_delete (addr, which_delete, virtual_size)
3023 tree addr;
a28e3c7f 3024 int which_delete;
8d08fdba
MS
3025 tree virtual_size;
3026{
a28e3c7f
MS
3027 int use_global_delete = which_delete & 1;
3028 int use_vec_delete = !!(which_delete & 2);
a28e3c7f 3029 enum tree_code code = use_vec_delete ? VEC_DELETE_EXPR : DELETE_EXPR;
da4768fe 3030 int flags = LOOKUP_NORMAL | (use_global_delete * LOOKUP_GLOBAL);
8d08fdba 3031
519ebd1e 3032 return build_op_delete_call (code, addr, virtual_size, flags, NULL_TREE);
8d08fdba
MS
3033}
3034
3035/* Generate a call to a destructor. TYPE is the type to cast ADDR to.
3036 ADDR is an expression which yields the store to be destroyed.
3037 AUTO_DELETE is nonzero if a call to DELETE should be made or not.
3038 If in the program, (AUTO_DELETE & 2) is non-zero, we tear down the
3039 virtual baseclasses.
3040 If in the program, (AUTO_DELETE & 1) is non-zero, then we deallocate.
3041
3042 FLAGS is the logical disjunction of zero or more LOOKUP_
3043 flags. See cp-tree.h for more info.
3044
3045 This function does not delete an object's virtual base classes. */
e92cc029 3046
8d08fdba
MS
3047tree
3048build_delete (type, addr, auto_delete, flags, use_global_delete)
3049 tree type, addr;
3050 tree auto_delete;
3051 int flags;
3052 int use_global_delete;
3053{
8d08fdba
MS
3054 tree member;
3055 tree expr;
3056 tree ref;
8d08fdba
MS
3057
3058 if (addr == error_mark_node)
3059 return error_mark_node;
3060
3061 /* Can happen when CURRENT_EXCEPTION_OBJECT gets its type
3062 set to `error_mark_node' before it gets properly cleaned up. */
3063 if (type == error_mark_node)
3064 return error_mark_node;
3065
3066 type = TYPE_MAIN_VARIANT (type);
3067
3068 if (TREE_CODE (type) == POINTER_TYPE)
3069 {
2986ae00 3070 type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
66543169 3071 if (type != void_type_node && !complete_type_or_else (type, addr))
8f259df3 3072 return error_mark_node;
8d08fdba
MS
3073 if (TREE_CODE (type) == ARRAY_TYPE)
3074 goto handle_array;
3075 if (! IS_AGGR_TYPE (type))
3076 {
3077 /* Call the builtin operator delete. */
c787dd82 3078 return build_builtin_delete_call (addr);
8d08fdba
MS
3079 }
3080 if (TREE_SIDE_EFFECTS (addr))
3081 addr = save_expr (addr);
2986ae00
MS
3082
3083 /* throw away const and volatile on target type of addr */
6060a796 3084 addr = convert_force (build_pointer_type (type), addr, 0);
8d08fdba 3085 ref = build_indirect_ref (addr, NULL_PTR);
8d08fdba
MS
3086 }
3087 else if (TREE_CODE (type) == ARRAY_TYPE)
3088 {
3089 handle_array:
3090 if (TREE_SIDE_EFFECTS (addr))
3091 addr = save_expr (addr);
c407792d
RK
3092 if (TYPE_DOMAIN (type) == NULL_TREE)
3093 {
8251199e 3094 error ("unknown array size in delete");
c407792d
RK
3095 return error_mark_node;
3096 }
8d08fdba 3097 return build_vec_delete (addr, array_type_nelts (type),
c7edeea3 3098 auto_delete, use_global_delete);
8d08fdba
MS
3099 }
3100 else
3101 {
3102 /* Don't check PROTECT here; leave that decision to the
3103 destructor. If the destructor is accessible, call it,
3104 else report error. */
3105 addr = build_unary_op (ADDR_EXPR, addr, 0);
3106 if (TREE_SIDE_EFFECTS (addr))
3107 addr = save_expr (addr);
3108
3109 if (TREE_CONSTANT (addr))
3110 addr = convert_pointer_to (type, addr);
3111 else
6060a796 3112 addr = convert_force (build_pointer_type (type), addr, 0);
8d08fdba 3113
bd6dd845 3114 ref = build_indirect_ref (addr, NULL_PTR);
8d08fdba
MS
3115 }
3116
3117 my_friendly_assert (IS_AGGR_TYPE (type), 220);
3118
834c6dff 3119 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
8d08fdba 3120 {
8d08fdba
MS
3121 if (auto_delete == integer_zero_node)
3122 return void_zero_node;
3123
da4768fe
JM
3124 return build_op_delete_call
3125 (DELETE_EXPR, addr, c_sizeof_nowarn (type),
519ebd1e
JM
3126 LOOKUP_NORMAL | (use_global_delete * LOOKUP_GLOBAL),
3127 NULL_TREE);
8d08fdba 3128 }
8d08fdba
MS
3129
3130 /* Below, we will reverse the order in which these calls are made.
3131 If we have a destructor, then that destructor will take care
3132 of the base classes; otherwise, we must do that here. */
3133 if (TYPE_HAS_DESTRUCTOR (type))
3134 {
700f8a87
MS
3135 tree passed_auto_delete;
3136 tree do_delete = NULL_TREE;
bd6dd845 3137 tree ifexp;
700f8a87
MS
3138
3139 if (use_global_delete)
3140 {
3141 tree cond = fold (build (BIT_AND_EXPR, integer_type_node,
3142 auto_delete, integer_one_node));
c787dd82 3143 tree call = build_builtin_delete_call (addr);
700f8a87
MS
3144
3145 cond = fold (build (COND_EXPR, void_type_node, cond,
3146 call, void_zero_node));
3147 if (cond != void_zero_node)
3148 do_delete = cond;
3149
3150 passed_auto_delete = fold (build (BIT_AND_EXPR, integer_type_node,
3151 auto_delete, integer_two_node));
3152 }
3153 else
863adfc0 3154 passed_auto_delete = auto_delete;
8d08fdba 3155
bd6dd845 3156 expr = build_method_call
051e6fd7 3157 (ref, dtor_identifier, build_tree_list (NULL_TREE, passed_auto_delete),
bd6dd845 3158 NULL_TREE, flags);
8d08fdba 3159
bd6dd845
MS
3160 if (do_delete)
3161 expr = build (COMPOUND_EXPR, void_type_node, expr, do_delete);
9e9ff709 3162
bd6dd845
MS
3163 if (flags & LOOKUP_DESTRUCTOR)
3164 /* Explicit destructor call; don't check for null pointer. */
3165 ifexp = integer_one_node;
8d08fdba 3166 else
bd6dd845 3167 /* Handle deleting a null pointer. */
337c90cc 3168 ifexp = fold (build_binary_op (NE_EXPR, addr, integer_zero_node));
8d08fdba 3169
bd6dd845
MS
3170 if (ifexp != integer_one_node)
3171 expr = build (COND_EXPR, void_type_node,
3172 ifexp, expr, void_zero_node);
8d08fdba 3173
8d08fdba
MS
3174 return expr;
3175 }
3176 else
3177 {
bd6dd845 3178 /* We only get here from finish_function for a destructor. */
8d08fdba 3179 tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
d43829f9 3180 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (type);
8d08fdba
MS
3181 tree base_binfo = n_baseclasses > 0 ? TREE_VEC_ELT (binfos, 0) : NULL_TREE;
3182 tree exprstmt = NULL_TREE;
3183 tree parent_auto_delete = auto_delete;
3184 tree cond;
3185
2a2480e1
JM
3186 /* Set this again before we call anything, as we might get called
3187 recursively. */
3188 TYPE_HAS_DESTRUCTOR (type) = 1;
3189
bd6dd845
MS
3190 /* If we have member delete or vbases, we call delete in
3191 finish_function. */
3192 if (auto_delete == integer_zero_node)
3193 cond = NULL_TREE;
8d08fdba 3194 else if (base_binfo == NULL_TREE
834c6dff 3195 || TYPE_HAS_TRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo)))
8d08fdba 3196 {
8d08fdba
MS
3197 cond = build (COND_EXPR, void_type_node,
3198 build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node),
c787dd82 3199 build_builtin_delete_call (addr),
8d08fdba
MS
3200 void_zero_node);
3201 }
3202 else
3203 cond = NULL_TREE;
3204
3205 if (cond)
051e6fd7 3206 exprstmt = build_tree_list (NULL_TREE, cond);
8d08fdba
MS
3207
3208 if (base_binfo
3209 && ! TREE_VIA_VIRTUAL (base_binfo)
834c6dff 3210 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo)))
8d08fdba
MS
3211 {
3212 tree this_auto_delete;
3213
3214 if (BINFO_OFFSET_ZEROP (base_binfo))
3215 this_auto_delete = parent_auto_delete;
3216 else
3217 this_auto_delete = integer_zero_node;
3218
bd6dd845
MS
3219 expr = build_scoped_method_call
3220 (ref, base_binfo, dtor_identifier,
051e6fd7 3221 build_tree_list (NULL_TREE, this_auto_delete));
e1b3e07d 3222 exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
8d08fdba
MS
3223 }
3224
3225 /* Take care of the remaining baseclasses. */
3226 for (i = 1; i < n_baseclasses; i++)
3227 {
3228 base_binfo = TREE_VEC_ELT (binfos, i);
834c6dff 3229 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))
8d08fdba
MS
3230 || TREE_VIA_VIRTUAL (base_binfo))
3231 continue;
3232
bd6dd845
MS
3233 expr = build_scoped_method_call
3234 (ref, base_binfo, dtor_identifier,
051e6fd7 3235 build_tree_list (NULL_TREE, integer_zero_node));
8d08fdba 3236
e1b3e07d 3237 exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
8d08fdba
MS
3238 }
3239
3240 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
3241 {
3242 if (TREE_CODE (member) != FIELD_DECL)
3243 continue;
834c6dff 3244 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (member)))
8d08fdba 3245 {
4dabb379 3246 tree this_member = build_component_ref (ref, DECL_NAME (member), NULL_TREE, 0);
8d08fdba
MS
3247 tree this_type = TREE_TYPE (member);
3248 expr = build_delete (this_type, this_member, integer_two_node, flags, 0);
e1b3e07d 3249 exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
8d08fdba
MS
3250 }
3251 }
3252
3253 if (exprstmt)
3254 return build_compound_expr (exprstmt);
3255 /* Virtual base classes make this function do nothing. */
3256 return void_zero_node;
3257 }
3258}
3259
3260/* For type TYPE, delete the virtual baseclass objects of DECL. */
3261
3262tree
3263build_vbase_delete (type, decl)
3264 tree type, decl;
3265{
3266 tree vbases = CLASSTYPE_VBASECLASSES (type);
3267 tree result = NULL_TREE;
3268 tree addr = build_unary_op (ADDR_EXPR, decl, 0);
3269
3270 my_friendly_assert (addr != error_mark_node, 222);
3271
3272 while (vbases)
3273 {
f30432d7 3274 tree this_addr = convert_force (build_pointer_type (BINFO_TYPE (vbases)),
6060a796 3275 addr, 0);
e1b3e07d 3276 result = tree_cons (NULL_TREE,
8d08fdba
MS
3277 build_delete (TREE_TYPE (this_addr), this_addr,
3278 integer_zero_node,
3279 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
3280 result);
3281 vbases = TREE_CHAIN (vbases);
3282 }
3283 return build_compound_expr (nreverse (result));
3284}
3285
3286/* Build a C++ vector delete expression.
3287 MAXINDEX is the number of elements to be deleted.
3288 ELT_SIZE is the nominal size of each element in the vector.
3289 BASE is the expression that should yield the store to be deleted.
8d08fdba
MS
3290 This function expands (or synthesizes) these calls itself.
3291 AUTO_DELETE_VEC says whether the container (vector) should be deallocated.
8d08fdba
MS
3292
3293 This also calls delete for virtual baseclasses of elements of the vector.
3294
3295 Update: MAXINDEX is no longer needed. The size can be extracted from the
3296 start of the vector for pointers, and from the type for arrays. We still
3297 use MAXINDEX for arrays because it happens to already have one of the
3298 values we'd have to extract. (We could use MAXINDEX with pointers to
3299 confirm the size, and trap if the numbers differ; not clear that it'd
3300 be worth bothering.) */
e92cc029 3301
8d08fdba 3302tree
c7edeea3 3303build_vec_delete (base, maxindex, auto_delete_vec, use_global_delete)
5566b478 3304 tree base, maxindex;
c7edeea3 3305 tree auto_delete_vec;
a28e3c7f 3306 int use_global_delete;
8d08fdba 3307{
f30432d7 3308 tree type;
8d08fdba 3309
c407792d
RK
3310 if (TREE_CODE (base) == OFFSET_REF)
3311 base = resolve_offset_ref (base);
3312
f30432d7 3313 type = TREE_TYPE (base);
c407792d 3314
8d08fdba
MS
3315 base = stabilize_reference (base);
3316
e92cc029 3317 /* Since we can use base many times, save_expr it. */
8d08fdba
MS
3318 if (TREE_SIDE_EFFECTS (base))
3319 base = save_expr (base);
3320
f30432d7 3321 if (TREE_CODE (type) == POINTER_TYPE)
8d08fdba
MS
3322 {
3323 /* Step back one from start of vector, and read dimension. */
834c6dff
MM
3324 tree cookie_addr;
3325
3326 if (flag_new_abi)
3327 {
3328 cookie_addr = build (MINUS_EXPR,
3329 build_pointer_type (sizetype),
3330 base,
3331 TYPE_SIZE_UNIT (sizetype));
3332 maxindex = build_indirect_ref (cookie_addr, NULL_PTR);
3333 }
3334 else
3335 {
3336 tree cookie;
3337
3338 cookie_addr = build (MINUS_EXPR, build_pointer_type (BI_header_type),
3339 base, BI_header_size);
3340 cookie = build_indirect_ref (cookie_addr, NULL_PTR);
3341 maxindex = build_component_ref (cookie, nelts_identifier,
3342 NULL_TREE, 0);
3343 }
3344
3345 type = strip_array_types (TREE_TYPE (type));
8d08fdba 3346 }
f30432d7 3347 else if (TREE_CODE (type) == ARRAY_TYPE)
8d08fdba
MS
3348 {
3349 /* get the total number of things in the array, maxindex is a bad name */
f30432d7 3350 maxindex = array_type_nelts_total (type);
834c6dff 3351 type = strip_array_types (type);
8d08fdba
MS
3352 base = build_unary_op (ADDR_EXPR, base, 1);
3353 }
3354 else
3355 {
9e9ff709 3356 if (base != error_mark_node)
8251199e 3357 error ("type to vector delete is neither pointer or array type");
8d08fdba
MS
3358 return error_mark_node;
3359 }
8d08fdba 3360
c7edeea3 3361 return build_vec_delete_1 (base, maxindex, type, auto_delete_vec,
f30432d7 3362 use_global_delete);
8d08fdba 3363}