* sv.po: Update.
[official-gcc.git] / gcc / cp / typeck2.c
blob54a432f256f3801b63a1b7dcc60ee0273d46e836
1 /* Report error messages, build initializers, and perform
2 some front-end optimizations for C++ compiler.
3 Copyright (C) 1987-2016 Free Software Foundation, Inc.
4 Hacked by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file is part of the C++ front end.
24 It contains routines to build C++ expressions given their operands,
25 including computing the types of the result, C and C++ specific error
26 checks, and some optimization. */
28 #include "config.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "cp-tree.h"
32 #include "stor-layout.h"
33 #include "varasm.h"
34 #include "intl.h"
36 static tree
37 process_init_constructor (tree type, tree init, tsubst_flags_t complain);
40 /* Print an error message stemming from an attempt to use
41 BASETYPE as a base class for TYPE. */
43 tree
44 error_not_base_type (tree basetype, tree type)
46 if (TREE_CODE (basetype) == FUNCTION_DECL)
47 basetype = DECL_CONTEXT (basetype);
48 error ("type %qT is not a base type for type %qT", basetype, type);
49 return error_mark_node;
52 tree
53 binfo_or_else (tree base, tree type)
55 tree binfo = lookup_base (type, base, ba_unique,
56 NULL, tf_warning_or_error);
58 if (binfo == error_mark_node)
59 return NULL_TREE;
60 else if (!binfo)
61 error_not_base_type (base, type);
62 return binfo;
65 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
66 value may not be changed thereafter. */
68 void
69 cxx_readonly_error (tree arg, enum lvalue_use errstring)
72 /* This macro is used to emit diagnostics to ensure that all format
73 strings are complete sentences, visible to gettext and checked at
74 compile time. */
76 #define ERROR_FOR_ASSIGNMENT(AS, ASM, IN, DE, ARG) \
77 do { \
78 switch (errstring) \
79 { \
80 case lv_assign: \
81 error(AS, ARG); \
82 break; \
83 case lv_asm: \
84 error(ASM, ARG); \
85 break; \
86 case lv_increment: \
87 error (IN, ARG); \
88 break; \
89 case lv_decrement: \
90 error (DE, ARG); \
91 break; \
92 default: \
93 gcc_unreachable (); \
94 } \
95 } while (0)
97 /* Handle C++-specific things first. */
99 if (VAR_P (arg)
100 && DECL_LANG_SPECIFIC (arg)
101 && DECL_IN_AGGR_P (arg)
102 && !TREE_STATIC (arg))
103 ERROR_FOR_ASSIGNMENT (G_("assignment of "
104 "constant field %qD"),
105 G_("constant field %qD "
106 "used as %<asm%> output"),
107 G_("increment of "
108 "constant field %qD"),
109 G_("decrement of "
110 "constant field %qD"),
111 arg);
112 else if (INDIRECT_REF_P (arg)
113 && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE
114 && (VAR_P (TREE_OPERAND (arg, 0))
115 || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL))
116 ERROR_FOR_ASSIGNMENT (G_("assignment of "
117 "read-only reference %qD"),
118 G_("read-only reference %qD "
119 "used as %<asm%> output"),
120 G_("increment of "
121 "read-only reference %qD"),
122 G_("decrement of "
123 "read-only reference %qD"),
124 TREE_OPERAND (arg, 0));
125 else
126 readonly_error (input_location, arg, errstring);
130 /* Structure that holds information about declarations whose type was
131 incomplete and we could not check whether it was abstract or not. */
133 struct GTY((chain_next ("%h.next"), for_user)) pending_abstract_type {
134 /* Declaration which we are checking for abstractness. It is either
135 a DECL node, or an IDENTIFIER_NODE if we do not have a full
136 declaration available. */
137 tree decl;
139 /* Type which will be checked for abstractness. */
140 tree type;
142 /* Kind of use in an unnamed declarator. */
143 enum abstract_class_use use;
145 /* Position of the declaration. This is only needed for IDENTIFIER_NODEs,
146 because DECLs already carry locus information. */
147 location_t locus;
149 /* Link to the next element in list. */
150 struct pending_abstract_type* next;
153 struct abstract_type_hasher : ggc_ptr_hash<pending_abstract_type>
155 typedef tree compare_type;
156 static hashval_t hash (pending_abstract_type *);
157 static bool equal (pending_abstract_type *, tree);
160 /* Compute the hash value of the node VAL. This function is used by the
161 hash table abstract_pending_vars. */
163 hashval_t
164 abstract_type_hasher::hash (pending_abstract_type *pat)
166 return (hashval_t) TYPE_UID (pat->type);
170 /* Compare node VAL1 with the type VAL2. This function is used by the
171 hash table abstract_pending_vars. */
173 bool
174 abstract_type_hasher::equal (pending_abstract_type *pat1, tree type2)
176 return (pat1->type == type2);
179 /* Hash table that maintains pending_abstract_type nodes, for which we still
180 need to check for type abstractness. The key of the table is the type
181 of the declaration. */
182 static GTY (()) hash_table<abstract_type_hasher> *abstract_pending_vars = NULL;
184 static int abstract_virtuals_error_sfinae (tree, tree, abstract_class_use, tsubst_flags_t);
186 /* This function is called after TYPE is completed, and will check if there
187 are pending declarations for which we still need to verify the abstractness
188 of TYPE, and emit a diagnostic (through abstract_virtuals_error) if TYPE
189 turned out to be incomplete. */
191 void
192 complete_type_check_abstract (tree type)
194 struct pending_abstract_type *pat;
195 location_t cur_loc = input_location;
197 gcc_assert (COMPLETE_TYPE_P (type));
199 if (!abstract_pending_vars)
200 return;
202 /* Retrieve the list of pending declarations for this type. */
203 pending_abstract_type **slot
204 = abstract_pending_vars->find_slot_with_hash (type, TYPE_UID (type),
205 NO_INSERT);
206 if (!slot)
207 return;
208 pat = *slot;
209 gcc_assert (pat);
211 /* If the type is not abstract, do not do anything. */
212 if (CLASSTYPE_PURE_VIRTUALS (type))
214 struct pending_abstract_type *prev = 0, *next;
216 /* Reverse the list to emit the errors in top-down order. */
217 for (; pat; pat = next)
219 next = pat->next;
220 pat->next = prev;
221 prev = pat;
223 pat = prev;
225 /* Go through the list, and call abstract_virtuals_error for each
226 element: it will issue a diagnostic if the type is abstract. */
227 while (pat)
229 gcc_assert (type == pat->type);
231 /* Tweak input_location so that the diagnostic appears at the correct
232 location. Notice that this is only needed if the decl is an
233 IDENTIFIER_NODE. */
234 input_location = pat->locus;
235 abstract_virtuals_error_sfinae (pat->decl, pat->type, pat->use,
236 tf_warning_or_error);
237 pat = pat->next;
241 abstract_pending_vars->clear_slot (slot);
243 input_location = cur_loc;
247 /* If TYPE has abstract virtual functions, issue an error about trying
248 to create an object of that type. DECL is the object declared, or
249 NULL_TREE if the declaration is unavailable, in which case USE specifies
250 the kind of invalid use. Returns 1 if an error occurred; zero if
251 all was well. */
253 static int
254 abstract_virtuals_error_sfinae (tree decl, tree type, abstract_class_use use,
255 tsubst_flags_t complain)
257 vec<tree, va_gc> *pure;
259 /* This function applies only to classes. Any other entity can never
260 be abstract. */
261 if (!CLASS_TYPE_P (type))
262 return 0;
263 type = TYPE_MAIN_VARIANT (type);
265 #if 0
266 /* Instantiation here seems to be required by the standard,
267 but breaks e.g. boost::bind. FIXME! */
268 /* In SFINAE, non-N3276 context, force instantiation. */
269 if (!(complain & (tf_error|tf_decltype)))
270 complete_type (type);
271 #endif
273 /* If the type is incomplete, we register it within a hash table,
274 so that we can check again once it is completed. This makes sense
275 only for objects for which we have a declaration or at least a
276 name. */
277 if (!COMPLETE_TYPE_P (type) && (complain & tf_error))
279 struct pending_abstract_type *pat;
281 gcc_assert (!decl || DECL_P (decl) || identifier_p (decl));
283 if (!abstract_pending_vars)
284 abstract_pending_vars
285 = hash_table<abstract_type_hasher>::create_ggc (31);
287 pending_abstract_type **slot
288 = abstract_pending_vars->find_slot_with_hash (type, TYPE_UID (type),
289 INSERT);
291 pat = ggc_alloc<pending_abstract_type> ();
292 pat->type = type;
293 pat->decl = decl;
294 pat->use = use;
295 pat->locus = ((decl && DECL_P (decl))
296 ? DECL_SOURCE_LOCATION (decl)
297 : input_location);
299 pat->next = *slot;
300 *slot = pat;
302 return 0;
305 if (!TYPE_SIZE (type))
306 /* TYPE is being defined, and during that time
307 CLASSTYPE_PURE_VIRTUALS holds the inline friends. */
308 return 0;
310 pure = CLASSTYPE_PURE_VIRTUALS (type);
311 if (!pure)
312 return 0;
314 if (!(complain & tf_error))
315 return 1;
317 if (decl)
319 if (VAR_P (decl))
320 error ("cannot declare variable %q+D to be of abstract "
321 "type %qT", decl, type);
322 else if (TREE_CODE (decl) == PARM_DECL)
324 if (DECL_NAME (decl))
325 error ("cannot declare parameter %q+D to be of abstract type %qT",
326 decl, type);
327 else
328 error ("cannot declare parameter to be of abstract type %qT",
329 type);
331 else if (TREE_CODE (decl) == FIELD_DECL)
332 error ("cannot declare field %q+D to be of abstract type %qT",
333 decl, type);
334 else if (TREE_CODE (decl) == FUNCTION_DECL
335 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
336 error ("invalid abstract return type for member function %q+#D", decl);
337 else if (TREE_CODE (decl) == FUNCTION_DECL)
338 error ("invalid abstract return type for function %q+#D", decl);
339 else if (identifier_p (decl))
340 /* Here we do not have location information. */
341 error ("invalid abstract type %qT for %qE", type, decl);
342 else
343 error ("invalid abstract type for %q+D", decl);
345 else switch (use)
347 case ACU_ARRAY:
348 error ("creating array of %qT, which is an abstract class type", type);
349 break;
350 case ACU_CAST:
351 error ("invalid cast to abstract class type %qT", type);
352 break;
353 case ACU_NEW:
354 error ("invalid new-expression of abstract class type %qT", type);
355 break;
356 case ACU_RETURN:
357 error ("invalid abstract return type %qT", type);
358 break;
359 case ACU_PARM:
360 error ("invalid abstract parameter type %qT", type);
361 break;
362 case ACU_THROW:
363 error ("expression of abstract class type %qT cannot "
364 "be used in throw-expression", type);
365 break;
366 case ACU_CATCH:
367 error ("cannot declare catch parameter to be of abstract "
368 "class type %qT", type);
369 break;
370 default:
371 error ("cannot allocate an object of abstract type %qT", type);
374 /* Only go through this once. */
375 if (pure->length ())
377 unsigned ix;
378 tree fn;
380 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
381 " because the following virtual functions are pure within %qT:",
382 type);
384 FOR_EACH_VEC_ELT (*pure, ix, fn)
385 if (! DECL_CLONED_FUNCTION_P (fn)
386 || DECL_COMPLETE_DESTRUCTOR_P (fn))
387 inform (DECL_SOURCE_LOCATION (fn), "\t%#D", fn);
389 /* Now truncate the vector. This leaves it non-null, so we know
390 there are pure virtuals, but empty so we don't list them out
391 again. */
392 pure->truncate (0);
395 return 1;
399 abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
401 return abstract_virtuals_error_sfinae (decl, type, ACU_UNKNOWN, complain);
405 abstract_virtuals_error_sfinae (abstract_class_use use, tree type,
406 tsubst_flags_t complain)
408 return abstract_virtuals_error_sfinae (NULL_TREE, type, use, complain);
412 /* Wrapper for the above function in the common case of wanting errors. */
415 abstract_virtuals_error (tree decl, tree type)
417 return abstract_virtuals_error_sfinae (decl, type, tf_warning_or_error);
421 abstract_virtuals_error (abstract_class_use use, tree type)
423 return abstract_virtuals_error_sfinae (use, type, tf_warning_or_error);
426 /* Print an inform about the declaration of the incomplete type TYPE. */
428 void
429 cxx_incomplete_type_inform (const_tree type)
431 if (!TYPE_MAIN_DECL (type))
432 return;
434 location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
435 tree ptype = strip_top_quals (CONST_CAST_TREE (type));
437 if (current_class_type
438 && TYPE_BEING_DEFINED (current_class_type)
439 && same_type_p (ptype, current_class_type))
440 inform (loc, "definition of %q#T is not complete until "
441 "the closing brace", ptype);
442 else if (!TYPE_TEMPLATE_INFO (ptype))
443 inform (loc, "forward declaration of %q#T", ptype);
444 else
445 inform (loc, "declaration of %q#T", ptype);
448 /* Print an error message for invalid use of an incomplete type.
449 VALUE is the expression that was used (or 0 if that isn't known)
450 and TYPE is the type that was invalid. DIAG_KIND indicates the
451 type of diagnostic (see diagnostic.def). */
453 void
454 cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
455 diagnostic_t diag_kind)
457 bool is_decl = false, complained = false;
459 gcc_assert (diag_kind == DK_WARNING
460 || diag_kind == DK_PEDWARN
461 || diag_kind == DK_ERROR);
463 /* Avoid duplicate error message. */
464 if (TREE_CODE (type) == ERROR_MARK)
465 return;
467 if (value != 0 && (VAR_P (value)
468 || TREE_CODE (value) == PARM_DECL
469 || TREE_CODE (value) == FIELD_DECL))
471 complained = emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (value), 0,
472 "%qD has incomplete type", value);
473 is_decl = true;
475 retry:
476 /* We must print an error message. Be clever about what it says. */
478 location_t loc = EXPR_LOC_OR_LOC (value, input_location);
480 switch (TREE_CODE (type))
482 case RECORD_TYPE:
483 case UNION_TYPE:
484 case ENUMERAL_TYPE:
485 if (!is_decl)
486 complained = emit_diagnostic (diag_kind, loc, 0,
487 "invalid use of incomplete type %q#T",
488 type);
489 if (complained)
490 cxx_incomplete_type_inform (type);
491 break;
493 case VOID_TYPE:
494 emit_diagnostic (diag_kind, loc, 0,
495 "invalid use of %qT", type);
496 break;
498 case ARRAY_TYPE:
499 if (TYPE_DOMAIN (type))
501 type = TREE_TYPE (type);
502 goto retry;
504 emit_diagnostic (diag_kind, loc, 0,
505 "invalid use of array with unspecified bounds");
506 break;
508 case OFFSET_TYPE:
509 bad_member:
511 tree member = TREE_OPERAND (value, 1);
512 if (is_overloaded_fn (member))
513 member = get_first_fn (member);
514 if (DECL_FUNCTION_MEMBER_P (member)
515 && ! flag_ms_extensions)
516 emit_diagnostic (diag_kind, loc, 0,
517 "invalid use of member function %qD "
518 "(did you forget the %<()%> ?)", member);
519 else
520 emit_diagnostic (diag_kind, loc, 0,
521 "invalid use of member %qD "
522 "(did you forget the %<&%> ?)", member);
524 break;
526 case TEMPLATE_TYPE_PARM:
527 if (is_auto (type))
528 emit_diagnostic (diag_kind, loc, 0,
529 "invalid use of %<auto%>");
530 else
531 emit_diagnostic (diag_kind, loc, 0,
532 "invalid use of template type parameter %qT", type);
533 break;
535 case BOUND_TEMPLATE_TEMPLATE_PARM:
536 emit_diagnostic (diag_kind, loc, 0,
537 "invalid use of template template parameter %qT",
538 TYPE_NAME (type));
539 break;
541 case TYPENAME_TYPE:
542 emit_diagnostic (diag_kind, loc, 0,
543 "invalid use of dependent type %qT", type);
544 break;
546 case LANG_TYPE:
547 if (type == init_list_type_node)
549 emit_diagnostic (diag_kind, loc, 0,
550 "invalid use of brace-enclosed initializer list");
551 break;
553 gcc_assert (type == unknown_type_node);
554 if (value && TREE_CODE (value) == COMPONENT_REF)
555 goto bad_member;
556 else if (value && TREE_CODE (value) == ADDR_EXPR)
557 emit_diagnostic (diag_kind, loc, 0,
558 "address of overloaded function with no contextual "
559 "type information");
560 else if (value && TREE_CODE (value) == OVERLOAD)
561 emit_diagnostic (diag_kind, loc, 0,
562 "overloaded function with no contextual type information");
563 else
564 emit_diagnostic (diag_kind, loc, 0,
565 "insufficient contextual information to determine type");
566 break;
568 default:
569 gcc_unreachable ();
573 /* Backward-compatibility interface to incomplete_type_diagnostic;
574 required by ../tree.c. */
575 #undef cxx_incomplete_type_error
576 void
577 cxx_incomplete_type_error (const_tree value, const_tree type)
579 cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
583 /* The recursive part of split_nonconstant_init. DEST is an lvalue
584 expression to which INIT should be assigned. INIT is a CONSTRUCTOR.
585 Return true if the whole of the value was initialized by the
586 generated statements. */
588 static bool
589 split_nonconstant_init_1 (tree dest, tree init)
591 unsigned HOST_WIDE_INT idx;
592 tree field_index, value;
593 tree type = TREE_TYPE (dest);
594 tree inner_type = NULL;
595 bool array_type_p = false;
596 bool complete_p = true;
597 HOST_WIDE_INT num_split_elts = 0;
599 switch (TREE_CODE (type))
601 case ARRAY_TYPE:
602 inner_type = TREE_TYPE (type);
603 array_type_p = true;
604 if ((TREE_SIDE_EFFECTS (init)
605 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
606 || array_of_runtime_bound_p (type))
608 /* For an array, we only need/want a single cleanup region rather
609 than one per element. */
610 tree code = build_vec_init (dest, NULL_TREE, init, false, 1,
611 tf_warning_or_error);
612 add_stmt (code);
613 return true;
615 /* FALLTHRU */
617 case RECORD_TYPE:
618 case UNION_TYPE:
619 case QUAL_UNION_TYPE:
620 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), idx,
621 field_index, value)
623 /* The current implementation of this algorithm assumes that
624 the field was set for all the elements. This is usually done
625 by process_init_constructor. */
626 gcc_assert (field_index);
628 if (!array_type_p)
629 inner_type = TREE_TYPE (field_index);
631 if (TREE_CODE (value) == CONSTRUCTOR)
633 tree sub;
635 if (array_type_p)
636 sub = build4 (ARRAY_REF, inner_type, dest, field_index,
637 NULL_TREE, NULL_TREE);
638 else
639 sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
640 NULL_TREE);
642 if (!split_nonconstant_init_1 (sub, value))
643 complete_p = false;
644 else
645 CONSTRUCTOR_ELTS (init)->ordered_remove (idx--);
646 num_split_elts++;
648 else if (!initializer_constant_valid_p (value, inner_type))
650 tree code;
651 tree sub;
653 /* FIXME: Ordered removal is O(1) so the whole function is
654 worst-case quadratic. This could be fixed using an aside
655 bitmap to record which elements must be removed and remove
656 them all at the same time. Or by merging
657 split_non_constant_init into process_init_constructor_array,
658 that is separating constants from non-constants while building
659 the vector. */
660 CONSTRUCTOR_ELTS (init)->ordered_remove (idx);
661 --idx;
663 if (TREE_CODE (field_index) == RANGE_EXPR)
665 /* Use build_vec_init to initialize a range. */
666 tree low = TREE_OPERAND (field_index, 0);
667 tree hi = TREE_OPERAND (field_index, 1);
668 sub = build4 (ARRAY_REF, inner_type, dest, low,
669 NULL_TREE, NULL_TREE);
670 sub = cp_build_addr_expr (sub, tf_warning_or_error);
671 tree max = size_binop (MINUS_EXPR, hi, low);
672 code = build_vec_init (sub, max, value, false, 0,
673 tf_warning_or_error);
674 add_stmt (code);
675 if (tree_fits_shwi_p (max))
676 num_split_elts += tree_to_shwi (max);
678 else
680 if (array_type_p)
681 sub = build4 (ARRAY_REF, inner_type, dest, field_index,
682 NULL_TREE, NULL_TREE);
683 else
684 sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
685 NULL_TREE);
687 code = build2 (INIT_EXPR, inner_type, sub, value);
688 code = build_stmt (input_location, EXPR_STMT, code);
689 code = maybe_cleanup_point_expr_void (code);
690 add_stmt (code);
691 if (type_build_dtor_call (inner_type))
693 code = (build_special_member_call
694 (sub, complete_dtor_identifier, NULL, inner_type,
695 LOOKUP_NORMAL, tf_warning_or_error));
696 if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (inner_type))
697 finish_eh_cleanup (code);
701 num_split_elts++;
704 break;
706 case VECTOR_TYPE:
707 if (!initializer_constant_valid_p (init, type))
709 tree code;
710 tree cons = copy_node (init);
711 CONSTRUCTOR_ELTS (init) = NULL;
712 code = build2 (MODIFY_EXPR, type, dest, cons);
713 code = build_stmt (input_location, EXPR_STMT, code);
714 add_stmt (code);
715 num_split_elts += CONSTRUCTOR_NELTS (init);
717 break;
719 default:
720 gcc_unreachable ();
723 /* The rest of the initializer is now a constant. */
724 TREE_CONSTANT (init) = 1;
725 return complete_p && complete_ctor_at_level_p (TREE_TYPE (init),
726 num_split_elts, inner_type);
729 /* A subroutine of store_init_value. Splits non-constant static
730 initializer INIT into a constant part and generates code to
731 perform the non-constant part of the initialization to DEST.
732 Returns the code for the runtime init. */
734 tree
735 split_nonconstant_init (tree dest, tree init)
737 tree code;
739 if (TREE_CODE (init) == TARGET_EXPR)
740 init = TARGET_EXPR_INITIAL (init);
741 if (TREE_CODE (init) == CONSTRUCTOR)
743 init = cp_fully_fold (init);
744 code = push_stmt_list ();
745 if (split_nonconstant_init_1 (dest, init))
746 init = NULL_TREE;
747 code = pop_stmt_list (code);
748 DECL_INITIAL (dest) = init;
749 TREE_READONLY (dest) = 0;
751 else
752 code = build2 (INIT_EXPR, TREE_TYPE (dest), dest, init);
754 return code;
757 /* Perform appropriate conversions on the initial value of a variable,
758 store it in the declaration DECL,
759 and print any error messages that are appropriate.
760 If the init is invalid, store an ERROR_MARK.
762 C++: Note that INIT might be a TREE_LIST, which would mean that it is
763 a base class initializer for some aggregate type, hopefully compatible
764 with DECL. If INIT is a single element, and DECL is an aggregate
765 type, we silently convert INIT into a TREE_LIST, allowing a constructor
766 to be called.
768 If INIT is a TREE_LIST and there is no constructor, turn INIT
769 into a CONSTRUCTOR and use standard initialization techniques.
770 Perhaps a warning should be generated?
772 Returns code to be executed if initialization could not be performed
773 for static variable. In that case, caller must emit the code. */
775 tree
776 store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
778 tree value, type;
780 /* If variable's type was invalidly declared, just ignore it. */
782 type = TREE_TYPE (decl);
783 if (TREE_CODE (type) == ERROR_MARK)
784 return NULL_TREE;
786 if (MAYBE_CLASS_TYPE_P (type))
788 if (TREE_CODE (init) == TREE_LIST)
790 error ("constructor syntax used, but no constructor declared "
791 "for type %qT", type);
792 init = build_constructor_from_list (init_list_type_node, nreverse (init));
796 /* End of special C++ code. */
798 if (flags & LOOKUP_ALREADY_DIGESTED)
799 value = init;
800 else
801 /* Digest the specified initializer into an expression. */
802 value = digest_init_flags (type, init, flags);
804 value = extend_ref_init_temps (decl, value, cleanups);
806 /* In C++11 constant expression is a semantic, not syntactic, property.
807 In C++98, make sure that what we thought was a constant expression at
808 template definition time is still constant and otherwise perform this
809 as optimization, e.g. to fold SIZEOF_EXPRs in the initializer. */
810 if (decl_maybe_constant_var_p (decl) || TREE_STATIC (decl))
812 bool const_init;
813 value = instantiate_non_dependent_expr (value);
814 if (DECL_DECLARED_CONSTEXPR_P (decl)
815 || DECL_IN_AGGR_P (decl))
817 /* Diagnose a non-constant initializer for constexpr. */
818 if (processing_template_decl
819 && !require_potential_constant_expression (value))
820 value = error_mark_node;
821 else
822 value = cxx_constant_value (value, decl);
824 value = maybe_constant_init (value, decl);
825 if (TREE_CODE (value) == CONSTRUCTOR && cp_has_mutable_p (type))
826 /* Poison this CONSTRUCTOR so it can't be copied to another
827 constexpr variable. */
828 CONSTRUCTOR_MUTABLE_POISON (value) = true;
829 const_init = (reduced_constant_expression_p (value)
830 || error_operand_p (value));
831 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init;
832 TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl);
834 value = cp_fully_fold (value);
836 if (cxx_dialect >= cxx14 && CLASS_TYPE_P (strip_array_types (type)))
837 /* Handle aggregate NSDMI in non-constant initializers, too. */
838 value = replace_placeholders (value, decl);
840 /* DECL may change value; purge caches. */
841 clear_cv_and_fold_caches ();
843 /* If the initializer is not a constant, fill in DECL_INITIAL with
844 the bits that are constant, and then return an expression that
845 will perform the dynamic initialization. */
846 if (value != error_mark_node
847 && (TREE_SIDE_EFFECTS (value)
848 || array_of_runtime_bound_p (type)
849 || ! reduced_constant_expression_p (value)))
850 return split_nonconstant_init (decl, value);
851 /* If the value is a constant, just put it in DECL_INITIAL. If DECL
852 is an automatic variable, the middle end will turn this into a
853 dynamic initialization later. */
854 DECL_INITIAL (decl) = value;
855 return NULL_TREE;
859 /* Give diagnostic about narrowing conversions within { }. */
861 bool
862 check_narrowing (tree type, tree init, tsubst_flags_t complain)
864 tree ftype = unlowered_expr_type (init);
865 bool ok = true;
866 REAL_VALUE_TYPE d;
868 if (((!warn_narrowing || !(complain & tf_warning))
869 && cxx_dialect == cxx98)
870 || !ARITHMETIC_TYPE_P (type))
871 return ok;
873 if (BRACE_ENCLOSED_INITIALIZER_P (init)
874 && TREE_CODE (type) == COMPLEX_TYPE)
876 tree elttype = TREE_TYPE (type);
877 if (CONSTRUCTOR_NELTS (init) > 0)
878 ok &= check_narrowing (elttype, CONSTRUCTOR_ELT (init, 0)->value,
879 complain);
880 if (CONSTRUCTOR_NELTS (init) > 1)
881 ok &= check_narrowing (elttype, CONSTRUCTOR_ELT (init, 1)->value,
882 complain);
883 return ok;
886 init = fold_non_dependent_expr (init);
888 if (TREE_CODE (type) == INTEGER_TYPE
889 && TREE_CODE (ftype) == REAL_TYPE)
890 ok = false;
891 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
892 && CP_INTEGRAL_TYPE_P (type))
894 if (TREE_CODE (ftype) == ENUMERAL_TYPE)
895 /* Check for narrowing based on the values of the enumeration. */
896 ftype = ENUM_UNDERLYING_TYPE (ftype);
897 if ((tree_int_cst_lt (TYPE_MAX_VALUE (type),
898 TYPE_MAX_VALUE (ftype))
899 || tree_int_cst_lt (TYPE_MIN_VALUE (ftype),
900 TYPE_MIN_VALUE (type)))
901 && (TREE_CODE (init) != INTEGER_CST
902 || !int_fits_type_p (init, type)))
903 ok = false;
905 else if (TREE_CODE (ftype) == REAL_TYPE
906 && TREE_CODE (type) == REAL_TYPE)
908 if (TYPE_PRECISION (type) < TYPE_PRECISION (ftype))
910 if (TREE_CODE (init) == REAL_CST)
912 /* Issue 703: Loss of precision is OK as long as the value is
913 within the representable range of the new type. */
914 REAL_VALUE_TYPE r;
915 d = TREE_REAL_CST (init);
916 real_convert (&r, TYPE_MODE (type), &d);
917 if (real_isinf (&r))
918 ok = false;
920 else
921 ok = false;
924 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
925 && TREE_CODE (type) == REAL_TYPE)
927 ok = false;
928 if (TREE_CODE (init) == INTEGER_CST)
930 d = real_value_from_int_cst (0, init);
931 if (exact_real_truncate (TYPE_MODE (type), &d))
932 ok = true;
936 bool almost_ok = ok;
937 if (!ok && !CONSTANT_CLASS_P (init) && (complain & tf_warning_or_error))
939 tree folded = cp_fully_fold (init);
940 if (TREE_CONSTANT (folded) && check_narrowing (type, folded, tf_none))
941 almost_ok = true;
944 if (!ok)
946 location_t loc = EXPR_LOC_OR_LOC (init, input_location);
947 if (cxx_dialect == cxx98)
949 if (complain & tf_warning)
950 warning_at (loc, OPT_Wnarrowing, "narrowing conversion of %qE "
951 "from %qT to %qT inside { } is ill-formed in C++11",
952 init, ftype, type);
953 ok = true;
955 else if (!CONSTANT_CLASS_P (init))
957 if (complain & tf_warning_or_error)
959 if (!almost_ok || pedantic)
960 pedwarn (loc, OPT_Wnarrowing, "narrowing conversion of %qE "
961 "from %qT to %qT inside { }", init, ftype, type);
962 if (pedantic && almost_ok)
963 inform (loc, " the expression has a constant value but is not "
964 "a C++ constant-expression");
965 ok = true;
968 else if (complain & tf_error)
970 int savederrorcount = errorcount;
971 global_dc->pedantic_errors = 1;
972 pedwarn (loc, OPT_Wnarrowing,
973 "narrowing conversion of %qE from %qT to %qT "
974 "inside { }", init, ftype, type);
975 if (errorcount == savederrorcount)
976 ok = true;
977 global_dc->pedantic_errors = flag_pedantic_errors;
981 return ok;
984 /* Process the initializer INIT for a variable of type TYPE, emitting
985 diagnostics for invalid initializers and converting the initializer as
986 appropriate.
988 For aggregate types, it assumes that reshape_init has already run, thus the
989 initializer will have the right shape (brace elision has been undone).
991 NESTED is true iff we are being called for an element of a CONSTRUCTOR. */
993 static tree
994 digest_init_r (tree type, tree init, bool nested, int flags,
995 tsubst_flags_t complain)
997 enum tree_code code = TREE_CODE (type);
999 if (error_operand_p (init))
1000 return error_mark_node;
1002 gcc_assert (init);
1004 /* We must strip the outermost array type when completing the type,
1005 because the its bounds might be incomplete at the moment. */
1006 if (!complete_type_or_maybe_complain (TREE_CODE (type) == ARRAY_TYPE
1007 ? TREE_TYPE (type) : type, NULL_TREE,
1008 complain))
1009 return error_mark_node;
1011 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue
1012 (g++.old-deja/g++.law/casts2.C). */
1013 if (TREE_CODE (init) == NON_LVALUE_EXPR)
1014 init = TREE_OPERAND (init, 0);
1016 /* Initialization of an array of chars from a string constant. The initializer
1017 can be optionally enclosed in braces, but reshape_init has already removed
1018 them if they were present. */
1019 if (code == ARRAY_TYPE)
1021 if (nested && !TYPE_DOMAIN (type))
1023 /* C++ flexible array members have a null domain. */
1024 pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wpedantic,
1025 "initialization of a flexible array member");
1028 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
1029 if (char_type_p (typ1)
1030 /*&& init */
1031 && TREE_CODE (init) == STRING_CST)
1033 tree char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
1035 if (TYPE_PRECISION (typ1) == BITS_PER_UNIT)
1037 if (char_type != char_type_node)
1039 if (complain & tf_error)
1040 error ("char-array initialized from wide string");
1041 return error_mark_node;
1044 else
1046 if (char_type == char_type_node)
1048 if (complain & tf_error)
1049 error ("int-array initialized from non-wide string");
1050 return error_mark_node;
1052 else if (char_type != typ1)
1054 if (complain & tf_error)
1055 error ("int-array initialized from incompatible "
1056 "wide string");
1057 return error_mark_node;
1061 if (type != TREE_TYPE (init))
1063 init = copy_node (init);
1064 TREE_TYPE (init) = type;
1066 if (TYPE_DOMAIN (type) && TREE_CONSTANT (TYPE_SIZE (type)))
1068 /* Not a flexible array member. */
1069 int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
1070 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
1071 /* In C it is ok to subtract 1 from the length of the string
1072 because it's ok to ignore the terminating null char that is
1073 counted in the length of the constant, but in C++ this would
1074 be invalid. */
1075 if (size < TREE_STRING_LENGTH (init))
1076 permerror (input_location, "initializer-string for array "
1077 "of chars is too long");
1079 return init;
1083 /* Handle scalar types (including conversions) and references. */
1084 if ((TREE_CODE (type) != COMPLEX_TYPE
1085 || BRACE_ENCLOSED_INITIALIZER_P (init))
1086 && (SCALAR_TYPE_P (type) || code == REFERENCE_TYPE))
1088 if (nested)
1089 flags |= LOOKUP_NO_NARROWING;
1090 init = convert_for_initialization (0, type, init, flags,
1091 ICR_INIT, NULL_TREE, 0,
1092 complain);
1094 return init;
1097 /* Come here only for aggregates: records, arrays, unions, complex numbers
1098 and vectors. */
1099 gcc_assert (TREE_CODE (type) == ARRAY_TYPE
1100 || VECTOR_TYPE_P (type)
1101 || TREE_CODE (type) == RECORD_TYPE
1102 || TREE_CODE (type) == UNION_TYPE
1103 || TREE_CODE (type) == COMPLEX_TYPE);
1105 /* "If T is a class type and the initializer list has a single
1106 element of type cv U, where U is T or a class derived from T,
1107 the object is initialized from that element." */
1108 if (flag_checking
1109 && cxx_dialect >= cxx11
1110 && BRACE_ENCLOSED_INITIALIZER_P (init)
1111 && CONSTRUCTOR_NELTS (init) == 1
1112 && ((CLASS_TYPE_P (type) && !CLASSTYPE_NON_AGGREGATE (type))
1113 || VECTOR_TYPE_P (type)))
1115 tree elt = CONSTRUCTOR_ELT (init, 0)->value;
1116 if (reference_related_p (type, TREE_TYPE (elt)))
1117 /* We should have fixed this in reshape_init. */
1118 gcc_unreachable ();
1121 if (BRACE_ENCLOSED_INITIALIZER_P (init)
1122 && !TYPE_NON_AGGREGATE_CLASS (type))
1123 return process_init_constructor (type, init, complain);
1124 else
1126 if (COMPOUND_LITERAL_P (init) && TREE_CODE (type) == ARRAY_TYPE)
1128 if (complain & tf_error)
1129 error ("cannot initialize aggregate of type %qT with "
1130 "a compound literal", type);
1132 return error_mark_node;
1135 if (TREE_CODE (type) == ARRAY_TYPE
1136 && !BRACE_ENCLOSED_INITIALIZER_P (init))
1138 /* Allow the result of build_array_copy and of
1139 build_value_init_noctor. */
1140 if ((TREE_CODE (init) == VEC_INIT_EXPR
1141 || TREE_CODE (init) == CONSTRUCTOR)
1142 && (same_type_ignoring_top_level_qualifiers_p
1143 (type, TREE_TYPE (init))))
1144 return init;
1146 if (complain & tf_error)
1147 error ("array must be initialized with a brace-enclosed"
1148 " initializer");
1149 return error_mark_node;
1152 return convert_for_initialization (NULL_TREE, type, init,
1153 flags,
1154 ICR_INIT, NULL_TREE, 0,
1155 complain);
1159 tree
1160 digest_init (tree type, tree init, tsubst_flags_t complain)
1162 return digest_init_r (type, init, false, LOOKUP_IMPLICIT, complain);
1165 tree
1166 digest_init_flags (tree type, tree init, int flags)
1168 return digest_init_r (type, init, false, flags, tf_warning_or_error);
1171 /* Process the initializer INIT for an NSDMI DECL (a FIELD_DECL). */
1172 tree
1173 digest_nsdmi_init (tree decl, tree init)
1175 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
1177 tree type = TREE_TYPE (decl);
1178 int flags = LOOKUP_IMPLICIT;
1179 if (DIRECT_LIST_INIT_P (init))
1180 flags = LOOKUP_NORMAL;
1181 if (BRACE_ENCLOSED_INITIALIZER_P (init)
1182 && CP_AGGREGATE_TYPE_P (type))
1183 init = reshape_init (type, init, tf_warning_or_error);
1184 init = digest_init_flags (type, init, flags);
1185 if (TREE_CODE (init) == TARGET_EXPR)
1186 /* This represents the whole initialization. */
1187 TARGET_EXPR_DIRECT_INIT_P (init) = true;
1188 return init;
1191 /* Set of flags used within process_init_constructor to describe the
1192 initializers. */
1193 #define PICFLAG_ERRONEOUS 1
1194 #define PICFLAG_NOT_ALL_CONSTANT 2
1195 #define PICFLAG_NOT_ALL_SIMPLE 4
1196 #define PICFLAG_SIDE_EFFECTS 8
1198 /* Given an initializer INIT, return the flag (PICFLAG_*) which better
1199 describe it. */
1201 static int
1202 picflag_from_initializer (tree init)
1204 if (init == error_mark_node)
1205 return PICFLAG_ERRONEOUS;
1206 else if (!TREE_CONSTANT (init))
1208 if (TREE_SIDE_EFFECTS (init))
1209 return PICFLAG_SIDE_EFFECTS;
1210 else
1211 return PICFLAG_NOT_ALL_CONSTANT;
1213 else if (!initializer_constant_valid_p (init, TREE_TYPE (init)))
1214 return PICFLAG_NOT_ALL_SIMPLE;
1215 return 0;
1218 /* Adjust INIT for going into a CONSTRUCTOR. */
1220 static tree
1221 massage_init_elt (tree type, tree init, tsubst_flags_t complain)
1223 init = digest_init_r (type, init, true, LOOKUP_IMPLICIT, complain);
1224 /* Strip a simple TARGET_EXPR when we know this is an initializer. */
1225 if (SIMPLE_TARGET_EXPR_P (init))
1226 init = TARGET_EXPR_INITIAL (init);
1227 /* When we defer constant folding within a statement, we may want to
1228 defer this folding as well. */
1229 tree t = fold_non_dependent_expr (init);
1230 t = maybe_constant_init (t);
1231 if (TREE_CONSTANT (t))
1232 init = t;
1233 return init;
1236 /* Subroutine of process_init_constructor, which will process an initializer
1237 INIT for an array or vector of type TYPE. Returns the flags (PICFLAG_*)
1238 which describe the initializers. */
1240 static int
1241 process_init_constructor_array (tree type, tree init,
1242 tsubst_flags_t complain)
1244 unsigned HOST_WIDE_INT i, len = 0;
1245 int flags = 0;
1246 bool unbounded = false;
1247 constructor_elt *ce;
1248 vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (init);
1250 gcc_assert (TREE_CODE (type) == ARRAY_TYPE
1251 || VECTOR_TYPE_P (type));
1253 if (TREE_CODE (type) == ARRAY_TYPE)
1255 /* C++ flexible array members have a null domain. */
1256 tree domain = TYPE_DOMAIN (type);
1257 if (domain && TREE_CONSTANT (TYPE_MAX_VALUE (domain)))
1258 len = wi::ext (wi::to_offset (TYPE_MAX_VALUE (domain))
1259 - wi::to_offset (TYPE_MIN_VALUE (domain)) + 1,
1260 TYPE_PRECISION (TREE_TYPE (domain)),
1261 TYPE_SIGN (TREE_TYPE (domain))).to_uhwi ();
1262 else
1263 unbounded = true; /* Take as many as there are. */
1265 else
1266 /* Vectors are like simple fixed-size arrays. */
1267 len = TYPE_VECTOR_SUBPARTS (type);
1269 /* There must not be more initializers than needed. */
1270 if (!unbounded && vec_safe_length (v) > len)
1272 if (complain & tf_error)
1273 error ("too many initializers for %qT", type);
1274 else
1275 return PICFLAG_ERRONEOUS;
1278 FOR_EACH_VEC_SAFE_ELT (v, i, ce)
1280 if (ce->index)
1282 gcc_assert (TREE_CODE (ce->index) == INTEGER_CST);
1283 if (compare_tree_int (ce->index, i) != 0)
1285 ce->value = error_mark_node;
1286 sorry ("non-trivial designated initializers not supported");
1289 else
1290 ce->index = size_int (i);
1291 gcc_assert (ce->value);
1292 ce->value = massage_init_elt (TREE_TYPE (type), ce->value, complain);
1294 if (ce->value != error_mark_node)
1295 gcc_assert (same_type_ignoring_top_level_qualifiers_p
1296 (TREE_TYPE (type), TREE_TYPE (ce->value)));
1298 flags |= picflag_from_initializer (ce->value);
1301 /* No more initializers. If the array is unbounded, we are done. Otherwise,
1302 we must add initializers ourselves. */
1303 if (!unbounded)
1304 for (; i < len; ++i)
1306 tree next;
1308 if (type_build_ctor_call (TREE_TYPE (type)))
1310 /* If this type needs constructors run for default-initialization,
1311 we can't rely on the back end to do it for us, so make the
1312 initialization explicit by list-initializing from T{}. */
1313 next = build_constructor (init_list_type_node, NULL);
1314 next = massage_init_elt (TREE_TYPE (type), next, complain);
1315 if (initializer_zerop (next))
1316 /* The default zero-initialization is fine for us; don't
1317 add anything to the CONSTRUCTOR. */
1318 next = NULL_TREE;
1320 else if (!zero_init_p (TREE_TYPE (type)))
1321 next = build_zero_init (TREE_TYPE (type),
1322 /*nelts=*/NULL_TREE,
1323 /*static_storage_p=*/false);
1324 else
1325 /* The default zero-initialization is fine for us; don't
1326 add anything to the CONSTRUCTOR. */
1327 next = NULL_TREE;
1329 if (next)
1331 flags |= picflag_from_initializer (next);
1332 CONSTRUCTOR_APPEND_ELT (v, size_int (i), next);
1336 CONSTRUCTOR_ELTS (init) = v;
1337 return flags;
1340 /* Subroutine of process_init_constructor, which will process an initializer
1341 INIT for a class of type TYPE. Returns the flags (PICFLAG_*) which describe
1342 the initializers. */
1344 static int
1345 process_init_constructor_record (tree type, tree init,
1346 tsubst_flags_t complain)
1348 vec<constructor_elt, va_gc> *v = NULL;
1349 tree field;
1350 int skipped = 0;
1352 gcc_assert (TREE_CODE (type) == RECORD_TYPE);
1353 gcc_assert (!CLASSTYPE_VBASECLASSES (type));
1354 gcc_assert (!TYPE_BINFO (type)
1355 || !BINFO_N_BASE_BINFOS (TYPE_BINFO (type)));
1356 gcc_assert (!TYPE_POLYMORPHIC_P (type));
1358 restart:
1359 int flags = 0;
1360 unsigned HOST_WIDE_INT idx = 0;
1361 /* Generally, we will always have an index for each initializer (which is
1362 a FIELD_DECL, put by reshape_init), but compound literals don't go trough
1363 reshape_init. So we need to handle both cases. */
1364 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
1366 tree next;
1367 tree type;
1369 if (!DECL_NAME (field) && DECL_C_BIT_FIELD (field))
1370 continue;
1372 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
1373 continue;
1375 /* If this is a bitfield, first convert to the declared type. */
1376 type = TREE_TYPE (field);
1377 if (DECL_BIT_FIELD_TYPE (field))
1378 type = DECL_BIT_FIELD_TYPE (field);
1379 if (type == error_mark_node)
1380 return PICFLAG_ERRONEOUS;
1382 if (idx < vec_safe_length (CONSTRUCTOR_ELTS (init)))
1384 constructor_elt *ce = &(*CONSTRUCTOR_ELTS (init))[idx];
1385 if (ce->index)
1387 /* We can have either a FIELD_DECL or an IDENTIFIER_NODE. The
1388 latter case can happen in templates where lookup has to be
1389 deferred. */
1390 gcc_assert (TREE_CODE (ce->index) == FIELD_DECL
1391 || identifier_p (ce->index));
1392 if (ce->index != field
1393 && ce->index != DECL_NAME (field))
1395 ce->value = error_mark_node;
1396 sorry ("non-trivial designated initializers not supported");
1400 gcc_assert (ce->value);
1401 next = massage_init_elt (type, ce->value, complain);
1402 ++idx;
1404 else if (DECL_INITIAL (field))
1406 if (skipped > 0)
1408 /* We're using an NSDMI past a field with implicit
1409 zero-init. Go back and make it explicit. */
1410 skipped = -1;
1411 vec_safe_truncate (v, 0);
1412 goto restart;
1414 /* C++14 aggregate NSDMI. */
1415 next = get_nsdmi (field, /*ctor*/false);
1417 else if (type_build_ctor_call (TREE_TYPE (field)))
1419 /* If this type needs constructors run for
1420 default-initialization, we can't rely on the back end to do it
1421 for us, so build up TARGET_EXPRs. If the type in question is
1422 a class, just build one up; if it's an array, recurse. */
1423 next = build_constructor (init_list_type_node, NULL);
1424 next = massage_init_elt (TREE_TYPE (field), next, complain);
1426 /* Warn when some struct elements are implicitly initialized. */
1427 if ((complain & tf_warning)
1428 && !EMPTY_CONSTRUCTOR_P (init))
1429 warning (OPT_Wmissing_field_initializers,
1430 "missing initializer for member %qD", field);
1432 else
1434 const_tree fldtype = TREE_TYPE (field);
1435 if (TREE_CODE (fldtype) == REFERENCE_TYPE)
1437 if (complain & tf_error)
1438 error ("member %qD is uninitialized reference", field);
1439 else
1440 return PICFLAG_ERRONEOUS;
1442 else if (CLASSTYPE_REF_FIELDS_NEED_INIT (fldtype))
1444 if (complain & tf_error)
1445 error ("member %qD with uninitialized reference fields", field);
1446 else
1447 return PICFLAG_ERRONEOUS;
1450 /* Warn when some struct elements are implicitly initialized
1451 to zero. However, avoid issuing the warning for flexible
1452 array members since they need not have any elements. */
1453 if ((TREE_CODE (fldtype) != ARRAY_TYPE || TYPE_DOMAIN (fldtype))
1454 && (complain & tf_warning)
1455 && !EMPTY_CONSTRUCTOR_P (init))
1456 warning (OPT_Wmissing_field_initializers,
1457 "missing initializer for member %qD", field);
1459 if (!zero_init_p (fldtype)
1460 || skipped < 0)
1461 next = build_zero_init (TREE_TYPE (field), /*nelts=*/NULL_TREE,
1462 /*static_storage_p=*/false);
1463 else
1465 /* The default zero-initialization is fine for us; don't
1466 add anything to the CONSTRUCTOR. */
1467 skipped = 1;
1468 continue;
1472 /* If this is a bitfield, now convert to the lowered type. */
1473 if (type != TREE_TYPE (field))
1474 next = cp_convert_and_check (TREE_TYPE (field), next, complain);
1475 flags |= picflag_from_initializer (next);
1476 CONSTRUCTOR_APPEND_ELT (v, field, next);
1479 if (idx < vec_safe_length (CONSTRUCTOR_ELTS (init)))
1481 if (complain & tf_error)
1482 error ("too many initializers for %qT", type);
1483 else
1484 return PICFLAG_ERRONEOUS;
1487 CONSTRUCTOR_ELTS (init) = v;
1488 return flags;
1491 /* Subroutine of process_init_constructor, which will process a single
1492 initializer INIT for a union of type TYPE. Returns the flags (PICFLAG_*)
1493 which describe the initializer. */
1495 static int
1496 process_init_constructor_union (tree type, tree init,
1497 tsubst_flags_t complain)
1499 constructor_elt *ce;
1500 int len;
1502 /* If the initializer was empty, use default zero initialization. */
1503 if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
1504 return 0;
1506 len = CONSTRUCTOR_ELTS (init)->length ();
1507 if (len > 1)
1509 if (!(complain & tf_error))
1510 return PICFLAG_ERRONEOUS;
1511 error ("too many initializers for %qT", type);
1512 CONSTRUCTOR_ELTS (init)->block_remove (1, len-1);
1515 ce = &(*CONSTRUCTOR_ELTS (init))[0];
1517 /* If this element specifies a field, initialize via that field. */
1518 if (ce->index)
1520 if (TREE_CODE (ce->index) == FIELD_DECL)
1522 else if (identifier_p (ce->index))
1524 /* This can happen within a cast, see g++.dg/opt/cse2.C. */
1525 tree name = ce->index;
1526 tree field;
1527 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1528 if (DECL_NAME (field) == name)
1529 break;
1530 if (!field)
1532 if (complain & tf_error)
1533 error ("no field %qD found in union being initialized",
1534 field);
1535 ce->value = error_mark_node;
1537 ce->index = field;
1539 else
1541 gcc_assert (TREE_CODE (ce->index) == INTEGER_CST
1542 || TREE_CODE (ce->index) == RANGE_EXPR);
1543 if (complain & tf_error)
1544 error ("index value instead of field name in union initializer");
1545 ce->value = error_mark_node;
1548 else
1550 /* Find the first named field. ANSI decided in September 1990
1551 that only named fields count here. */
1552 tree field = TYPE_FIELDS (type);
1553 while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
1554 field = TREE_CHAIN (field);
1555 if (field == NULL_TREE)
1557 if (complain & tf_error)
1558 error ("too many initializers for %qT", type);
1559 ce->value = error_mark_node;
1561 ce->index = field;
1564 if (ce->value && ce->value != error_mark_node)
1565 ce->value = massage_init_elt (TREE_TYPE (ce->index), ce->value, complain);
1567 return picflag_from_initializer (ce->value);
1570 /* Process INIT, a constructor for a variable of aggregate type TYPE. The
1571 constructor is a brace-enclosed initializer, and will be modified in-place.
1573 Each element is converted to the right type through digest_init, and
1574 missing initializers are added following the language rules (zero-padding,
1575 etc.).
1577 After the execution, the initializer will have TREE_CONSTANT if all elts are
1578 constant, and TREE_STATIC set if, in addition, all elts are simple enough
1579 constants that the assembler and linker can compute them.
1581 The function returns the initializer itself, or error_mark_node in case
1582 of error. */
1584 static tree
1585 process_init_constructor (tree type, tree init, tsubst_flags_t complain)
1587 int flags;
1589 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
1591 if (TREE_CODE (type) == ARRAY_TYPE || VECTOR_TYPE_P (type))
1592 flags = process_init_constructor_array (type, init, complain);
1593 else if (TREE_CODE (type) == RECORD_TYPE)
1594 flags = process_init_constructor_record (type, init, complain);
1595 else if (TREE_CODE (type) == UNION_TYPE)
1596 flags = process_init_constructor_union (type, init, complain);
1597 else
1598 gcc_unreachable ();
1600 if (flags & PICFLAG_ERRONEOUS)
1601 return error_mark_node;
1603 TREE_TYPE (init) = type;
1604 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE)
1605 cp_complete_array_type (&TREE_TYPE (init), init, /*do_default=*/0);
1606 if (flags & PICFLAG_SIDE_EFFECTS)
1608 TREE_CONSTANT (init) = false;
1609 TREE_SIDE_EFFECTS (init) = true;
1611 else if (flags & PICFLAG_NOT_ALL_CONSTANT)
1612 /* Make sure TREE_CONSTANT isn't set from build_constructor. */
1613 TREE_CONSTANT (init) = false;
1614 else
1616 TREE_CONSTANT (init) = 1;
1617 if (!(flags & PICFLAG_NOT_ALL_SIMPLE))
1618 TREE_STATIC (init) = 1;
1620 return init;
1623 /* Given a structure or union value DATUM, construct and return
1624 the structure or union component which results from narrowing
1625 that value to the base specified in BASETYPE. For example, given the
1626 hierarchy
1628 class L { int ii; };
1629 class A : L { ... };
1630 class B : L { ... };
1631 class C : A, B { ... };
1633 and the declaration
1635 C x;
1637 then the expression
1639 x.A::ii refers to the ii member of the L part of
1640 the A part of the C object named by X. In this case,
1641 DATUM would be x, and BASETYPE would be A.
1643 I used to think that this was nonconformant, that the standard specified
1644 that first we look up ii in A, then convert x to an L& and pull out the
1645 ii part. But in fact, it does say that we convert x to an A&; A here
1646 is known as the "naming class". (jason 2000-12-19)
1648 BINFO_P points to a variable initialized either to NULL_TREE or to the
1649 binfo for the specific base subobject we want to convert to. */
1651 tree
1652 build_scoped_ref (tree datum, tree basetype, tree* binfo_p)
1654 tree binfo;
1656 if (datum == error_mark_node)
1657 return error_mark_node;
1658 if (*binfo_p)
1659 binfo = *binfo_p;
1660 else
1661 binfo = lookup_base (TREE_TYPE (datum), basetype, ba_check,
1662 NULL, tf_warning_or_error);
1664 if (!binfo || binfo == error_mark_node)
1666 *binfo_p = NULL_TREE;
1667 if (!binfo)
1668 error_not_base_type (basetype, TREE_TYPE (datum));
1669 return error_mark_node;
1672 *binfo_p = binfo;
1673 return build_base_path (PLUS_EXPR, datum, binfo, 1,
1674 tf_warning_or_error);
1677 /* Build a reference to an object specified by the C++ `->' operator.
1678 Usually this just involves dereferencing the object, but if the
1679 `->' operator is overloaded, then such overloads must be
1680 performed until an object which does not have the `->' operator
1681 overloaded is found. An error is reported when circular pointer
1682 delegation is detected. */
1684 tree
1685 build_x_arrow (location_t loc, tree expr, tsubst_flags_t complain)
1687 tree orig_expr = expr;
1688 tree type = TREE_TYPE (expr);
1689 tree last_rval = NULL_TREE;
1690 vec<tree, va_gc> *types_memoized = NULL;
1692 if (type == error_mark_node)
1693 return error_mark_node;
1695 if (processing_template_decl)
1697 if (type && TREE_CODE (type) == POINTER_TYPE
1698 && !dependent_scope_p (TREE_TYPE (type)))
1699 /* Pointer to current instantiation, don't treat as dependent. */;
1700 else if (type_dependent_expression_p (expr))
1701 return build_min_nt_loc (loc, ARROW_EXPR, expr);
1702 expr = build_non_dependent_expr (expr);
1705 if (MAYBE_CLASS_TYPE_P (type))
1707 struct tinst_level *actual_inst = current_instantiation ();
1708 tree fn = NULL;
1710 while ((expr = build_new_op (loc, COMPONENT_REF,
1711 LOOKUP_NORMAL, expr, NULL_TREE, NULL_TREE,
1712 &fn, complain)))
1714 if (expr == error_mark_node)
1715 return error_mark_node;
1717 /* This provides a better instantiation backtrace in case of
1718 error. */
1719 if (fn && DECL_USE_TEMPLATE (fn))
1720 push_tinst_level_loc (fn,
1721 (current_instantiation () != actual_inst)
1722 ? DECL_SOURCE_LOCATION (fn)
1723 : input_location);
1724 fn = NULL;
1726 if (vec_member (TREE_TYPE (expr), types_memoized))
1728 if (complain & tf_error)
1729 error ("circular pointer delegation detected");
1730 return error_mark_node;
1733 vec_safe_push (types_memoized, TREE_TYPE (expr));
1734 last_rval = expr;
1737 while (current_instantiation () != actual_inst)
1738 pop_tinst_level ();
1740 if (last_rval == NULL_TREE)
1742 if (complain & tf_error)
1743 error ("base operand of %<->%> has non-pointer type %qT", type);
1744 return error_mark_node;
1747 if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE)
1748 last_rval = convert_from_reference (last_rval);
1750 else
1751 last_rval = decay_conversion (expr, complain);
1753 if (TYPE_PTR_P (TREE_TYPE (last_rval)))
1755 if (processing_template_decl)
1757 expr = build_min (ARROW_EXPR, TREE_TYPE (TREE_TYPE (last_rval)),
1758 orig_expr);
1759 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (last_rval);
1760 return expr;
1763 return cp_build_indirect_ref (last_rval, RO_NULL, complain);
1766 if (complain & tf_error)
1768 if (types_memoized)
1769 error ("result of %<operator->()%> yields non-pointer result");
1770 else
1771 error ("base operand of %<->%> is not a pointer");
1773 return error_mark_node;
1776 /* Return an expression for "DATUM .* COMPONENT". DATUM has not
1777 already been checked out to be of aggregate type. */
1779 tree
1780 build_m_component_ref (tree datum, tree component, tsubst_flags_t complain)
1782 tree ptrmem_type;
1783 tree objtype;
1784 tree type;
1785 tree binfo;
1786 tree ctype;
1788 if (error_operand_p (datum) || error_operand_p (component))
1789 return error_mark_node;
1791 datum = mark_lvalue_use (datum);
1792 component = mark_rvalue_use (component);
1794 ptrmem_type = TREE_TYPE (component);
1795 if (!TYPE_PTRMEM_P (ptrmem_type))
1797 if (complain & tf_error)
1798 error ("%qE cannot be used as a member pointer, since it is of "
1799 "type %qT", component, ptrmem_type);
1800 return error_mark_node;
1803 objtype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));
1804 if (! MAYBE_CLASS_TYPE_P (objtype))
1806 if (complain & tf_error)
1807 error ("cannot apply member pointer %qE to %qE, which is of "
1808 "non-class type %qT", component, datum, objtype);
1809 return error_mark_node;
1812 type = TYPE_PTRMEM_POINTED_TO_TYPE (ptrmem_type);
1813 ctype = complete_type (TYPE_PTRMEM_CLASS_TYPE (ptrmem_type));
1815 if (!COMPLETE_TYPE_P (ctype))
1817 if (!same_type_p (ctype, objtype))
1818 goto mismatch;
1819 binfo = NULL;
1821 else
1823 binfo = lookup_base (objtype, ctype, ba_check, NULL, complain);
1825 if (!binfo)
1827 mismatch:
1828 if (complain & tf_error)
1829 error ("pointer to member type %qT incompatible with object "
1830 "type %qT", type, objtype);
1831 return error_mark_node;
1833 else if (binfo == error_mark_node)
1834 return error_mark_node;
1837 if (TYPE_PTRDATAMEM_P (ptrmem_type))
1839 cp_lvalue_kind kind = lvalue_kind (datum);
1840 tree ptype;
1842 /* Compute the type of the field, as described in [expr.ref].
1843 There's no such thing as a mutable pointer-to-member, so
1844 things are not as complex as they are for references to
1845 non-static data members. */
1846 type = cp_build_qualified_type (type,
1847 (cp_type_quals (type)
1848 | cp_type_quals (TREE_TYPE (datum))));
1850 datum = build_address (datum);
1852 /* Convert object to the correct base. */
1853 if (binfo)
1855 datum = build_base_path (PLUS_EXPR, datum, binfo, 1, complain);
1856 if (datum == error_mark_node)
1857 return error_mark_node;
1860 /* Build an expression for "object + offset" where offset is the
1861 value stored in the pointer-to-data-member. */
1862 ptype = build_pointer_type (type);
1863 datum = fold_build_pointer_plus (fold_convert (ptype, datum), component);
1864 datum = cp_build_indirect_ref (datum, RO_NULL, complain);
1865 if (datum == error_mark_node)
1866 return error_mark_node;
1868 /* If the object expression was an rvalue, return an rvalue. */
1869 if (kind & clk_class)
1870 datum = rvalue (datum);
1871 else if (kind & clk_rvalueref)
1872 datum = move (datum);
1873 return datum;
1875 else
1877 /* 5.5/6: In a .* expression whose object expression is an rvalue, the
1878 program is ill-formed if the second operand is a pointer to member
1879 function with ref-qualifier &. In a .* expression whose object
1880 expression is an lvalue, the program is ill-formed if the second
1881 operand is a pointer to member function with ref-qualifier &&. */
1882 if (FUNCTION_REF_QUALIFIED (type))
1884 bool lval = real_lvalue_p (datum);
1885 if (lval && FUNCTION_RVALUE_QUALIFIED (type))
1887 if (complain & tf_error)
1888 error ("pointer-to-member-function type %qT requires an rvalue",
1889 ptrmem_type);
1890 return error_mark_node;
1892 else if (!lval && !FUNCTION_RVALUE_QUALIFIED (type))
1894 if (complain & tf_error)
1895 error ("pointer-to-member-function type %qT requires an lvalue",
1896 ptrmem_type);
1897 return error_mark_node;
1900 return build2 (OFFSET_REF, type, datum, component);
1904 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
1906 tree
1907 build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
1909 /* This is either a call to a constructor,
1910 or a C cast in C++'s `functional' notation. */
1912 /* The type to which we are casting. */
1913 tree type;
1914 vec<tree, va_gc> *parmvec;
1916 if (error_operand_p (exp) || parms == error_mark_node)
1917 return error_mark_node;
1919 if (TREE_CODE (exp) == TYPE_DECL)
1921 type = TREE_TYPE (exp);
1923 if (complain & tf_warning
1924 && TREE_DEPRECATED (type)
1925 && DECL_ARTIFICIAL (exp))
1926 warn_deprecated_use (type, NULL_TREE);
1928 else
1929 type = exp;
1931 /* We need to check this explicitly, since value-initialization of
1932 arrays is allowed in other situations. */
1933 if (TREE_CODE (type) == ARRAY_TYPE)
1935 if (complain & tf_error)
1936 error ("functional cast to array type %qT", type);
1937 return error_mark_node;
1940 if (type_uses_auto (type))
1942 if (complain & tf_error)
1943 error ("invalid use of %<auto%>");
1944 return error_mark_node;
1947 if (processing_template_decl)
1949 tree t;
1951 /* Diagnose this even in a template. We could also try harder
1952 to give all the usual errors when the type and args are
1953 non-dependent... */
1954 if (TREE_CODE (type) == REFERENCE_TYPE && !parms)
1956 if (complain & tf_error)
1957 error ("invalid value-initialization of reference type");
1958 return error_mark_node;
1961 t = build_min (CAST_EXPR, type, parms);
1962 /* We don't know if it will or will not have side effects. */
1963 TREE_SIDE_EFFECTS (t) = 1;
1964 return t;
1967 if (! MAYBE_CLASS_TYPE_P (type))
1969 if (parms == NULL_TREE)
1971 if (VOID_TYPE_P (type))
1972 return void_node;
1973 return build_value_init (cv_unqualified (type), complain);
1976 /* This must build a C cast. */
1977 parms = build_x_compound_expr_from_list (parms, ELK_FUNC_CAST, complain);
1978 return cp_build_c_cast (type, parms, complain);
1981 /* Prepare to evaluate as a call to a constructor. If this expression
1982 is actually used, for example,
1984 return X (arg1, arg2, ...);
1986 then the slot being initialized will be filled in. */
1988 if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
1989 return error_mark_node;
1990 if (abstract_virtuals_error_sfinae (ACU_CAST, type, complain))
1991 return error_mark_node;
1993 /* [expr.type.conv]
1995 If the expression list is a single-expression, the type
1996 conversion is equivalent (in definedness, and if defined in
1997 meaning) to the corresponding cast expression. */
1998 if (parms && TREE_CHAIN (parms) == NULL_TREE)
1999 return cp_build_c_cast (type, TREE_VALUE (parms), complain);
2001 /* [expr.type.conv]
2003 The expression T(), where T is a simple-type-specifier for a
2004 non-array complete object type or the (possibly cv-qualified)
2005 void type, creates an rvalue of the specified type, which is
2006 value-initialized. */
2008 if (parms == NULL_TREE)
2010 exp = build_value_init (type, complain);
2011 exp = get_target_expr_sfinae (exp, complain);
2012 return exp;
2015 /* Call the constructor. */
2016 parmvec = make_tree_vector ();
2017 for (; parms != NULL_TREE; parms = TREE_CHAIN (parms))
2018 vec_safe_push (parmvec, TREE_VALUE (parms));
2019 exp = build_special_member_call (NULL_TREE, complete_ctor_identifier,
2020 &parmvec, type, LOOKUP_NORMAL, complain);
2021 release_tree_vector (parmvec);
2023 if (exp == error_mark_node)
2024 return error_mark_node;
2026 return build_cplus_new (type, exp, complain);
2030 /* Add new exception specifier SPEC, to the LIST we currently have.
2031 If it's already in LIST then do nothing.
2032 Moan if it's bad and we're allowed to. COMPLAIN < 0 means we
2033 know what we're doing. */
2035 tree
2036 add_exception_specifier (tree list, tree spec, int complain)
2038 bool ok;
2039 tree core = spec;
2040 bool is_ptr;
2041 diagnostic_t diag_type = DK_UNSPECIFIED; /* none */
2043 if (spec == error_mark_node)
2044 return list;
2046 gcc_assert (spec && (!list || TREE_VALUE (list)));
2048 /* [except.spec] 1, type in an exception specifier shall not be
2049 incomplete, or pointer or ref to incomplete other than pointer
2050 to cv void. */
2051 is_ptr = TYPE_PTR_P (core);
2052 if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE)
2053 core = TREE_TYPE (core);
2054 if (complain < 0)
2055 ok = true;
2056 else if (VOID_TYPE_P (core))
2057 ok = is_ptr;
2058 else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM)
2059 ok = true;
2060 else if (processing_template_decl)
2061 ok = true;
2062 else
2064 ok = true;
2065 /* 15.4/1 says that types in an exception specifier must be complete,
2066 but it seems more reasonable to only require this on definitions
2067 and calls. So just give a pedwarn at this point; we will give an
2068 error later if we hit one of those two cases. */
2069 if (!COMPLETE_TYPE_P (complete_type (core)))
2070 diag_type = DK_PEDWARN; /* pedwarn */
2073 if (ok)
2075 tree probe;
2077 for (probe = list; probe; probe = TREE_CHAIN (probe))
2078 if (same_type_p (TREE_VALUE (probe), spec))
2079 break;
2080 if (!probe)
2081 list = tree_cons (NULL_TREE, spec, list);
2083 else
2084 diag_type = DK_ERROR; /* error */
2086 if (diag_type != DK_UNSPECIFIED
2087 && (complain & tf_warning_or_error))
2088 cxx_incomplete_type_diagnostic (NULL_TREE, core, diag_type);
2090 return list;
2093 /* Like nothrow_spec_p, but don't abort on deferred noexcept. */
2095 static bool
2096 nothrow_spec_p_uninst (const_tree spec)
2098 if (DEFERRED_NOEXCEPT_SPEC_P (spec))
2099 return false;
2100 return nothrow_spec_p (spec);
2103 /* Combine the two exceptions specifier lists LIST and ADD, and return
2104 their union. */
2106 tree
2107 merge_exception_specifiers (tree list, tree add)
2109 tree noex, orig_list;
2111 /* No exception-specifier or noexcept(false) are less strict than
2112 anything else. Prefer the newer variant (LIST). */
2113 if (!list || list == noexcept_false_spec)
2114 return list;
2115 else if (!add || add == noexcept_false_spec)
2116 return add;
2118 /* noexcept(true) and throw() are stricter than anything else.
2119 As above, prefer the more recent one (LIST). */
2120 if (nothrow_spec_p_uninst (add))
2121 return list;
2123 /* Two implicit noexcept specs (e.g. on a destructor) are equivalent. */
2124 if (UNEVALUATED_NOEXCEPT_SPEC_P (add)
2125 && UNEVALUATED_NOEXCEPT_SPEC_P (list))
2126 return list;
2127 /* We should have instantiated other deferred noexcept specs by now. */
2128 gcc_assert (!DEFERRED_NOEXCEPT_SPEC_P (add));
2130 if (nothrow_spec_p_uninst (list))
2131 return add;
2132 noex = TREE_PURPOSE (list);
2133 gcc_checking_assert (!TREE_PURPOSE (add)
2134 || errorcount
2135 || cp_tree_equal (noex, TREE_PURPOSE (add)));
2137 /* Combine the dynamic-exception-specifiers, if any. */
2138 orig_list = list;
2139 for (; add && TREE_VALUE (add); add = TREE_CHAIN (add))
2141 tree spec = TREE_VALUE (add);
2142 tree probe;
2144 for (probe = orig_list; probe && TREE_VALUE (probe);
2145 probe = TREE_CHAIN (probe))
2146 if (same_type_p (TREE_VALUE (probe), spec))
2147 break;
2148 if (!probe)
2150 spec = build_tree_list (NULL_TREE, spec);
2151 TREE_CHAIN (spec) = list;
2152 list = spec;
2156 /* Keep the noexcept-specifier at the beginning of the list. */
2157 if (noex != TREE_PURPOSE (list))
2158 list = tree_cons (noex, TREE_VALUE (list), TREE_CHAIN (list));
2160 return list;
2163 /* Subroutine of build_call. Ensure that each of the types in the
2164 exception specification is complete. Technically, 15.4/1 says that
2165 they need to be complete when we see a declaration of the function,
2166 but we should be able to get away with only requiring this when the
2167 function is defined or called. See also add_exception_specifier. */
2169 void
2170 require_complete_eh_spec_types (tree fntype, tree decl)
2172 tree raises;
2173 /* Don't complain about calls to op new. */
2174 if (decl && DECL_ARTIFICIAL (decl))
2175 return;
2176 for (raises = TYPE_RAISES_EXCEPTIONS (fntype); raises;
2177 raises = TREE_CHAIN (raises))
2179 tree type = TREE_VALUE (raises);
2180 if (type && !COMPLETE_TYPE_P (type))
2182 if (decl)
2183 error
2184 ("call to function %qD which throws incomplete type %q#T",
2185 decl, type);
2186 else
2187 error ("call to function which throws incomplete type %q#T",
2188 decl);
2194 #include "gt-cp-typeck2.h"