./
[official-gcc.git] / gcc / cp / typeck2.c
blobdaa23993425d5259fddf73eaadcd0db2206a46f5
1 /* Report error messages, build initializers, and perform
2 some front-end optimizations for C++ compiler.
3 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2004, 2005
5 Free Software Foundation, Inc.
6 Hacked by Michael Tiemann (tiemann@cygnus.com)
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
26 /* This file is part of the C++ front end.
27 It contains routines to build C++ expressions given their operands,
28 including computing the types of the result, C and C++ specific error
29 checks, and some optimization. */
31 #include "config.h"
32 #include "system.h"
33 #include "coretypes.h"
34 #include "tm.h"
35 #include "tree.h"
36 #include "cp-tree.h"
37 #include "flags.h"
38 #include "toplev.h"
39 #include "output.h"
40 #include "diagnostic.h"
42 static tree process_init_constructor (tree, tree, tree *);
44 /* Print an error message stemming from an attempt to use
45 BASETYPE as a base class for TYPE. */
47 tree
48 error_not_base_type (tree basetype, tree type)
50 if (TREE_CODE (basetype) == FUNCTION_DECL)
51 basetype = DECL_CONTEXT (basetype);
52 error ("type %qT is not a base type for type %qT", basetype, type);
53 return error_mark_node;
56 tree
57 binfo_or_else (tree base, tree type)
59 tree binfo = lookup_base (type, base, ba_unique, NULL);
61 if (binfo == error_mark_node)
62 return NULL_TREE;
63 else if (!binfo)
64 error_not_base_type (base, type);
65 return binfo;
68 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
69 value may not be changed thereafter. Thus, we emit hard errors for these,
70 rather than just pedwarns. If `SOFT' is 1, then we just pedwarn. (For
71 example, conversions to references.) */
73 void
74 readonly_error (tree arg, const char* string, int soft)
76 const char *fmt;
77 void (*fn) (const char *, ...);
79 if (soft)
80 fn = pedwarn;
81 else
82 fn = error;
84 if (TREE_CODE (arg) == COMPONENT_REF)
86 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
87 fmt = "%s of data-member %qD in read-only structure";
88 else
89 fmt = "%s of read-only data-member %qD";
90 (*fn) (fmt, string, TREE_OPERAND (arg, 1));
92 else if (TREE_CODE (arg) == VAR_DECL)
94 if (DECL_LANG_SPECIFIC (arg)
95 && DECL_IN_AGGR_P (arg)
96 && !TREE_STATIC (arg))
97 fmt = "%s of constant field %qD";
98 else
99 fmt = "%s of read-only variable %qD";
100 (*fn) (fmt, string, arg);
102 else if (TREE_CODE (arg) == PARM_DECL)
103 (*fn) ("%s of read-only parameter %qD", string, arg);
104 else if (TREE_CODE (arg) == INDIRECT_REF
105 && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE
106 && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL
107 || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL))
108 (*fn) ("%s of read-only reference %qD", string, TREE_OPERAND (arg, 0));
109 else if (TREE_CODE (arg) == RESULT_DECL)
110 (*fn) ("%s of read-only named return value %qD", string, arg);
111 else if (TREE_CODE (arg) == FUNCTION_DECL)
112 (*fn) ("%s of function %qD", string, arg);
113 else
114 (*fn) ("%s of read-only location", string);
118 /* Structure that holds information about declarations whose type was
119 incomplete and we could not check whether it was abstract or not. */
121 struct pending_abstract_type GTY((chain_next ("%h.next")))
123 /* Declaration which we are checking for abstractness. It is either
124 a DECL node, or an IDENTIFIER_NODE if we do not have a full
125 declaration available. */
126 tree decl;
128 /* Type which will be checked for abstractness. */
129 tree type;
131 /* Position of the declaration. This is only needed for IDENTIFIER_NODEs,
132 because DECLs already carry locus information. */
133 location_t locus;
135 /* Link to the next element in list. */
136 struct pending_abstract_type* next;
140 /* Compute the hash value of the node VAL. This function is used by the
141 hash table abstract_pending_vars. */
143 static hashval_t
144 pat_calc_hash (const void* val)
146 const struct pending_abstract_type* pat = val;
147 return (hashval_t) TYPE_UID (pat->type);
151 /* Compare node VAL1 with the type VAL2. This function is used by the
152 hash table abstract_pending_vars. */
154 static int
155 pat_compare (const void* val1, const void* val2)
157 const struct pending_abstract_type* pat1 = val1;
158 tree type2 = (tree)val2;
160 return (pat1->type == type2);
163 /* Hash table that maintains pending_abstract_type nodes, for which we still
164 need to check for type abstractness. The key of the table is the type
165 of the declaration. */
166 static GTY ((param_is (struct pending_abstract_type)))
167 htab_t abstract_pending_vars = NULL;
170 /* This function is called after TYPE is completed, and will check if there
171 are pending declarations for which we still need to verify the abstractness
172 of TYPE, and emit a diagnostic (through abstract_virtuals_error) if TYPE
173 turned out to be incomplete. */
175 void
176 complete_type_check_abstract (tree type)
178 void **slot;
179 struct pending_abstract_type *pat;
180 location_t cur_loc = input_location;
182 gcc_assert (COMPLETE_TYPE_P (type));
184 if (!abstract_pending_vars)
185 return;
187 /* Retrieve the list of pending declarations for this type. */
188 slot = htab_find_slot_with_hash (abstract_pending_vars, type,
189 (hashval_t)TYPE_UID (type), NO_INSERT);
190 if (!slot)
191 return;
192 pat = (struct pending_abstract_type*)*slot;
193 gcc_assert (pat);
195 /* If the type is not abstract, do not do anything. */
196 if (CLASSTYPE_PURE_VIRTUALS (type))
198 struct pending_abstract_type *prev = 0, *next;
200 /* Reverse the list to emit the errors in top-down order. */
201 for (; pat; pat = next)
203 next = pat->next;
204 pat->next = prev;
205 prev = pat;
207 pat = prev;
209 /* Go through the list, and call abstract_virtuals_error for each
210 element: it will issue a diagnostic if the type is abstract. */
211 while (pat)
213 gcc_assert (type == pat->type);
215 /* Tweak input_location so that the diagnostic appears at the correct
216 location. Notice that this is only needed if the decl is an
217 IDENTIFIER_NODE, otherwise cp_error_at. */
218 input_location = pat->locus;
219 abstract_virtuals_error (pat->decl, pat->type);
220 pat = pat->next;
224 htab_clear_slot (abstract_pending_vars, slot);
226 input_location = cur_loc;
230 /* If TYPE has abstract virtual functions, issue an error about trying
231 to create an object of that type. DECL is the object declared, or
232 NULL_TREE if the declaration is unavailable. Returns 1 if an error
233 occurred; zero if all was well. */
236 abstract_virtuals_error (tree decl, tree type)
238 VEC (tree) *pure;
240 /* This function applies only to classes. Any other entity can never
241 be abstract. */
242 if (!CLASS_TYPE_P (type))
243 return 0;
245 /* If the type is incomplete, we register it within a hash table,
246 so that we can check again once it is completed. This makes sense
247 only for objects for which we have a declaration or at least a
248 name. */
249 if (!COMPLETE_TYPE_P (type))
251 void **slot;
252 struct pending_abstract_type *pat;
254 gcc_assert (!decl || DECL_P (decl)
255 || TREE_CODE (decl) == IDENTIFIER_NODE);
257 if (!abstract_pending_vars)
258 abstract_pending_vars = htab_create_ggc (31, &pat_calc_hash,
259 &pat_compare, NULL);
261 slot = htab_find_slot_with_hash (abstract_pending_vars, type,
262 (hashval_t)TYPE_UID (type), INSERT);
264 pat = GGC_NEW (struct pending_abstract_type);
265 pat->type = type;
266 pat->decl = decl;
267 pat->locus = ((decl && DECL_P (decl))
268 ? DECL_SOURCE_LOCATION (decl)
269 : input_location);
271 pat->next = *slot;
272 *slot = pat;
274 return 0;
277 if (!TYPE_SIZE (type))
278 /* TYPE is being defined, and during that time
279 CLASSTYPE_PURE_VIRTUALS holds the inline friends. */
280 return 0;
282 pure = CLASSTYPE_PURE_VIRTUALS (type);
283 if (!pure)
284 return 0;
286 if (decl)
288 if (TREE_CODE (decl) == RESULT_DECL)
289 return 0;
291 if (TREE_CODE (decl) == VAR_DECL)
292 cp_error_at ("cannot declare variable %q+D to be of abstract "
293 "type %qT", decl, type);
294 else if (TREE_CODE (decl) == PARM_DECL)
295 cp_error_at ("cannot declare parameter %q+D to be of abstract "
296 "type %qT", decl, type);
297 else if (TREE_CODE (decl) == FIELD_DECL)
298 cp_error_at ("cannot declare field %q+D to be of abstract "
299 "type %qT", decl, type);
300 else if (TREE_CODE (decl) == FUNCTION_DECL
301 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
302 cp_error_at ("invalid abstract return type for member function %q+#D",
303 decl);
304 else if (TREE_CODE (decl) == FUNCTION_DECL)
305 cp_error_at ("invalid abstract return type for function %q+#D",
306 decl);
307 else if (TREE_CODE (decl) == IDENTIFIER_NODE)
308 /* Here we do not have location information, so use error instead
309 of cp_error_at. */
310 error ("invalid abstract type %qT for %qE", type, decl);
311 else
312 cp_error_at ("invalid abstract type for %q+D", decl);
314 else
315 error ("cannot allocate an object of abstract type %qT", type);
317 /* Only go through this once. */
318 if (VEC_length (tree, pure))
320 unsigned ix;
321 tree fn;
323 inform ("%J because the following virtual functions are pure "
324 "within %qT:", TYPE_MAIN_DECL (type), type);
326 for (ix = 0; VEC_iterate (tree, pure, ix, fn); ix++)
327 inform ("%J\t%#D", fn, fn);
328 /* Now truncate the vector. This leaves it non-null, so we know
329 there are pure virtuals, but empty so we don't list them out
330 again. */
331 VEC_truncate (tree, pure, 0);
333 else
334 inform ("%J since type %qT has pure virtual functions",
335 TYPE_MAIN_DECL (type), type);
337 return 1;
340 /* Print an error message for invalid use of an incomplete type.
341 VALUE is the expression that was used (or 0 if that isn't known)
342 and TYPE is the type that was invalid. DIAG_TYPE indicates the
343 type of diagnostic: 0 for an error, 1 for a warning, 2 for a
344 pedwarn. */
346 void
347 cxx_incomplete_type_diagnostic (tree value, tree type, int diag_type)
349 int decl = 0;
350 void (*p_msg) (const char *, ...);
351 void (*p_msg_at) (const char *, ...);
353 if (diag_type == 1)
355 p_msg = warning;
356 p_msg_at = cp_warning_at;
358 else if (diag_type == 2)
360 p_msg = pedwarn;
361 p_msg_at = cp_pedwarn_at;
363 else
365 p_msg = error;
366 p_msg_at = cp_error_at;
369 /* Avoid duplicate error message. */
370 if (TREE_CODE (type) == ERROR_MARK)
371 return;
373 if (value != 0 && (TREE_CODE (value) == VAR_DECL
374 || TREE_CODE (value) == PARM_DECL
375 || TREE_CODE (value) == FIELD_DECL))
377 (*p_msg_at) ("%qD has incomplete type", value);
378 decl = 1;
380 retry:
381 /* We must print an error message. Be clever about what it says. */
383 switch (TREE_CODE (type))
385 case RECORD_TYPE:
386 case UNION_TYPE:
387 case ENUMERAL_TYPE:
388 if (!decl)
389 (*p_msg) ("invalid use of undefined type %q#T", type);
390 if (!TYPE_TEMPLATE_INFO (type))
391 (*p_msg_at) ("forward declaration of %q#T", type);
392 else
393 (*p_msg_at) ("declaration of %q#T", type);
394 break;
396 case VOID_TYPE:
397 (*p_msg) ("invalid use of %qT", type);
398 break;
400 case ARRAY_TYPE:
401 if (TYPE_DOMAIN (type))
403 type = TREE_TYPE (type);
404 goto retry;
406 (*p_msg) ("invalid use of array with unspecified bounds");
407 break;
409 case OFFSET_TYPE:
410 bad_member:
411 (*p_msg) ("invalid use of member (did you forget the %<&%> ?)");
412 break;
414 case TEMPLATE_TYPE_PARM:
415 (*p_msg) ("invalid use of template type parameter");
416 break;
418 case UNKNOWN_TYPE:
419 if (value && TREE_CODE (value) == COMPONENT_REF)
420 goto bad_member;
421 else if (value && TREE_CODE (value) == ADDR_EXPR)
422 (*p_msg) ("address of overloaded function with no contextual "
423 "type information");
424 else if (value && TREE_CODE (value) == OVERLOAD)
425 (*p_msg) ("overloaded function with no contextual type information");
426 else
427 (*p_msg) ("insufficient contextual information to determine type");
428 break;
430 default:
431 gcc_unreachable ();
435 /* Backward-compatibility interface to incomplete_type_diagnostic;
436 required by ../tree.c. */
437 #undef cxx_incomplete_type_error
438 void
439 cxx_incomplete_type_error (tree value, tree type)
441 cxx_incomplete_type_diagnostic (value, type, 0);
445 /* The recursive part of split_nonconstant_init. DEST is an lvalue
446 expression to which INIT should be assigned. INIT is a CONSTRUCTOR. */
448 static void
449 split_nonconstant_init_1 (tree dest, tree init)
451 tree *pelt, elt, type = TREE_TYPE (dest);
452 tree sub, code, inner_type = NULL;
453 bool array_type_p = false;
455 pelt = &CONSTRUCTOR_ELTS (init);
456 switch (TREE_CODE (type))
458 case ARRAY_TYPE:
459 inner_type = TREE_TYPE (type);
460 array_type_p = true;
461 /* FALLTHRU */
463 case RECORD_TYPE:
464 case UNION_TYPE:
465 case QUAL_UNION_TYPE:
466 while ((elt = *pelt))
468 tree field_index = TREE_PURPOSE (elt);
469 tree value = TREE_VALUE (elt);
471 if (!array_type_p)
472 inner_type = TREE_TYPE (field_index);
474 if (TREE_CODE (value) == CONSTRUCTOR)
476 if (array_type_p)
477 sub = build4 (ARRAY_REF, inner_type, dest, field_index,
478 NULL_TREE, NULL_TREE);
479 else
480 sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
481 NULL_TREE);
483 split_nonconstant_init_1 (sub, value);
485 else if (!initializer_constant_valid_p (value, inner_type))
487 *pelt = TREE_CHAIN (elt);
489 if (array_type_p)
490 sub = build4 (ARRAY_REF, inner_type, dest, field_index,
491 NULL_TREE, NULL_TREE);
492 else
493 sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
494 NULL_TREE);
496 code = build2 (MODIFY_EXPR, inner_type, sub, value);
497 code = build_stmt (EXPR_STMT, code);
498 add_stmt (code);
499 continue;
502 pelt = &TREE_CHAIN (elt);
504 break;
506 case VECTOR_TYPE:
507 if (!initializer_constant_valid_p (init, type))
509 tree cons = copy_node (init);
510 CONSTRUCTOR_ELTS (init) = NULL;
511 code = build2 (MODIFY_EXPR, type, dest, cons);
512 code = build_stmt (EXPR_STMT, code);
513 add_stmt (code);
515 break;
517 default:
518 gcc_unreachable ();
522 /* A subroutine of store_init_value. Splits non-constant static
523 initializer INIT into a constant part and generates code to
524 perform the non-constant part of the initialization to DEST.
525 Returns the code for the runtime init. */
527 static tree
528 split_nonconstant_init (tree dest, tree init)
530 tree code;
532 if (TREE_CODE (init) == CONSTRUCTOR)
534 code = push_stmt_list ();
535 split_nonconstant_init_1 (dest, init);
536 code = pop_stmt_list (code);
537 DECL_INITIAL (dest) = init;
538 TREE_READONLY (dest) = 0;
540 else
541 code = build2 (INIT_EXPR, TREE_TYPE (dest), dest, init);
543 return code;
546 /* Perform appropriate conversions on the initial value of a variable,
547 store it in the declaration DECL,
548 and print any error messages that are appropriate.
549 If the init is invalid, store an ERROR_MARK.
551 C++: Note that INIT might be a TREE_LIST, which would mean that it is
552 a base class initializer for some aggregate type, hopefully compatible
553 with DECL. If INIT is a single element, and DECL is an aggregate
554 type, we silently convert INIT into a TREE_LIST, allowing a constructor
555 to be called.
557 If INIT is a TREE_LIST and there is no constructor, turn INIT
558 into a CONSTRUCTOR and use standard initialization techniques.
559 Perhaps a warning should be generated?
561 Returns code to be executed if initialization could not be performed
562 for static variable. In that case, caller must emit the code. */
564 tree
565 store_init_value (tree decl, tree init)
567 tree value, type;
569 /* If variable's type was invalidly declared, just ignore it. */
571 type = TREE_TYPE (decl);
572 if (TREE_CODE (type) == ERROR_MARK)
573 return NULL_TREE;
575 if (IS_AGGR_TYPE (type))
577 gcc_assert (TYPE_HAS_TRIVIAL_INIT_REF (type)
578 || TREE_CODE (init) == CONSTRUCTOR);
580 if (TREE_CODE (init) == TREE_LIST)
582 error ("constructor syntax used, but no constructor declared "
583 "for type %qT", type);
584 init = build_constructor (NULL_TREE, nreverse (init));
587 else if (TREE_CODE (init) == TREE_LIST
588 && TREE_TYPE (init) != unknown_type_node)
590 if (TREE_CODE (decl) == RESULT_DECL)
591 init = build_x_compound_expr_from_list (init,
592 "return value initializer");
593 else if (TREE_CODE (init) == TREE_LIST
594 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
596 error ("cannot initialize arrays using this syntax");
597 return NULL_TREE;
599 else
600 /* We get here with code like `int a (2);' */
601 init = build_x_compound_expr_from_list (init, "initializer");
604 /* End of special C++ code. */
606 /* Digest the specified initializer into an expression. */
607 value = digest_init (type, init, (tree *) 0);
608 /* If the initializer is not a constant, fill in DECL_INITIAL with
609 the bits that are constant, and then return an expression that
610 will perform the dynamic initialization. */
611 if (value != error_mark_node
612 && (TREE_SIDE_EFFECTS (value)
613 || ! initializer_constant_valid_p (value, TREE_TYPE (value))))
614 return split_nonconstant_init (decl, value);
615 /* If the value is a constant, just put it in DECL_INITIAL. If DECL
616 is an automatic variable, the middle end will turn this into a
617 dynamic initialization later. */
618 DECL_INITIAL (decl) = value;
619 return NULL_TREE;
623 /* Digest the parser output INIT as an initializer for type TYPE.
624 Return a C expression of type TYPE to represent the initial value.
626 If TAIL is nonzero, it points to a variable holding a list of elements
627 of which INIT is the first. We update the list stored there by
628 removing from the head all the elements that we use.
629 Normally this is only one; we use more than one element only if
630 TYPE is an aggregate and INIT is not a constructor. */
632 tree
633 digest_init (tree type, tree init, tree* tail)
635 enum tree_code code = TREE_CODE (type);
636 tree element = NULL_TREE;
637 tree old_tail_contents = NULL_TREE;
639 /* By default, assume we use one element from a list.
640 We correct this later in the sole case where it is not true. */
642 if (tail)
644 old_tail_contents = *tail;
645 *tail = TREE_CHAIN (*tail);
648 if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST
649 && TREE_VALUE (init) == error_mark_node))
650 return error_mark_node;
652 if (TREE_CODE (init) == ERROR_MARK)
653 /* __PRETTY_FUNCTION__'s initializer is a bogus expression inside
654 a template function. This gets substituted during instantiation. */
655 return init;
657 /* We must strip the outermost array type when completing the type,
658 because the its bounds might be incomplete at the moment. */
659 if (!complete_type_or_else (TREE_CODE (type) == ARRAY_TYPE
660 ? TREE_TYPE (type) : type, NULL_TREE))
661 return error_mark_node;
663 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
664 if (TREE_CODE (init) == NON_LVALUE_EXPR)
665 init = TREE_OPERAND (init, 0);
667 if (BRACE_ENCLOSED_INITIALIZER_P (init)
668 && CONSTRUCTOR_ELTS (init) != 0
669 && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0)
671 element = TREE_VALUE (CONSTRUCTOR_ELTS (init));
672 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
673 if (element && TREE_CODE (element) == NON_LVALUE_EXPR)
674 element = TREE_OPERAND (element, 0);
675 if (element == error_mark_node)
676 return element;
679 /* Initialization of an array of chars from a string constant
680 optionally enclosed in braces. */
682 if (code == ARRAY_TYPE)
684 tree typ1;
686 if (TREE_CODE (init) == TREE_LIST)
688 error ("initializing array with parameter list");
689 return error_mark_node;
692 typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
693 if (char_type_p (typ1)
694 && ((init && TREE_CODE (init) == STRING_CST)
695 || (element && TREE_CODE (element) == STRING_CST)))
697 tree string = element ? element : init;
699 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
700 != char_type_node)
701 && TYPE_PRECISION (typ1) == BITS_PER_UNIT)
703 error ("char-array initialized from wide string");
704 return error_mark_node;
706 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string)))
707 == char_type_node)
708 && TYPE_PRECISION (typ1) != BITS_PER_UNIT)
710 error ("int-array initialized from non-wide string");
711 return error_mark_node;
714 TREE_TYPE (string) = type;
715 if (TYPE_DOMAIN (type) != 0
716 && TREE_CONSTANT (TYPE_SIZE (type)))
718 int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
719 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
720 /* In C it is ok to subtract 1 from the length of the string
721 because it's ok to ignore the terminating null char that is
722 counted in the length of the constant, but in C++ this would
723 be invalid. */
724 if (size < TREE_STRING_LENGTH (string))
725 pedwarn ("initializer-string for array of chars is too long");
727 return string;
731 /* Handle scalar types, including conversions,
732 and signature pointers and references. */
734 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
735 || code == ENUMERAL_TYPE || code == REFERENCE_TYPE
736 || code == BOOLEAN_TYPE || code == COMPLEX_TYPE
737 || TYPE_PTR_TO_MEMBER_P (type))
739 if (BRACE_ENCLOSED_INITIALIZER_P (init))
741 if (element == 0)
743 error ("initializer for scalar variable requires one element");
744 return error_mark_node;
746 init = element;
748 while (BRACE_ENCLOSED_INITIALIZER_P (init))
750 pedwarn ("braces around scalar initializer for %qT", type);
751 init = CONSTRUCTOR_ELTS (init);
752 if (TREE_CHAIN (init))
753 pedwarn ("ignoring extra initializers for %qT", type);
754 init = TREE_VALUE (init);
757 return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
758 "initialization", NULL_TREE, 0);
761 /* Come here only for records and arrays (and unions with constructors). */
763 if (COMPLETE_TYPE_P (type) && ! TREE_CONSTANT (TYPE_SIZE (type)))
765 error ("variable-sized object of type %qT may not be initialized",
766 type);
767 return error_mark_node;
770 if (code == ARRAY_TYPE || code == VECTOR_TYPE || IS_AGGR_TYPE_CODE (code))
772 if (BRACE_ENCLOSED_INITIALIZER_P (init))
774 if (TYPE_NON_AGGREGATE_CLASS (type))
776 error ("subobject of type %qT must be initialized by "
777 "constructor, not by %qE",
778 type, init);
779 return error_mark_node;
781 return process_init_constructor (type, init, (tree *)0);
783 else if (can_convert_arg (type, TREE_TYPE (init), init)
784 || TYPE_NON_AGGREGATE_CLASS (type))
785 /* These are never initialized from multiple constructor elements. */;
786 else if (tail != 0)
788 *tail = old_tail_contents;
789 return process_init_constructor (type, 0, tail);
792 if (code != ARRAY_TYPE)
794 int flags = LOOKUP_NORMAL;
795 /* Initialization from { } is copy-initialization. */
796 if (tail)
797 flags |= LOOKUP_ONLYCONVERTING;
799 return convert_for_initialization (NULL_TREE, type, init, flags,
800 "initialization", NULL_TREE, 0);
804 error ("invalid initializer");
805 return error_mark_node;
808 /* Process a constructor for a variable of type TYPE.
809 The constructor elements may be specified either with INIT or with ELTS,
810 only one of which should be non-null.
812 If INIT is specified, it is a CONSTRUCTOR node which is specifically
813 and solely for initializing this datum.
815 If ELTS is specified, it is the address of a variable containing
816 a list of expressions. We take as many elements as we need
817 from the head of the list and update the list.
819 In the resulting constructor, TREE_CONSTANT is set if all elts are
820 constant, and TREE_STATIC is set if, in addition, all elts are simple enough
821 constants that the assembler and linker can compute them. */
823 static tree
824 process_init_constructor (tree type, tree init, tree* elts)
826 tree tail;
827 /* List of the elements of the result constructor,
828 in reverse order. */
829 tree members = NULL;
830 tree next1;
831 tree result;
832 int allconstant = 1;
833 int allsimple = 1;
834 int erroneous = 0;
836 /* Make TAIL be the list of elements to use for the initialization,
837 no matter how the data was given to us. */
839 if (elts)
841 if (warn_missing_braces)
842 warning ("aggregate has a partly bracketed initializer");
843 tail = *elts;
845 else
846 tail = CONSTRUCTOR_ELTS (init);
848 /* Gobble as many elements as needed, and make a constructor or initial value
849 for each element of this aggregate. Chain them together in result.
850 If there are too few, use 0 for each scalar ultimate component. */
852 if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == VECTOR_TYPE)
854 long len;
855 int i;
857 if (TREE_CODE (type) == ARRAY_TYPE)
859 tree domain = TYPE_DOMAIN (type);
860 if (domain)
861 len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
862 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
863 + 1);
864 else
865 len = -1; /* Take as many as there are. */
867 else
869 /* Vectors are like simple fixed-size arrays. */
870 len = TYPE_VECTOR_SUBPARTS (type);
873 for (i = 0; len < 0 || i < len; i++)
875 if (tail)
877 if (TREE_PURPOSE (tail)
878 && (TREE_CODE (TREE_PURPOSE (tail)) != INTEGER_CST
879 || compare_tree_int (TREE_PURPOSE (tail), i) != 0))
880 sorry ("non-trivial labeled initializers");
882 if (TREE_VALUE (tail) != 0)
884 tree tail1 = tail;
885 next1 = digest_init (TREE_TYPE (type),
886 TREE_VALUE (tail), &tail1);
887 if (next1 == error_mark_node)
888 return next1;
889 gcc_assert (same_type_ignoring_top_level_qualifiers_p
890 (TREE_TYPE (type), TREE_TYPE (next1)));
891 gcc_assert (!tail1 || TREE_CODE (tail1) == TREE_LIST);
892 if (tail == tail1 && len < 0)
894 error ("non-empty initializer for array of empty elements");
895 /* Just ignore what we were supposed to use. */
896 tail1 = NULL_TREE;
898 tail = tail1;
900 else
902 next1 = error_mark_node;
903 tail = TREE_CHAIN (tail);
906 else if (len < 0)
907 /* We're done. */
908 break;
909 else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)))
911 /* If this type needs constructors run for
912 default-initialization, we can't rely on the backend to do it
913 for us, so build up TARGET_EXPRs. If the type in question is
914 a class, just build one up; if it's an array, recurse. */
916 if (IS_AGGR_TYPE (TREE_TYPE (type)))
917 next1 = build_functional_cast (TREE_TYPE (type), NULL_TREE);
918 else
919 next1 = build_constructor (NULL_TREE, NULL_TREE);
920 next1 = digest_init (TREE_TYPE (type), next1, 0);
922 else if (! zero_init_p (TREE_TYPE (type)))
923 next1 = build_zero_init (TREE_TYPE (type),
924 /*nelts=*/NULL_TREE,
925 /*static_storage_p=*/false);
926 else
927 /* The default zero-initialization is fine for us; don't
928 add anything to the CONSTRUCTOR. */
929 break;
931 if (next1 == error_mark_node)
932 erroneous = 1;
933 else if (!TREE_CONSTANT (next1))
934 allconstant = 0;
935 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
936 allsimple = 0;
937 members = tree_cons (size_int (i), next1, members);
940 else if (TREE_CODE (type) == RECORD_TYPE)
942 tree field;
944 if (tail)
946 gcc_assert (!CLASSTYPE_VBASECLASSES (type));
947 gcc_assert (!TYPE_BINFO (type)
948 || !BINFO_N_BASE_BINFOS (TYPE_BINFO (type)));
949 gcc_assert (!TYPE_POLYMORPHIC_P (type));
952 for (field = TYPE_FIELDS (type); field;
953 field = TREE_CHAIN (field))
955 if (! DECL_NAME (field) && DECL_C_BIT_FIELD (field))
957 members = tree_cons (field, integer_zero_node, members);
958 continue;
961 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
962 continue;
964 if (tail)
966 if (TREE_PURPOSE (tail)
967 && TREE_PURPOSE (tail) != field
968 && TREE_PURPOSE (tail) != DECL_NAME (field))
969 sorry ("non-trivial labeled initializers");
971 if (TREE_VALUE (tail) != 0)
973 tree tail1 = tail;
975 next1 = digest_init (TREE_TYPE (field),
976 TREE_VALUE (tail), &tail1);
977 gcc_assert (!tail1 || TREE_CODE (tail1) == TREE_LIST);
978 tail = tail1;
980 else
982 next1 = error_mark_node;
983 tail = TREE_CHAIN (tail);
986 else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
988 /* If this type needs constructors run for
989 default-initialization, we can't rely on the backend to do it
990 for us, so build up TARGET_EXPRs. If the type in question is
991 a class, just build one up; if it's an array, recurse. */
993 if (IS_AGGR_TYPE (TREE_TYPE (field)))
994 next1 = build_functional_cast (TREE_TYPE (field),
995 NULL_TREE);
996 else
998 next1 = build_constructor (NULL_TREE, NULL_TREE);
999 if (init)
1000 TREE_HAS_CONSTRUCTOR (next1)
1001 = TREE_HAS_CONSTRUCTOR (init);
1003 next1 = digest_init (TREE_TYPE (field), next1, 0);
1005 /* Warn when some struct elements are implicitly initialized. */
1006 if (warn_missing_field_initializers
1007 && (!init || BRACE_ENCLOSED_INITIALIZER_P (init)))
1008 warning ("missing initializer for member %qD", field);
1010 else
1012 if (TREE_READONLY (field))
1013 error ("uninitialized const member %qD", field);
1014 else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
1015 error ("member %qD with uninitialized const fields", field);
1016 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
1017 error ("member %qD is uninitialized reference", field);
1019 /* Warn when some struct elements are implicitly initialized
1020 to zero. */
1021 if (warn_missing_field_initializers
1022 && (!init || BRACE_ENCLOSED_INITIALIZER_P (init)))
1023 warning ("missing initializer for member %qD", field);
1025 if (! zero_init_p (TREE_TYPE (field)))
1026 next1 = build_zero_init (TREE_TYPE (field),
1027 /*nelts=*/NULL_TREE,
1028 /*static_storage_p=*/false);
1029 else
1030 /* The default zero-initialization is fine for us; don't
1031 add anything to the CONSTRUCTOR. */
1032 continue;
1035 if (next1 == error_mark_node)
1036 erroneous = 1;
1037 else if (!TREE_CONSTANT (next1))
1038 allconstant = 0;
1039 else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1)))
1040 allsimple = 0;
1041 members = tree_cons (field, next1, members);
1044 else if (TREE_CODE (type) == UNION_TYPE
1045 /* If the initializer was empty, use default zero initialization. */
1046 && tail)
1048 tree field = TYPE_FIELDS (type);
1050 /* Find the first named field. ANSI decided in September 1990
1051 that only named fields count here. */
1052 while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
1053 field = TREE_CHAIN (field);
1055 /* If this element specifies a field, initialize via that field. */
1056 if (TREE_PURPOSE (tail) != NULL_TREE)
1058 int win = 0;
1060 if (TREE_CODE (TREE_PURPOSE (tail)) == FIELD_DECL)
1061 /* Handle the case of a call by build_c_cast. */
1062 field = TREE_PURPOSE (tail), win = 1;
1063 else if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE)
1064 error ("index value instead of field name in union initializer");
1065 else
1067 tree temp;
1068 for (temp = TYPE_FIELDS (type);
1069 temp;
1070 temp = TREE_CHAIN (temp))
1071 if (DECL_NAME (temp) == TREE_PURPOSE (tail))
1072 break;
1073 if (temp)
1074 field = temp, win = 1;
1075 else
1076 error ("no field %qD in union being initialized",
1077 TREE_PURPOSE (tail));
1079 if (!win)
1080 TREE_VALUE (tail) = error_mark_node;
1082 else if (field == 0)
1084 error ("union %qT with no named members cannot be initialized",
1085 type);
1086 TREE_VALUE (tail) = error_mark_node;
1089 if (TREE_VALUE (tail) != 0)
1091 tree tail1 = tail;
1093 next1 = digest_init (TREE_TYPE (field),
1094 TREE_VALUE (tail), &tail1);
1095 gcc_assert (!tail1 || TREE_CODE (tail1) == TREE_LIST);
1096 tail = tail1;
1098 else
1100 next1 = error_mark_node;
1101 tail = TREE_CHAIN (tail);
1104 if (next1 == error_mark_node)
1105 erroneous = 1;
1106 else if (!TREE_CONSTANT (next1))
1107 allconstant = 0;
1108 else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0)
1109 allsimple = 0;
1110 members = tree_cons (field, next1, members);
1113 /* If arguments were specified as a list, just remove the ones we used. */
1114 if (elts)
1115 *elts = tail;
1116 /* If arguments were specified as a constructor,
1117 complain unless we used all the elements of the constructor. */
1118 else if (tail)
1119 pedwarn ("excess elements in aggregate initializer");
1121 if (erroneous)
1122 return error_mark_node;
1124 result = build_constructor (type, nreverse (members));
1125 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE)
1126 cp_complete_array_type (&TREE_TYPE (result), result, /*do_default=*/0);
1127 if (init)
1128 TREE_HAS_CONSTRUCTOR (result) = TREE_HAS_CONSTRUCTOR (init);
1129 if (allconstant)
1131 TREE_CONSTANT (result) = 1;
1132 TREE_INVARIANT (result) = 1;
1133 if (allsimple)
1134 TREE_STATIC (result) = 1;
1136 return result;
1139 /* Given a structure or union value DATUM, construct and return
1140 the structure or union component which results from narrowing
1141 that value to the base specified in BASETYPE. For example, given the
1142 hierarchy
1144 class L { int ii; };
1145 class A : L { ... };
1146 class B : L { ... };
1147 class C : A, B { ... };
1149 and the declaration
1151 C x;
1153 then the expression
1155 x.A::ii refers to the ii member of the L part of
1156 the A part of the C object named by X. In this case,
1157 DATUM would be x, and BASETYPE would be A.
1159 I used to think that this was nonconformant, that the standard specified
1160 that first we look up ii in A, then convert x to an L& and pull out the
1161 ii part. But in fact, it does say that we convert x to an A&; A here
1162 is known as the "naming class". (jason 2000-12-19)
1164 BINFO_P points to a variable initialized either to NULL_TREE or to the
1165 binfo for the specific base subobject we want to convert to. */
1167 tree
1168 build_scoped_ref (tree datum, tree basetype, tree* binfo_p)
1170 tree binfo;
1172 if (datum == error_mark_node)
1173 return error_mark_node;
1174 if (*binfo_p)
1175 binfo = *binfo_p;
1176 else
1177 binfo = lookup_base (TREE_TYPE (datum), basetype, ba_check, NULL);
1179 if (!binfo || binfo == error_mark_node)
1181 *binfo_p = NULL_TREE;
1182 if (!binfo)
1183 error_not_base_type (basetype, TREE_TYPE (datum));
1184 return error_mark_node;
1187 *binfo_p = binfo;
1188 return build_base_path (PLUS_EXPR, datum, binfo, 1);
1191 /* Build a reference to an object specified by the C++ `->' operator.
1192 Usually this just involves dereferencing the object, but if the
1193 `->' operator is overloaded, then such overloads must be
1194 performed until an object which does not have the `->' operator
1195 overloaded is found. An error is reported when circular pointer
1196 delegation is detected. */
1198 tree
1199 build_x_arrow (tree expr)
1201 tree orig_expr = expr;
1202 tree types_memoized = NULL_TREE;
1203 tree type = TREE_TYPE (expr);
1204 tree last_rval = NULL_TREE;
1206 if (type == error_mark_node)
1207 return error_mark_node;
1209 if (processing_template_decl)
1211 if (type_dependent_expression_p (expr))
1212 return build_min_nt (ARROW_EXPR, expr);
1213 expr = build_non_dependent_expr (expr);
1216 if (IS_AGGR_TYPE (type))
1218 while ((expr = build_new_op (COMPONENT_REF, LOOKUP_NORMAL, expr,
1219 NULL_TREE, NULL_TREE,
1220 /*overloaded_p=*/NULL)))
1222 if (expr == error_mark_node)
1223 return error_mark_node;
1225 if (value_member (TREE_TYPE (expr), types_memoized))
1227 error ("circular pointer delegation detected");
1228 return error_mark_node;
1230 else
1232 types_memoized = tree_cons (NULL_TREE, TREE_TYPE (expr),
1233 types_memoized);
1235 last_rval = expr;
1238 if (last_rval == NULL_TREE)
1240 error ("base operand of %<->%> has non-pointer type %qT", type);
1241 return error_mark_node;
1244 if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE)
1245 last_rval = convert_from_reference (last_rval);
1247 else
1248 last_rval = decay_conversion (expr);
1250 if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE)
1252 if (processing_template_decl)
1254 expr = build_min_non_dep (ARROW_EXPR, last_rval, orig_expr);
1255 /* It will be dereferenced. */
1256 TREE_TYPE (expr) = TREE_TYPE (TREE_TYPE (last_rval));
1257 return expr;
1260 return build_indirect_ref (last_rval, NULL);
1263 if (types_memoized)
1264 error ("result of %<operator->()%> yields non-pointer result");
1265 else
1266 error ("base operand of %<->%> is not a pointer");
1267 return error_mark_node;
1270 /* Return an expression for "DATUM .* COMPONENT". DATUM has not
1271 already been checked out to be of aggregate type. */
1273 tree
1274 build_m_component_ref (tree datum, tree component)
1276 tree ptrmem_type;
1277 tree objtype;
1278 tree type;
1279 tree binfo;
1280 tree ctype;
1282 datum = decay_conversion (datum);
1284 if (datum == error_mark_node || component == error_mark_node)
1285 return error_mark_node;
1287 ptrmem_type = TREE_TYPE (component);
1288 if (!TYPE_PTR_TO_MEMBER_P (ptrmem_type))
1290 error ("%qE cannot be used as a member pointer, since it is of "
1291 "type %qT",
1292 component, ptrmem_type);
1293 return error_mark_node;
1296 objtype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));
1297 if (! IS_AGGR_TYPE (objtype))
1299 error ("cannot apply member pointer %qE to %qE, which is of "
1300 "non-aggregate type %qT",
1301 component, datum, objtype);
1302 return error_mark_node;
1305 type = TYPE_PTRMEM_POINTED_TO_TYPE (ptrmem_type);
1306 ctype = complete_type (TYPE_PTRMEM_CLASS_TYPE (ptrmem_type));
1308 if (!COMPLETE_TYPE_P (ctype))
1310 if (!same_type_p (ctype, objtype))
1311 goto mismatch;
1312 binfo = NULL;
1314 else
1316 binfo = lookup_base (objtype, ctype, ba_check, NULL);
1318 if (!binfo)
1320 mismatch:
1321 error ("pointer to member type %qT incompatible with object "
1322 "type %qT",
1323 type, objtype);
1324 return error_mark_node;
1326 else if (binfo == error_mark_node)
1327 return error_mark_node;
1330 if (TYPE_PTRMEM_P (ptrmem_type))
1332 /* Compute the type of the field, as described in [expr.ref].
1333 There's no such thing as a mutable pointer-to-member, so
1334 things are not as complex as they are for references to
1335 non-static data members. */
1336 type = cp_build_qualified_type (type,
1337 (cp_type_quals (type)
1338 | cp_type_quals (TREE_TYPE (datum))));
1340 datum = build_address (datum);
1342 /* Convert object to the correct base. */
1343 if (binfo)
1344 datum = build_base_path (PLUS_EXPR, datum, binfo, 1);
1346 /* Build an expression for "object + offset" where offset is the
1347 value stored in the pointer-to-data-member. */
1348 datum = build2 (PLUS_EXPR, build_pointer_type (type),
1349 datum, build_nop (ptrdiff_type_node, component));
1350 return build_indirect_ref (datum, 0);
1352 else
1353 return build2 (OFFSET_REF, type, datum, component);
1356 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
1358 tree
1359 build_functional_cast (tree exp, tree parms)
1361 /* This is either a call to a constructor,
1362 or a C cast in C++'s `functional' notation. */
1363 tree type;
1365 if (exp == error_mark_node || parms == error_mark_node)
1366 return error_mark_node;
1368 if (TREE_CODE (exp) == TYPE_DECL)
1369 type = TREE_TYPE (exp);
1370 else
1371 type = exp;
1373 if (processing_template_decl)
1375 tree t = build_min (CAST_EXPR, type, parms);
1376 /* We don't know if it will or will not have side effects. */
1377 TREE_SIDE_EFFECTS (t) = 1;
1378 return t;
1381 if (! IS_AGGR_TYPE (type))
1383 /* This must build a C cast. */
1384 if (parms == NULL_TREE)
1385 parms = integer_zero_node;
1386 else
1387 parms = build_x_compound_expr_from_list (parms, "functional cast");
1389 return build_c_cast (type, parms);
1392 /* Prepare to evaluate as a call to a constructor. If this expression
1393 is actually used, for example,
1395 return X (arg1, arg2, ...);
1397 then the slot being initialized will be filled in. */
1399 if (!complete_type_or_else (type, NULL_TREE))
1400 return error_mark_node;
1401 if (abstract_virtuals_error (NULL_TREE, type))
1402 return error_mark_node;
1404 if (parms && TREE_CHAIN (parms) == NULL_TREE)
1405 return build_c_cast (type, TREE_VALUE (parms));
1407 /* We need to zero-initialize POD types. Let's do that for everything
1408 that doesn't need a constructor. */
1409 if (parms == NULL_TREE && !TYPE_NEEDS_CONSTRUCTING (type)
1410 && TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
1412 exp = build_constructor (type, NULL_TREE);
1413 return get_target_expr (exp);
1416 exp = build_special_member_call (NULL_TREE, complete_ctor_identifier, parms,
1417 type, LOOKUP_NORMAL);
1419 if (exp == error_mark_node)
1420 return error_mark_node;
1422 return build_cplus_new (type, exp);
1426 /* Add new exception specifier SPEC, to the LIST we currently have.
1427 If it's already in LIST then do nothing.
1428 Moan if it's bad and we're allowed to. COMPLAIN < 0 means we
1429 know what we're doing. */
1431 tree
1432 add_exception_specifier (tree list, tree spec, int complain)
1434 bool ok;
1435 tree core = spec;
1436 bool is_ptr;
1437 int diag_type = -1; /* none */
1439 if (spec == error_mark_node)
1440 return list;
1442 gcc_assert (spec && (!list || TREE_VALUE (list)));
1444 /* [except.spec] 1, type in an exception specifier shall not be
1445 incomplete, or pointer or ref to incomplete other than pointer
1446 to cv void. */
1447 is_ptr = TREE_CODE (core) == POINTER_TYPE;
1448 if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE)
1449 core = TREE_TYPE (core);
1450 if (complain < 0)
1451 ok = true;
1452 else if (VOID_TYPE_P (core))
1453 ok = is_ptr;
1454 else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM)
1455 ok = true;
1456 else if (processing_template_decl)
1457 ok = true;
1458 else
1460 ok = true;
1461 /* 15.4/1 says that types in an exception specifier must be complete,
1462 but it seems more reasonable to only require this on definitions
1463 and calls. So just give a pedwarn at this point; we will give an
1464 error later if we hit one of those two cases. */
1465 if (!COMPLETE_TYPE_P (complete_type (core)))
1466 diag_type = 2; /* pedwarn */
1469 if (ok)
1471 tree probe;
1473 for (probe = list; probe; probe = TREE_CHAIN (probe))
1474 if (same_type_p (TREE_VALUE (probe), spec))
1475 break;
1476 if (!probe)
1477 list = tree_cons (NULL_TREE, spec, list);
1479 else
1480 diag_type = 0; /* error */
1482 if (diag_type >= 0 && complain)
1483 cxx_incomplete_type_diagnostic (NULL_TREE, core, diag_type);
1485 return list;
1488 /* Combine the two exceptions specifier lists LIST and ADD, and return
1489 their union. */
1491 tree
1492 merge_exception_specifiers (tree list, tree add)
1494 if (!list || !add)
1495 return NULL_TREE;
1496 else if (!TREE_VALUE (list))
1497 return add;
1498 else if (!TREE_VALUE (add))
1499 return list;
1500 else
1502 tree orig_list = list;
1504 for (; add; add = TREE_CHAIN (add))
1506 tree spec = TREE_VALUE (add);
1507 tree probe;
1509 for (probe = orig_list; probe; probe = TREE_CHAIN (probe))
1510 if (same_type_p (TREE_VALUE (probe), spec))
1511 break;
1512 if (!probe)
1514 spec = build_tree_list (NULL_TREE, spec);
1515 TREE_CHAIN (spec) = list;
1516 list = spec;
1520 return list;
1523 /* Subroutine of build_call. Ensure that each of the types in the
1524 exception specification is complete. Technically, 15.4/1 says that
1525 they need to be complete when we see a declaration of the function,
1526 but we should be able to get away with only requiring this when the
1527 function is defined or called. See also add_exception_specifier. */
1529 void
1530 require_complete_eh_spec_types (tree fntype, tree decl)
1532 tree raises;
1533 /* Don't complain about calls to op new. */
1534 if (decl && DECL_ARTIFICIAL (decl))
1535 return;
1536 for (raises = TYPE_RAISES_EXCEPTIONS (fntype); raises;
1537 raises = TREE_CHAIN (raises))
1539 tree type = TREE_VALUE (raises);
1540 if (type && !COMPLETE_TYPE_P (type))
1542 if (decl)
1543 error
1544 ("call to function %qD which throws incomplete type %q#T",
1545 decl, type);
1546 else
1547 error ("call to function which throws incomplete type %q#T",
1548 decl);
1554 #include "gt-cp-typeck2.h"