1 /* Report error messages, build initializers, and perform
2 some front-end optimizations for C++ compiler.
3 Copyright (C) 1987-2018 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)
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. */
30 #include "coretypes.h"
32 #include "stor-layout.h"
37 process_init_constructor (tree type
, tree init
, int nested
,
38 tsubst_flags_t complain
);
41 /* Print an error message stemming from an attempt to use
42 BASETYPE as a base class for TYPE. */
45 error_not_base_type (tree basetype
, tree type
)
47 if (TREE_CODE (basetype
) == FUNCTION_DECL
)
48 basetype
= DECL_CONTEXT (basetype
);
49 error ("type %qT is not a base type for type %qT", basetype
, type
);
50 return error_mark_node
;
54 binfo_or_else (tree base
, tree type
)
56 tree binfo
= lookup_base (type
, base
, ba_unique
,
57 NULL
, tf_warning_or_error
);
59 if (binfo
== error_mark_node
)
62 error_not_base_type (base
, type
);
66 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
67 value may not be changed thereafter. */
70 cxx_readonly_error (location_t loc
, tree arg
, enum lvalue_use errstring
)
73 /* This macro is used to emit diagnostics to ensure that all format
74 strings are complete sentences, visible to gettext and checked at
77 #define ERROR_FOR_ASSIGNMENT(LOC, AS, ASM, IN, DE, ARG) \
82 error_at (LOC, AS, ARG); \
85 error_at (LOC, ASM, ARG); \
88 error_at (LOC, IN, ARG); \
91 error_at (LOC, DE, ARG); \
98 /* Handle C++-specific things first. */
101 && DECL_LANG_SPECIFIC (arg
)
102 && DECL_IN_AGGR_P (arg
)
103 && !TREE_STATIC (arg
))
104 ERROR_FOR_ASSIGNMENT (loc
,
105 G_("assignment of constant field %qD"),
106 G_("constant field %qD used as %<asm%> output"),
107 G_("increment of constant field %qD"),
108 G_("decrement of constant field %qD"),
110 else if (INDIRECT_REF_P (arg
)
111 && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (arg
, 0)))
112 && (VAR_P (TREE_OPERAND (arg
, 0))
113 || TREE_CODE (TREE_OPERAND (arg
, 0)) == PARM_DECL
))
114 ERROR_FOR_ASSIGNMENT (loc
,
115 G_("assignment of read-only reference %qD"),
116 G_("read-only reference %qD used as %<asm%> output"),
117 G_("increment of read-only reference %qD"),
118 G_("decrement of read-only reference %qD"),
119 TREE_OPERAND (arg
, 0));
121 readonly_error (loc
, arg
, errstring
);
124 /* Structure that holds information about declarations whose type was
125 incomplete and we could not check whether it was abstract or not. */
127 struct GTY((chain_next ("%h.next"), for_user
)) pending_abstract_type
{
128 /* Declaration which we are checking for abstractness. It is either
129 a DECL node, or an IDENTIFIER_NODE if we do not have a full
130 declaration available. */
133 /* Type which will be checked for abstractness. */
136 /* Kind of use in an unnamed declarator. */
137 enum abstract_class_use use
;
139 /* Position of the declaration. This is only needed for IDENTIFIER_NODEs,
140 because DECLs already carry locus information. */
143 /* Link to the next element in list. */
144 struct pending_abstract_type
* next
;
147 struct abstract_type_hasher
: ggc_ptr_hash
<pending_abstract_type
>
149 typedef tree compare_type
;
150 static hashval_t
hash (pending_abstract_type
*);
151 static bool equal (pending_abstract_type
*, tree
);
154 /* Compute the hash value of the node VAL. This function is used by the
155 hash table abstract_pending_vars. */
158 abstract_type_hasher::hash (pending_abstract_type
*pat
)
160 return (hashval_t
) TYPE_UID (pat
->type
);
164 /* Compare node VAL1 with the type VAL2. This function is used by the
165 hash table abstract_pending_vars. */
168 abstract_type_hasher::equal (pending_abstract_type
*pat1
, tree type2
)
170 return (pat1
->type
== type2
);
173 /* Hash table that maintains pending_abstract_type nodes, for which we still
174 need to check for type abstractness. The key of the table is the type
175 of the declaration. */
176 static GTY (()) hash_table
<abstract_type_hasher
> *abstract_pending_vars
= NULL
;
178 static int abstract_virtuals_error_sfinae (tree
, tree
, abstract_class_use
, tsubst_flags_t
);
180 /* This function is called after TYPE is completed, and will check if there
181 are pending declarations for which we still need to verify the abstractness
182 of TYPE, and emit a diagnostic (through abstract_virtuals_error) if TYPE
183 turned out to be incomplete. */
186 complete_type_check_abstract (tree type
)
188 struct pending_abstract_type
*pat
;
189 location_t cur_loc
= input_location
;
191 gcc_assert (COMPLETE_TYPE_P (type
));
193 if (!abstract_pending_vars
)
196 /* Retrieve the list of pending declarations for this type. */
197 pending_abstract_type
**slot
198 = abstract_pending_vars
->find_slot_with_hash (type
, TYPE_UID (type
),
205 /* If the type is not abstract, do not do anything. */
206 if (CLASSTYPE_PURE_VIRTUALS (type
))
208 struct pending_abstract_type
*prev
= 0, *next
;
210 /* Reverse the list to emit the errors in top-down order. */
211 for (; pat
; pat
= next
)
219 /* Go through the list, and call abstract_virtuals_error for each
220 element: it will issue a diagnostic if the type is abstract. */
223 gcc_assert (type
== pat
->type
);
225 /* Tweak input_location so that the diagnostic appears at the correct
226 location. Notice that this is only needed if the decl is an
228 input_location
= pat
->locus
;
229 abstract_virtuals_error_sfinae (pat
->decl
, pat
->type
, pat
->use
,
230 tf_warning_or_error
);
235 abstract_pending_vars
->clear_slot (slot
);
237 input_location
= cur_loc
;
241 /* If TYPE has abstract virtual functions, issue an error about trying
242 to create an object of that type. DECL is the object declared, or
243 NULL_TREE if the declaration is unavailable, in which case USE specifies
244 the kind of invalid use. Returns 1 if an error occurred; zero if
248 abstract_virtuals_error_sfinae (tree decl
, tree type
, abstract_class_use use
,
249 tsubst_flags_t complain
)
251 vec
<tree
, va_gc
> *pure
;
253 /* This function applies only to classes. Any other entity can never
255 if (!CLASS_TYPE_P (type
))
257 type
= TYPE_MAIN_VARIANT (type
);
260 /* Instantiation here seems to be required by the standard,
261 but breaks e.g. boost::bind. FIXME! */
262 /* In SFINAE, non-N3276 context, force instantiation. */
263 if (!(complain
& (tf_error
|tf_decltype
)))
264 complete_type (type
);
267 /* If the type is incomplete, we register it within a hash table,
268 so that we can check again once it is completed. This makes sense
269 only for objects for which we have a declaration or at least a
271 if (!COMPLETE_TYPE_P (type
) && (complain
& tf_error
))
273 struct pending_abstract_type
*pat
;
275 gcc_assert (!decl
|| DECL_P (decl
) || identifier_p (decl
));
277 if (!abstract_pending_vars
)
278 abstract_pending_vars
279 = hash_table
<abstract_type_hasher
>::create_ggc (31);
281 pending_abstract_type
**slot
282 = abstract_pending_vars
->find_slot_with_hash (type
, TYPE_UID (type
),
285 pat
= ggc_alloc
<pending_abstract_type
> ();
289 pat
->locus
= ((decl
&& DECL_P (decl
))
290 ? DECL_SOURCE_LOCATION (decl
)
299 if (!TYPE_SIZE (type
))
300 /* TYPE is being defined, and during that time
301 CLASSTYPE_PURE_VIRTUALS holds the inline friends. */
304 pure
= CLASSTYPE_PURE_VIRTUALS (type
);
308 if (!(complain
& tf_error
))
311 auto_diagnostic_group d
;
315 error ("cannot declare variable %q+D to be of abstract "
316 "type %qT", decl
, type
);
317 else if (TREE_CODE (decl
) == PARM_DECL
)
319 if (DECL_NAME (decl
))
320 error ("cannot declare parameter %q+D to be of abstract type %qT",
323 error ("cannot declare parameter to be of abstract type %qT",
326 else if (TREE_CODE (decl
) == FIELD_DECL
)
327 error ("cannot declare field %q+D to be of abstract type %qT",
329 else if (TREE_CODE (decl
) == FUNCTION_DECL
330 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
331 error ("invalid abstract return type for member function %q+#D", decl
);
332 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
333 error ("invalid abstract return type for function %q+#D", decl
);
334 else if (identifier_p (decl
))
335 /* Here we do not have location information. */
336 error ("invalid abstract type %qT for %qE", type
, decl
);
338 error ("invalid abstract type for %q+D", decl
);
343 error ("creating array of %qT, which is an abstract class type", type
);
346 error ("invalid cast to abstract class type %qT", type
);
349 error ("invalid new-expression of abstract class type %qT", type
);
352 error ("invalid abstract return type %qT", type
);
355 error ("invalid abstract parameter type %qT", type
);
358 error ("expression of abstract class type %qT cannot "
359 "be used in throw-expression", type
);
362 error ("cannot declare catch parameter to be of abstract "
363 "class type %qT", type
);
366 error ("cannot allocate an object of abstract type %qT", type
);
369 /* Only go through this once. */
375 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type
)),
376 " because the following virtual functions are pure within %qT:",
379 FOR_EACH_VEC_ELT (*pure
, ix
, fn
)
380 if (! DECL_CLONED_FUNCTION_P (fn
)
381 || DECL_COMPLETE_DESTRUCTOR_P (fn
))
382 inform (DECL_SOURCE_LOCATION (fn
), "\t%#qD", fn
);
384 /* Now truncate the vector. This leaves it non-null, so we know
385 there are pure virtuals, but empty so we don't list them out
394 abstract_virtuals_error_sfinae (tree decl
, tree type
, tsubst_flags_t complain
)
396 return abstract_virtuals_error_sfinae (decl
, type
, ACU_UNKNOWN
, complain
);
400 abstract_virtuals_error_sfinae (abstract_class_use use
, tree type
,
401 tsubst_flags_t complain
)
403 return abstract_virtuals_error_sfinae (NULL_TREE
, type
, use
, complain
);
407 /* Wrapper for the above function in the common case of wanting errors. */
410 abstract_virtuals_error (tree decl
, tree type
)
412 return abstract_virtuals_error_sfinae (decl
, type
, tf_warning_or_error
);
416 abstract_virtuals_error (abstract_class_use use
, tree type
)
418 return abstract_virtuals_error_sfinae (use
, type
, tf_warning_or_error
);
421 /* Print an inform about the declaration of the incomplete type TYPE. */
424 cxx_incomplete_type_inform (const_tree type
)
426 if (!TYPE_MAIN_DECL (type
))
429 location_t loc
= DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type
));
430 tree ptype
= strip_top_quals (CONST_CAST_TREE (type
));
432 if (current_class_type
433 && TYPE_BEING_DEFINED (current_class_type
)
434 && same_type_p (ptype
, current_class_type
))
435 inform (loc
, "definition of %q#T is not complete until "
436 "the closing brace", ptype
);
437 else if (!TYPE_TEMPLATE_INFO (ptype
))
438 inform (loc
, "forward declaration of %q#T", ptype
);
440 inform (loc
, "declaration of %q#T", ptype
);
443 /* Print an error message for invalid use of an incomplete type.
444 VALUE is the expression that was used (or 0 if that isn't known)
445 and TYPE is the type that was invalid. DIAG_KIND indicates the
446 type of diagnostic (see diagnostic.def). */
449 cxx_incomplete_type_diagnostic (location_t loc
, const_tree value
,
450 const_tree type
, diagnostic_t diag_kind
)
452 bool is_decl
= false, complained
= false;
454 gcc_assert (diag_kind
== DK_WARNING
455 || diag_kind
== DK_PEDWARN
456 || diag_kind
== DK_ERROR
);
458 /* Avoid duplicate error message. */
459 if (TREE_CODE (type
) == ERROR_MARK
)
462 if (value
!= 0 && (VAR_P (value
)
463 || TREE_CODE (value
) == PARM_DECL
464 || TREE_CODE (value
) == FIELD_DECL
))
466 complained
= emit_diagnostic (diag_kind
, DECL_SOURCE_LOCATION (value
), 0,
467 "%qD has incomplete type", value
);
471 /* We must print an error message. Be clever about what it says. */
473 switch (TREE_CODE (type
))
479 complained
= emit_diagnostic (diag_kind
, loc
, 0,
480 "invalid use of incomplete type %q#T",
483 cxx_incomplete_type_inform (type
);
487 emit_diagnostic (diag_kind
, loc
, 0,
488 "invalid use of %qT", type
);
492 if (TYPE_DOMAIN (type
))
494 type
= TREE_TYPE (type
);
497 emit_diagnostic (diag_kind
, loc
, 0,
498 "invalid use of array with unspecified bounds");
504 tree member
= TREE_OPERAND (value
, 1);
505 if (is_overloaded_fn (member
))
506 member
= get_first_fn (member
);
508 if (DECL_FUNCTION_MEMBER_P (member
)
509 && ! flag_ms_extensions
)
510 emit_diagnostic (diag_kind
, loc
, 0,
511 "invalid use of member function %qD "
512 "(did you forget the %<()%> ?)", member
);
514 emit_diagnostic (diag_kind
, loc
, 0,
515 "invalid use of member %qD "
516 "(did you forget the %<&%> ?)", member
);
520 case TEMPLATE_TYPE_PARM
:
523 if (CLASS_PLACEHOLDER_TEMPLATE (type
))
524 emit_diagnostic (diag_kind
, loc
, 0,
525 "invalid use of placeholder %qT", type
);
527 emit_diagnostic (diag_kind
, loc
, 0,
528 "invalid use of %qT", type
);
531 emit_diagnostic (diag_kind
, loc
, 0,
532 "invalid use of template type parameter %qT", type
);
535 case BOUND_TEMPLATE_TEMPLATE_PARM
:
536 emit_diagnostic (diag_kind
, loc
, 0,
537 "invalid use of template template parameter %qT",
543 emit_diagnostic (diag_kind
, loc
, 0,
544 "invalid use of dependent type %qT", type
);
548 if (type
== init_list_type_node
)
550 emit_diagnostic (diag_kind
, loc
, 0,
551 "invalid use of brace-enclosed initializer list");
554 gcc_assert (type
== unknown_type_node
);
555 if (value
&& TREE_CODE (value
) == COMPONENT_REF
)
557 else if (value
&& TREE_CODE (value
) == ADDR_EXPR
)
558 emit_diagnostic (diag_kind
, loc
, 0,
559 "address of overloaded function with no contextual "
561 else if (value
&& TREE_CODE (value
) == OVERLOAD
)
562 emit_diagnostic (diag_kind
, loc
, 0,
563 "overloaded function with no contextual type information");
565 emit_diagnostic (diag_kind
, loc
, 0,
566 "insufficient contextual information to determine type");
574 /* Print an error message for invalid use of an incomplete type.
575 VALUE is the expression that was used (or 0 if that isn't known)
576 and TYPE is the type that was invalid. */
579 cxx_incomplete_type_error (location_t loc
, const_tree value
, const_tree type
)
581 cxx_incomplete_type_diagnostic (loc
, value
, type
, DK_ERROR
);
585 /* The recursive part of split_nonconstant_init. DEST is an lvalue
586 expression to which INIT should be assigned. INIT is a CONSTRUCTOR.
587 Return true if the whole of the value was initialized by the
588 generated statements. */
591 split_nonconstant_init_1 (tree dest
, tree init
)
593 unsigned HOST_WIDE_INT idx
;
594 tree field_index
, value
;
595 tree type
= TREE_TYPE (dest
);
596 tree inner_type
= NULL
;
597 bool array_type_p
= false;
598 bool complete_p
= true;
599 HOST_WIDE_INT num_split_elts
= 0;
601 switch (TREE_CODE (type
))
604 inner_type
= TREE_TYPE (type
);
606 if ((TREE_SIDE_EFFECTS (init
)
607 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
608 || vla_type_p (type
))
610 /* For an array, we only need/want a single cleanup region rather
611 than one per element. */
612 tree code
= build_vec_init (dest
, NULL_TREE
, init
, false, 1,
613 tf_warning_or_error
);
621 case QUAL_UNION_TYPE
:
622 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), idx
,
625 /* The current implementation of this algorithm assumes that
626 the field was set for all the elements. This is usually done
627 by process_init_constructor. */
628 gcc_assert (field_index
);
631 inner_type
= TREE_TYPE (field_index
);
633 if (TREE_CODE (value
) == CONSTRUCTOR
)
638 sub
= build4 (ARRAY_REF
, inner_type
, dest
, field_index
,
639 NULL_TREE
, NULL_TREE
);
641 sub
= build3 (COMPONENT_REF
, inner_type
, dest
, field_index
,
644 if (!split_nonconstant_init_1 (sub
, value
))
647 CONSTRUCTOR_ELTS (init
)->ordered_remove (idx
--);
650 else if (!initializer_constant_valid_p (value
, inner_type
))
655 /* FIXME: Ordered removal is O(1) so the whole function is
656 worst-case quadratic. This could be fixed using an aside
657 bitmap to record which elements must be removed and remove
658 them all at the same time. Or by merging
659 split_non_constant_init into process_init_constructor_array,
660 that is separating constants from non-constants while building
662 CONSTRUCTOR_ELTS (init
)->ordered_remove (idx
);
665 if (TREE_CODE (field_index
) == RANGE_EXPR
)
667 /* Use build_vec_init to initialize a range. */
668 tree low
= TREE_OPERAND (field_index
, 0);
669 tree hi
= TREE_OPERAND (field_index
, 1);
670 sub
= build4 (ARRAY_REF
, inner_type
, dest
, low
,
671 NULL_TREE
, NULL_TREE
);
672 sub
= cp_build_addr_expr (sub
, tf_warning_or_error
);
673 tree max
= size_binop (MINUS_EXPR
, hi
, low
);
674 code
= build_vec_init (sub
, max
, value
, false, 0,
675 tf_warning_or_error
);
677 if (tree_fits_shwi_p (max
))
678 num_split_elts
+= tree_to_shwi (max
);
683 sub
= build4 (ARRAY_REF
, inner_type
, dest
, field_index
,
684 NULL_TREE
, NULL_TREE
);
686 sub
= build3 (COMPONENT_REF
, inner_type
, dest
, field_index
,
689 code
= build2 (INIT_EXPR
, inner_type
, sub
, value
);
690 code
= build_stmt (input_location
, EXPR_STMT
, code
);
691 code
= maybe_cleanup_point_expr_void (code
);
694 = cxx_maybe_build_cleanup (sub
, tf_warning_or_error
))
695 finish_eh_cleanup (cleanup
);
704 if (!initializer_constant_valid_p (init
, type
))
707 tree cons
= copy_node (init
);
708 CONSTRUCTOR_ELTS (init
) = NULL
;
709 code
= build2 (MODIFY_EXPR
, type
, dest
, cons
);
710 code
= build_stmt (input_location
, EXPR_STMT
, code
);
712 num_split_elts
+= CONSTRUCTOR_NELTS (init
);
720 /* The rest of the initializer is now a constant. */
721 TREE_CONSTANT (init
) = 1;
723 /* We didn't split out anything. */
724 if (num_split_elts
== 0)
727 return complete_p
&& complete_ctor_at_level_p (TREE_TYPE (init
),
728 num_split_elts
, inner_type
);
731 /* A subroutine of store_init_value. Splits non-constant static
732 initializer INIT into a constant part and generates code to
733 perform the non-constant part of the initialization to DEST.
734 Returns the code for the runtime init. */
737 split_nonconstant_init (tree dest
, tree init
)
741 if (TREE_CODE (init
) == TARGET_EXPR
)
742 init
= TARGET_EXPR_INITIAL (init
);
743 if (TREE_CODE (init
) == CONSTRUCTOR
)
745 init
= cp_fully_fold (init
);
746 code
= push_stmt_list ();
747 if (split_nonconstant_init_1 (dest
, init
))
749 code
= pop_stmt_list (code
);
750 DECL_INITIAL (dest
) = init
;
751 TREE_READONLY (dest
) = 0;
753 else if (TREE_CODE (init
) == STRING_CST
754 && array_of_runtime_bound_p (TREE_TYPE (dest
)))
755 code
= build_vec_init (dest
, NULL_TREE
, init
, /*value-init*/false,
756 /*from array*/1, tf_warning_or_error
);
758 code
= build2 (INIT_EXPR
, TREE_TYPE (dest
), dest
, init
);
763 /* Perform appropriate conversions on the initial value of a variable,
764 store it in the declaration DECL,
765 and print any error messages that are appropriate.
766 If the init is invalid, store an ERROR_MARK.
768 C++: Note that INIT might be a TREE_LIST, which would mean that it is
769 a base class initializer for some aggregate type, hopefully compatible
770 with DECL. If INIT is a single element, and DECL is an aggregate
771 type, we silently convert INIT into a TREE_LIST, allowing a constructor
774 If INIT is a TREE_LIST and there is no constructor, turn INIT
775 into a CONSTRUCTOR and use standard initialization techniques.
776 Perhaps a warning should be generated?
778 Returns code to be executed if initialization could not be performed
779 for static variable. In that case, caller must emit the code. */
782 store_init_value (tree decl
, tree init
, vec
<tree
, va_gc
>** cleanups
, int flags
)
786 /* If variable's type was invalidly declared, just ignore it. */
788 type
= TREE_TYPE (decl
);
789 if (TREE_CODE (type
) == ERROR_MARK
)
792 if (MAYBE_CLASS_TYPE_P (type
))
794 if (TREE_CODE (init
) == TREE_LIST
)
796 error ("constructor syntax used, but no constructor declared "
797 "for type %qT", type
);
798 init
= build_constructor_from_list (init_list_type_node
, nreverse (init
));
802 /* End of special C++ code. */
804 if (flags
& LOOKUP_ALREADY_DIGESTED
)
807 /* Digest the specified initializer into an expression. */
808 value
= digest_init_flags (type
, init
, flags
, tf_warning_or_error
);
810 if (TREE_CODE (type
) == ARRAY_TYPE
811 && TYPE_STRING_FLAG (TREE_TYPE (type
))
812 && TREE_CODE (value
) == CONSTRUCTOR
)
813 value
= braced_list_to_string (type
, value
);
815 value
= extend_ref_init_temps (decl
, value
, cleanups
);
817 /* In C++11 constant expression is a semantic, not syntactic, property.
818 In C++98, make sure that what we thought was a constant expression at
819 template definition time is still constant and otherwise perform this
820 as optimization, e.g. to fold SIZEOF_EXPRs in the initializer. */
821 if (decl_maybe_constant_var_p (decl
) || TREE_STATIC (decl
))
825 value
= fold_non_dependent_expr (value
);
826 if (DECL_DECLARED_CONSTEXPR_P (decl
)
827 || (DECL_IN_AGGR_P (decl
)
828 && DECL_INITIALIZED_IN_CLASS_P (decl
)
829 && !DECL_VAR_DECLARED_INLINE_P (decl
)))
831 /* Diagnose a non-constant initializer for constexpr variable or
832 non-inline in-class-initialized static data member. */
833 if (!require_constant_expression (value
))
834 value
= error_mark_node
;
836 value
= cxx_constant_init (value
, decl
);
839 value
= maybe_constant_init (value
, decl
, true);
840 if (TREE_CODE (value
) == CONSTRUCTOR
&& cp_has_mutable_p (type
))
841 /* Poison this CONSTRUCTOR so it can't be copied to another
842 constexpr variable. */
843 CONSTRUCTOR_MUTABLE_POISON (value
) = true;
844 const_init
= (reduced_constant_expression_p (value
)
845 || error_operand_p (value
));
846 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = const_init
;
847 /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
848 if (!TYPE_REF_P (type
))
849 TREE_CONSTANT (decl
) = const_init
&& decl_maybe_constant_var_p (decl
);
853 value
= cp_fully_fold (value
);
855 /* Handle aggregate NSDMI in non-constant initializers, too. */
856 value
= replace_placeholders (value
, decl
);
858 /* DECL may change value; purge caches. */
859 clear_cv_and_fold_caches ();
861 /* If the initializer is not a constant, fill in DECL_INITIAL with
862 the bits that are constant, and then return an expression that
863 will perform the dynamic initialization. */
864 if (value
!= error_mark_node
865 && (TREE_SIDE_EFFECTS (value
)
867 || ! reduced_constant_expression_p (value
)))
868 return split_nonconstant_init (decl
, value
);
869 /* If the value is a constant, just put it in DECL_INITIAL. If DECL
870 is an automatic variable, the middle end will turn this into a
871 dynamic initialization later. */
872 DECL_INITIAL (decl
) = value
;
877 /* Give diagnostic about narrowing conversions within { }, or as part of
878 a converted constant expression. If CONST_ONLY, only check
882 check_narrowing (tree type
, tree init
, tsubst_flags_t complain
, bool const_only
)
884 tree ftype
= unlowered_expr_type (init
);
888 if (((!warn_narrowing
|| !(complain
& tf_warning
))
889 && cxx_dialect
== cxx98
)
890 || !ARITHMETIC_TYPE_P (type
)
891 /* Don't emit bogus warnings with e.g. value-dependent trees. */
892 || instantiation_dependent_expression_p (init
))
895 if (BRACE_ENCLOSED_INITIALIZER_P (init
)
896 && TREE_CODE (type
) == COMPLEX_TYPE
)
898 tree elttype
= TREE_TYPE (type
);
899 if (CONSTRUCTOR_NELTS (init
) > 0)
900 ok
&= check_narrowing (elttype
, CONSTRUCTOR_ELT (init
, 0)->value
,
902 if (CONSTRUCTOR_NELTS (init
) > 1)
903 ok
&= check_narrowing (elttype
, CONSTRUCTOR_ELT (init
, 1)->value
,
908 init
= maybe_constant_value (init
);
910 /* If we were asked to only check constants, return early. */
911 if (const_only
&& !TREE_CONSTANT (init
))
914 if (CP_INTEGRAL_TYPE_P (type
)
915 && TREE_CODE (ftype
) == REAL_TYPE
)
917 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype
)
918 && CP_INTEGRAL_TYPE_P (type
))
920 if (TREE_CODE (ftype
) == ENUMERAL_TYPE
)
921 /* Check for narrowing based on the values of the enumeration. */
922 ftype
= ENUM_UNDERLYING_TYPE (ftype
);
923 if ((tree_int_cst_lt (TYPE_MAX_VALUE (type
),
924 TYPE_MAX_VALUE (ftype
))
925 || tree_int_cst_lt (TYPE_MIN_VALUE (ftype
),
926 TYPE_MIN_VALUE (type
)))
927 && (TREE_CODE (init
) != INTEGER_CST
928 || !int_fits_type_p (init
, type
)))
931 else if (TREE_CODE (ftype
) == REAL_TYPE
932 && TREE_CODE (type
) == REAL_TYPE
)
934 if (TYPE_PRECISION (type
) < TYPE_PRECISION (ftype
))
936 if (TREE_CODE (init
) == REAL_CST
)
938 /* Issue 703: Loss of precision is OK as long as the value is
939 within the representable range of the new type. */
941 d
= TREE_REAL_CST (init
);
942 real_convert (&r
, TYPE_MODE (type
), &d
);
950 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype
)
951 && TREE_CODE (type
) == REAL_TYPE
)
954 if (TREE_CODE (init
) == INTEGER_CST
)
956 d
= real_value_from_int_cst (0, init
);
957 if (exact_real_truncate (TYPE_MODE (type
), &d
))
963 if (!ok
&& !CONSTANT_CLASS_P (init
) && (complain
& tf_warning_or_error
))
965 tree folded
= cp_fully_fold (init
);
966 if (TREE_CONSTANT (folded
) && check_narrowing (type
, folded
, tf_none
))
972 location_t loc
= cp_expr_loc_or_loc (init
, input_location
);
973 if (cxx_dialect
== cxx98
)
975 if (complain
& tf_warning
)
976 warning_at (loc
, OPT_Wnarrowing
, "narrowing conversion of %qE "
977 "from %qH to %qI is ill-formed in C++11",
981 else if (!CONSTANT_CLASS_P (init
))
983 if (complain
& tf_warning_or_error
)
985 auto_diagnostic_group d
;
986 if ((!almost_ok
|| pedantic
)
987 && pedwarn (loc
, OPT_Wnarrowing
,
988 "narrowing conversion of %qE from %qH to %qI",
991 inform (loc
, " the expression has a constant value but is not "
992 "a C++ constant-expression");
996 else if (complain
& tf_error
)
998 int savederrorcount
= errorcount
;
999 global_dc
->pedantic_errors
= 1;
1000 pedwarn (loc
, OPT_Wnarrowing
,
1001 "narrowing conversion of %qE from %qH to %qI ",
1003 if (errorcount
== savederrorcount
)
1005 global_dc
->pedantic_errors
= flag_pedantic_errors
;
1012 /* Process the initializer INIT for a variable of type TYPE, emitting
1013 diagnostics for invalid initializers and converting the initializer as
1016 For aggregate types, it assumes that reshape_init has already run, thus the
1017 initializer will have the right shape (brace elision has been undone).
1019 NESTED is non-zero iff we are being called for an element of a CONSTRUCTOR,
1020 2 iff the element of a CONSTRUCTOR is inside another CONSTRUCTOR. */
1023 digest_init_r (tree type
, tree init
, int nested
, int flags
,
1024 tsubst_flags_t complain
)
1026 enum tree_code code
= TREE_CODE (type
);
1028 if (error_operand_p (init
))
1029 return error_mark_node
;
1033 /* We must strip the outermost array type when completing the type,
1034 because the its bounds might be incomplete at the moment. */
1035 if (!complete_type_or_maybe_complain (code
== ARRAY_TYPE
1036 ? TREE_TYPE (type
) : type
, NULL_TREE
,
1038 return error_mark_node
;
1040 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue
1041 (g++.old-deja/g++.law/casts2.C). */
1042 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
1043 init
= TREE_OPERAND (init
, 0);
1045 location_t loc
= cp_expr_loc_or_loc (init
, input_location
);
1047 /* Initialization of an array of chars from a string constant. The initializer
1048 can be optionally enclosed in braces, but reshape_init has already removed
1049 them if they were present. */
1050 if (code
== ARRAY_TYPE
)
1052 if (nested
&& !TYPE_DOMAIN (type
))
1053 /* C++ flexible array members have a null domain. */
1054 pedwarn (loc
, OPT_Wpedantic
,
1055 "initialization of a flexible array member");
1057 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
1058 if (char_type_p (typ1
)
1060 && TREE_CODE (init
) == STRING_CST
)
1062 tree char_type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init
)));
1064 if (TYPE_PRECISION (typ1
) == BITS_PER_UNIT
)
1066 if (char_type
!= char_type_node
)
1068 if (complain
& tf_error
)
1069 error_at (loc
, "char-array initialized from wide string");
1070 return error_mark_node
;
1075 if (char_type
== char_type_node
)
1077 if (complain
& tf_error
)
1079 "int-array initialized from non-wide string");
1080 return error_mark_node
;
1082 else if (char_type
!= typ1
)
1084 if (complain
& tf_error
)
1085 error_at (loc
, "int-array initialized from incompatible "
1087 return error_mark_node
;
1091 if (nested
== 2 && !TYPE_DOMAIN (type
))
1093 if (complain
& tf_error
)
1094 error_at (loc
, "initialization of flexible array member "
1095 "in a nested context");
1096 return error_mark_node
;
1099 if (type
!= TREE_TYPE (init
)
1100 && !variably_modified_type_p (type
, NULL_TREE
))
1102 init
= copy_node (init
);
1103 TREE_TYPE (init
) = type
;
1105 if (TYPE_DOMAIN (type
) && TREE_CONSTANT (TYPE_SIZE (type
)))
1107 /* Not a flexible array member. */
1108 int size
= TREE_INT_CST_LOW (TYPE_SIZE (type
));
1109 size
= (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
1110 /* In C it is ok to subtract 1 from the length of the string
1111 because it's ok to ignore the terminating null char that is
1112 counted in the length of the constant, but in C++ this would
1114 if (size
< TREE_STRING_LENGTH (init
))
1116 permerror (loc
, "initializer-string for array "
1117 "of chars is too long");
1119 init
= build_string (size
, TREE_STRING_POINTER (init
));
1120 TREE_TYPE (init
) = type
;
1127 /* Handle scalar types (including conversions) and references. */
1128 if ((code
!= COMPLEX_TYPE
|| BRACE_ENCLOSED_INITIALIZER_P (init
))
1129 && (SCALAR_TYPE_P (type
) || code
== REFERENCE_TYPE
))
1132 flags
|= LOOKUP_NO_NARROWING
;
1133 init
= convert_for_initialization (0, type
, init
, flags
,
1134 ICR_INIT
, NULL_TREE
, 0,
1140 /* Come here only for aggregates: records, arrays, unions, complex numbers
1142 gcc_assert (code
== ARRAY_TYPE
1143 || VECTOR_TYPE_P (type
)
1144 || code
== RECORD_TYPE
1145 || code
== UNION_TYPE
1146 || code
== COMPLEX_TYPE
);
1148 /* "If T is a class type and the initializer list has a single
1149 element of type cv U, where U is T or a class derived from T,
1150 the object is initialized from that element." */
1152 && cxx_dialect
>= cxx11
1153 && BRACE_ENCLOSED_INITIALIZER_P (init
)
1154 && CONSTRUCTOR_NELTS (init
) == 1
1155 && ((CLASS_TYPE_P (type
) && !CLASSTYPE_NON_AGGREGATE (type
))
1156 || VECTOR_TYPE_P (type
)))
1158 tree elt
= CONSTRUCTOR_ELT (init
, 0)->value
;
1159 if (reference_related_p (type
, TREE_TYPE (elt
)))
1160 /* We should have fixed this in reshape_init. */
1164 if (BRACE_ENCLOSED_INITIALIZER_P (init
)
1165 && !TYPE_NON_AGGREGATE_CLASS (type
))
1166 return process_init_constructor (type
, init
, nested
, complain
);
1169 if (COMPOUND_LITERAL_P (init
) && code
== ARRAY_TYPE
)
1171 if (complain
& tf_error
)
1172 error_at (loc
, "cannot initialize aggregate of type %qT with "
1173 "a compound literal", type
);
1175 return error_mark_node
;
1178 if (code
== ARRAY_TYPE
1179 && !BRACE_ENCLOSED_INITIALIZER_P (init
))
1181 /* Allow the result of build_array_copy and of
1182 build_value_init_noctor. */
1183 if ((TREE_CODE (init
) == VEC_INIT_EXPR
1184 || TREE_CODE (init
) == CONSTRUCTOR
)
1185 && (same_type_ignoring_top_level_qualifiers_p
1186 (type
, TREE_TYPE (init
))))
1189 if (complain
& tf_error
)
1190 error_at (loc
, "array must be initialized with a brace-enclosed"
1192 return error_mark_node
;
1195 return convert_for_initialization (NULL_TREE
, type
, init
,
1197 ICR_INIT
, NULL_TREE
, 0,
1203 digest_init (tree type
, tree init
, tsubst_flags_t complain
)
1205 return digest_init_r (type
, init
, 0, LOOKUP_IMPLICIT
, complain
);
1209 digest_init_flags (tree type
, tree init
, int flags
, tsubst_flags_t complain
)
1211 return digest_init_r (type
, init
, 0, flags
, complain
);
1214 /* Process the initializer INIT for an NSDMI DECL (a FIELD_DECL). */
1216 digest_nsdmi_init (tree decl
, tree init
, tsubst_flags_t complain
)
1218 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1220 tree type
= TREE_TYPE (decl
);
1221 int flags
= LOOKUP_IMPLICIT
;
1222 if (DIRECT_LIST_INIT_P (init
))
1223 flags
= LOOKUP_NORMAL
;
1224 if (BRACE_ENCLOSED_INITIALIZER_P (init
)
1225 && CP_AGGREGATE_TYPE_P (type
))
1226 init
= reshape_init (type
, init
, complain
);
1227 init
= digest_init_flags (type
, init
, flags
, complain
);
1228 if (TREE_CODE (init
) == TARGET_EXPR
)
1229 /* This represents the whole initialization. */
1230 TARGET_EXPR_DIRECT_INIT_P (init
) = true;
1234 /* Set of flags used within process_init_constructor to describe the
1236 #define PICFLAG_ERRONEOUS 1
1237 #define PICFLAG_NOT_ALL_CONSTANT 2
1238 #define PICFLAG_NOT_ALL_SIMPLE 4
1239 #define PICFLAG_SIDE_EFFECTS 8
1241 /* Given an initializer INIT, return the flag (PICFLAG_*) which better
1245 picflag_from_initializer (tree init
)
1247 if (init
== error_mark_node
)
1248 return PICFLAG_ERRONEOUS
;
1249 else if (!TREE_CONSTANT (init
))
1251 if (TREE_SIDE_EFFECTS (init
))
1252 return PICFLAG_SIDE_EFFECTS
;
1254 return PICFLAG_NOT_ALL_CONSTANT
;
1256 else if (!initializer_constant_valid_p (init
, TREE_TYPE (init
)))
1257 return PICFLAG_NOT_ALL_SIMPLE
;
1261 /* Adjust INIT for going into a CONSTRUCTOR. */
1264 massage_init_elt (tree type
, tree init
, int nested
, tsubst_flags_t complain
)
1266 init
= digest_init_r (type
, init
, nested
? 2 : 1, LOOKUP_IMPLICIT
, complain
);
1267 /* Strip a simple TARGET_EXPR when we know this is an initializer. */
1268 if (SIMPLE_TARGET_EXPR_P (init
))
1269 init
= TARGET_EXPR_INITIAL (init
);
1270 /* When we defer constant folding within a statement, we may want to
1271 defer this folding as well. */
1272 tree t
= fold_non_dependent_expr (init
, complain
);
1273 t
= maybe_constant_init (t
);
1274 if (TREE_CONSTANT (t
))
1279 /* Subroutine of process_init_constructor, which will process an initializer
1280 INIT for an array or vector of type TYPE. Returns the flags (PICFLAG_*)
1281 which describe the initializers. */
1284 process_init_constructor_array (tree type
, tree init
, int nested
,
1285 tsubst_flags_t complain
)
1287 unsigned HOST_WIDE_INT i
, len
= 0;
1289 bool unbounded
= false;
1290 constructor_elt
*ce
;
1291 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (init
);
1293 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
1294 || VECTOR_TYPE_P (type
));
1296 if (TREE_CODE (type
) == ARRAY_TYPE
)
1298 /* C++ flexible array members have a null domain. */
1299 tree domain
= TYPE_DOMAIN (type
);
1300 if (domain
&& TREE_CONSTANT (TYPE_MAX_VALUE (domain
)))
1301 len
= wi::ext (wi::to_offset (TYPE_MAX_VALUE (domain
))
1302 - wi::to_offset (TYPE_MIN_VALUE (domain
)) + 1,
1303 TYPE_PRECISION (TREE_TYPE (domain
)),
1304 TYPE_SIGN (TREE_TYPE (domain
))).to_uhwi ();
1306 unbounded
= true; /* Take as many as there are. */
1308 if (nested
== 2 && !domain
&& !vec_safe_is_empty (v
))
1310 if (complain
& tf_error
)
1311 error_at (cp_expr_loc_or_loc (init
, input_location
),
1312 "initialization of flexible array member "
1313 "in a nested context");
1314 return PICFLAG_ERRONEOUS
;
1318 /* Vectors are like simple fixed-size arrays. */
1319 unbounded
= !TYPE_VECTOR_SUBPARTS (type
).is_constant (&len
);
1321 /* There must not be more initializers than needed. */
1322 if (!unbounded
&& vec_safe_length (v
) > len
)
1324 if (complain
& tf_error
)
1325 error ("too many initializers for %qT", type
);
1327 return PICFLAG_ERRONEOUS
;
1330 FOR_EACH_VEC_SAFE_ELT (v
, i
, ce
)
1333 ce
->index
= size_int (i
);
1334 else if (!check_array_designated_initializer (ce
, i
))
1335 ce
->index
= error_mark_node
;
1336 gcc_assert (ce
->value
);
1338 = massage_init_elt (TREE_TYPE (type
), ce
->value
, nested
, complain
);
1341 (ce
->value
== error_mark_node
1342 || (same_type_ignoring_top_level_qualifiers_p
1343 (strip_array_types (TREE_TYPE (type
)),
1344 strip_array_types (TREE_TYPE (ce
->value
)))));
1346 flags
|= picflag_from_initializer (ce
->value
);
1349 /* No more initializers. If the array is unbounded, we are done. Otherwise,
1350 we must add initializers ourselves. */
1352 for (; i
< len
; ++i
)
1356 if (type_build_ctor_call (TREE_TYPE (type
)))
1358 /* If this type needs constructors run for default-initialization,
1359 we can't rely on the back end to do it for us, so make the
1360 initialization explicit by list-initializing from T{}. */
1361 next
= build_constructor (init_list_type_node
, NULL
);
1362 next
= massage_init_elt (TREE_TYPE (type
), next
, nested
, complain
);
1363 if (initializer_zerop (next
))
1364 /* The default zero-initialization is fine for us; don't
1365 add anything to the CONSTRUCTOR. */
1368 else if (!zero_init_p (TREE_TYPE (type
)))
1369 next
= build_zero_init (TREE_TYPE (type
),
1370 /*nelts=*/NULL_TREE
,
1371 /*static_storage_p=*/false);
1373 /* The default zero-initialization is fine for us; don't
1374 add anything to the CONSTRUCTOR. */
1379 flags
|= picflag_from_initializer (next
);
1381 && (initializer_constant_valid_p (next
, TREE_TYPE (next
))
1382 == null_pointer_node
))
1384 tree range
= build2 (RANGE_EXPR
, size_type_node
,
1385 build_int_cst (size_type_node
, i
),
1386 build_int_cst (size_type_node
, len
- 1));
1387 CONSTRUCTOR_APPEND_ELT (v
, range
, next
);
1391 CONSTRUCTOR_APPEND_ELT (v
, size_int (i
), next
);
1394 /* Don't bother checking all the other elements. */
1398 CONSTRUCTOR_ELTS (init
) = v
;
1402 /* Subroutine of process_init_constructor, which will process an initializer
1403 INIT for a class of type TYPE. Returns the flags (PICFLAG_*) which describe
1404 the initializers. */
1407 process_init_constructor_record (tree type
, tree init
, int nested
,
1408 tsubst_flags_t complain
)
1410 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1414 gcc_assert (TREE_CODE (type
) == RECORD_TYPE
);
1415 gcc_assert (!CLASSTYPE_VBASECLASSES (type
));
1416 gcc_assert (!TYPE_BINFO (type
)
1417 || cxx_dialect
>= cxx17
1418 || !BINFO_N_BASE_BINFOS (TYPE_BINFO (type
)));
1419 gcc_assert (!TYPE_POLYMORPHIC_P (type
));
1423 unsigned HOST_WIDE_INT idx
= 0;
1424 int designator_skip
= -1;
1425 /* Generally, we will always have an index for each initializer (which is
1426 a FIELD_DECL, put by reshape_init), but compound literals don't go trough
1427 reshape_init. So we need to handle both cases. */
1428 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
1433 if (TREE_CODE (field
) != FIELD_DECL
1434 || (DECL_ARTIFICIAL (field
)
1435 && !(cxx_dialect
>= cxx17
&& DECL_FIELD_IS_BASE (field
))))
1438 if (DECL_UNNAMED_BIT_FIELD (field
))
1441 /* If this is a bitfield, first convert to the declared type. */
1442 type
= TREE_TYPE (field
);
1443 if (DECL_BIT_FIELD_TYPE (field
))
1444 type
= DECL_BIT_FIELD_TYPE (field
);
1445 if (type
== error_mark_node
)
1446 return PICFLAG_ERRONEOUS
;
1449 if (idx
< CONSTRUCTOR_NELTS (init
))
1451 constructor_elt
*ce
= &(*CONSTRUCTOR_ELTS (init
))[idx
];
1454 /* We can have either a FIELD_DECL or an IDENTIFIER_NODE. The
1455 latter case can happen in templates where lookup has to be
1457 gcc_assert (TREE_CODE (ce
->index
) == FIELD_DECL
1458 || identifier_p (ce
->index
));
1459 if (ce
->index
== field
|| ce
->index
== DECL_NAME (field
))
1461 else if (ANON_AGGR_TYPE_P (type
)
1462 && search_anon_aggr (type
,
1463 TREE_CODE (ce
->index
) == FIELD_DECL
1464 ? DECL_NAME (ce
->index
)
1466 /* If the element is an anonymous union object and the
1467 initializer list is a designated-initializer-list, the
1468 anonymous union object is initialized by the
1469 designated-initializer-list { D }, where D is the
1470 designated-initializer-clause naming a member of the
1471 anonymous union object. */
1472 next
= build_constructor_single (init_list_type_node
,
1473 ce
->index
, ce
->value
);
1477 if (designator_skip
== -1)
1478 designator_skip
= 1;
1483 designator_skip
= 0;
1489 gcc_assert (ce
->value
);
1490 next
= massage_init_elt (type
, next
, nested
, complain
);
1495 /* Already handled above. */;
1496 else if (DECL_INITIAL (field
))
1500 /* We're using an NSDMI past a field with implicit
1501 zero-init. Go back and make it explicit. */
1503 vec_safe_truncate (v
, 0);
1506 /* C++14 aggregate NSDMI. */
1507 next
= get_nsdmi (field
, /*ctor*/false, complain
);
1508 if (!CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
)
1509 && find_placeholders (next
))
1510 CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
) = 1;
1512 else if (type_build_ctor_call (TREE_TYPE (field
)))
1514 /* If this type needs constructors run for
1515 default-initialization, we can't rely on the back end to do it
1516 for us, so build up TARGET_EXPRs. If the type in question is
1517 a class, just build one up; if it's an array, recurse. */
1518 next
= build_constructor (init_list_type_node
, NULL
);
1519 next
= massage_init_elt (TREE_TYPE (field
), next
, nested
, complain
);
1521 /* Warn when some struct elements are implicitly initialized. */
1522 if ((complain
& tf_warning
)
1523 && !EMPTY_CONSTRUCTOR_P (init
))
1524 warning (OPT_Wmissing_field_initializers
,
1525 "missing initializer for member %qD", field
);
1529 const_tree fldtype
= TREE_TYPE (field
);
1530 if (TYPE_REF_P (fldtype
))
1532 if (complain
& tf_error
)
1533 error ("member %qD is uninitialized reference", field
);
1535 return PICFLAG_ERRONEOUS
;
1537 else if (CLASSTYPE_REF_FIELDS_NEED_INIT (fldtype
))
1539 if (complain
& tf_error
)
1540 error ("member %qD with uninitialized reference fields", field
);
1542 return PICFLAG_ERRONEOUS
;
1545 /* Warn when some struct elements are implicitly initialized
1546 to zero. However, avoid issuing the warning for flexible
1547 array members since they need not have any elements. */
1548 if ((TREE_CODE (fldtype
) != ARRAY_TYPE
|| TYPE_DOMAIN (fldtype
))
1549 && (complain
& tf_warning
)
1550 && !EMPTY_CONSTRUCTOR_P (init
))
1551 warning (OPT_Wmissing_field_initializers
,
1552 "missing initializer for member %qD", field
);
1554 if (!zero_init_p (fldtype
)
1556 next
= build_zero_init (TREE_TYPE (field
), /*nelts=*/NULL_TREE
,
1557 /*static_storage_p=*/false);
1560 /* The default zero-initialization is fine for us; don't
1561 add anything to the CONSTRUCTOR. */
1567 /* If this is a bitfield, now convert to the lowered type. */
1568 if (type
!= TREE_TYPE (field
))
1569 next
= cp_convert_and_check (TREE_TYPE (field
), next
, complain
);
1570 flags
|= picflag_from_initializer (next
);
1571 CONSTRUCTOR_APPEND_ELT (v
, field
, next
);
1574 if (idx
< CONSTRUCTOR_NELTS (init
))
1576 if (complain
& tf_error
)
1578 constructor_elt
*ce
= &(*CONSTRUCTOR_ELTS (init
))[idx
];
1579 /* For better diagnostics, try to find out if it is really
1580 the case of too many initializers or if designators are
1581 in incorrect order. */
1582 if (designator_skip
== 1 && ce
->index
)
1584 gcc_assert (TREE_CODE (ce
->index
) == FIELD_DECL
1585 || identifier_p (ce
->index
));
1586 for (field
= TYPE_FIELDS (type
);
1587 field
; field
= DECL_CHAIN (field
))
1589 if (TREE_CODE (field
) != FIELD_DECL
1590 || (DECL_ARTIFICIAL (field
)
1591 && !(cxx_dialect
>= cxx17
1592 && DECL_FIELD_IS_BASE (field
))))
1595 if (DECL_UNNAMED_BIT_FIELD (field
))
1598 if (ce
->index
== field
|| ce
->index
== DECL_NAME (field
))
1600 if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
1603 = search_anon_aggr (TREE_TYPE (field
),
1604 TREE_CODE (ce
->index
) == FIELD_DECL
1605 ? DECL_NAME (ce
->index
)
1616 error ("designator order for field %qD does not match declaration "
1617 "order in %qT", field
, type
);
1619 error ("too many initializers for %qT", type
);
1622 return PICFLAG_ERRONEOUS
;
1625 CONSTRUCTOR_ELTS (init
) = v
;
1629 /* Subroutine of process_init_constructor, which will process a single
1630 initializer INIT for a union of type TYPE. Returns the flags (PICFLAG_*)
1631 which describe the initializer. */
1634 process_init_constructor_union (tree type
, tree init
, int nested
,
1635 tsubst_flags_t complain
)
1637 constructor_elt
*ce
;
1640 /* If the initializer was empty, use the union's NSDMI if it has one.
1641 Otherwise use default zero initialization. */
1642 if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init
)))
1644 for (tree field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
1646 if (TREE_CODE (field
) == FIELD_DECL
1647 && DECL_INITIAL (field
) != NULL_TREE
)
1649 tree val
= get_nsdmi (field
, /*in_ctor=*/false, complain
);
1650 if (!CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
)
1651 && find_placeholders (val
))
1652 CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
) = 1;
1653 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (init
), field
, val
);
1658 if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init
)))
1662 len
= CONSTRUCTOR_ELTS (init
)->length ();
1665 if (!(complain
& tf_error
))
1666 return PICFLAG_ERRONEOUS
;
1667 error ("too many initializers for %qT", type
);
1668 CONSTRUCTOR_ELTS (init
)->block_remove (1, len
-1);
1671 ce
= &(*CONSTRUCTOR_ELTS (init
))[0];
1673 /* If this element specifies a field, initialize via that field. */
1676 if (TREE_CODE (ce
->index
) == FIELD_DECL
)
1678 else if (identifier_p (ce
->index
))
1680 /* This can happen within a cast, see g++.dg/opt/cse2.C. */
1681 tree name
= ce
->index
;
1683 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
1684 if (DECL_NAME (field
) == name
)
1688 if (complain
& tf_error
)
1689 error ("no field %qD found in union being initialized",
1691 ce
->value
= error_mark_node
;
1697 gcc_assert (TREE_CODE (ce
->index
) == INTEGER_CST
1698 || TREE_CODE (ce
->index
) == RANGE_EXPR
);
1699 if (complain
& tf_error
)
1700 error ("index value instead of field name in union initializer");
1701 ce
->value
= error_mark_node
;
1706 /* Find the first named field. ANSI decided in September 1990
1707 that only named fields count here. */
1708 tree field
= TYPE_FIELDS (type
);
1709 while (field
&& (!DECL_NAME (field
) || TREE_CODE (field
) != FIELD_DECL
))
1710 field
= TREE_CHAIN (field
);
1711 if (field
== NULL_TREE
)
1713 if (complain
& tf_error
)
1714 error ("too many initializers for %qT", type
);
1715 ce
->value
= error_mark_node
;
1720 if (ce
->value
&& ce
->value
!= error_mark_node
)
1721 ce
->value
= massage_init_elt (TREE_TYPE (ce
->index
), ce
->value
, nested
,
1724 return picflag_from_initializer (ce
->value
);
1727 /* Process INIT, a constructor for a variable of aggregate type TYPE. The
1728 constructor is a brace-enclosed initializer, and will be modified in-place.
1730 Each element is converted to the right type through digest_init, and
1731 missing initializers are added following the language rules (zero-padding,
1734 After the execution, the initializer will have TREE_CONSTANT if all elts are
1735 constant, and TREE_STATIC set if, in addition, all elts are simple enough
1736 constants that the assembler and linker can compute them.
1738 The function returns the initializer itself, or error_mark_node in case
1742 process_init_constructor (tree type
, tree init
, int nested
,
1743 tsubst_flags_t complain
)
1747 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init
));
1749 if (TREE_CODE (type
) == ARRAY_TYPE
|| VECTOR_TYPE_P (type
))
1750 flags
= process_init_constructor_array (type
, init
, nested
, complain
);
1751 else if (TREE_CODE (type
) == RECORD_TYPE
)
1752 flags
= process_init_constructor_record (type
, init
, nested
, complain
);
1753 else if (TREE_CODE (type
) == UNION_TYPE
)
1754 flags
= process_init_constructor_union (type
, init
, nested
, complain
);
1758 if (flags
& PICFLAG_ERRONEOUS
)
1759 return error_mark_node
;
1761 TREE_TYPE (init
) = type
;
1762 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
) == NULL_TREE
)
1763 cp_complete_array_type (&TREE_TYPE (init
), init
, /*do_default=*/0);
1764 if (flags
& PICFLAG_SIDE_EFFECTS
)
1766 TREE_CONSTANT (init
) = false;
1767 TREE_SIDE_EFFECTS (init
) = true;
1769 else if (flags
& PICFLAG_NOT_ALL_CONSTANT
)
1770 /* Make sure TREE_CONSTANT isn't set from build_constructor. */
1771 TREE_CONSTANT (init
) = false;
1774 TREE_CONSTANT (init
) = 1;
1775 if (!(flags
& PICFLAG_NOT_ALL_SIMPLE
))
1776 TREE_STATIC (init
) = 1;
1781 /* Given a structure or union value DATUM, construct and return
1782 the structure or union component which results from narrowing
1783 that value to the base specified in BASETYPE. For example, given the
1786 class L { int ii; };
1787 class A : L { ... };
1788 class B : L { ... };
1789 class C : A, B { ... };
1797 x.A::ii refers to the ii member of the L part of
1798 the A part of the C object named by X. In this case,
1799 DATUM would be x, and BASETYPE would be A.
1801 I used to think that this was nonconformant, that the standard specified
1802 that first we look up ii in A, then convert x to an L& and pull out the
1803 ii part. But in fact, it does say that we convert x to an A&; A here
1804 is known as the "naming class". (jason 2000-12-19)
1806 BINFO_P points to a variable initialized either to NULL_TREE or to the
1807 binfo for the specific base subobject we want to convert to. */
1810 build_scoped_ref (tree datum
, tree basetype
, tree
* binfo_p
)
1814 if (datum
== error_mark_node
)
1815 return error_mark_node
;
1819 binfo
= lookup_base (TREE_TYPE (datum
), basetype
, ba_check
,
1820 NULL
, tf_warning_or_error
);
1822 if (!binfo
|| binfo
== error_mark_node
)
1824 *binfo_p
= NULL_TREE
;
1826 error_not_base_type (basetype
, TREE_TYPE (datum
));
1827 return error_mark_node
;
1831 return build_base_path (PLUS_EXPR
, datum
, binfo
, 1,
1832 tf_warning_or_error
);
1835 /* Build a reference to an object specified by the C++ `->' operator.
1836 Usually this just involves dereferencing the object, but if the
1837 `->' operator is overloaded, then such overloads must be
1838 performed until an object which does not have the `->' operator
1839 overloaded is found. An error is reported when circular pointer
1840 delegation is detected. */
1843 build_x_arrow (location_t loc
, tree expr
, tsubst_flags_t complain
)
1845 tree orig_expr
= expr
;
1846 tree type
= TREE_TYPE (expr
);
1847 tree last_rval
= NULL_TREE
;
1848 vec
<tree
, va_gc
> *types_memoized
= NULL
;
1850 if (type
== error_mark_node
)
1851 return error_mark_node
;
1853 if (processing_template_decl
)
1855 if (type
&& TYPE_PTR_P (type
)
1856 && !dependent_scope_p (TREE_TYPE (type
)))
1857 /* Pointer to current instantiation, don't treat as dependent. */;
1858 else if (type_dependent_expression_p (expr
))
1859 return build_min_nt_loc (loc
, ARROW_EXPR
, expr
);
1860 expr
= build_non_dependent_expr (expr
);
1863 if (MAYBE_CLASS_TYPE_P (type
))
1865 struct tinst_level
*actual_inst
= current_instantiation ();
1868 while ((expr
= build_new_op (loc
, COMPONENT_REF
,
1869 LOOKUP_NORMAL
, expr
, NULL_TREE
, NULL_TREE
,
1872 if (expr
== error_mark_node
)
1873 return error_mark_node
;
1875 /* This provides a better instantiation backtrace in case of
1877 if (fn
&& DECL_USE_TEMPLATE (fn
))
1878 push_tinst_level_loc (fn
,
1879 (current_instantiation () != actual_inst
)
1880 ? DECL_SOURCE_LOCATION (fn
)
1884 if (vec_member (TREE_TYPE (expr
), types_memoized
))
1886 if (complain
& tf_error
)
1887 error ("circular pointer delegation detected");
1888 return error_mark_node
;
1891 vec_safe_push (types_memoized
, TREE_TYPE (expr
));
1895 while (current_instantiation () != actual_inst
)
1898 if (last_rval
== NULL_TREE
)
1900 if (complain
& tf_error
)
1901 error ("base operand of %<->%> has non-pointer type %qT", type
);
1902 return error_mark_node
;
1905 if (TYPE_REF_P (TREE_TYPE (last_rval
)))
1906 last_rval
= convert_from_reference (last_rval
);
1909 last_rval
= decay_conversion (expr
, complain
);
1911 if (TYPE_PTR_P (TREE_TYPE (last_rval
)))
1913 if (processing_template_decl
)
1915 expr
= build_min (ARROW_EXPR
, TREE_TYPE (TREE_TYPE (last_rval
)),
1917 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (last_rval
);
1921 return cp_build_indirect_ref (last_rval
, RO_ARROW
, complain
);
1924 if (complain
& tf_error
)
1927 error ("result of %<operator->()%> yields non-pointer result");
1929 error ("base operand of %<->%> is not a pointer");
1931 return error_mark_node
;
1934 /* Return an expression for "DATUM .* COMPONENT". DATUM has not
1935 already been checked out to be of aggregate type. */
1938 build_m_component_ref (tree datum
, tree component
, tsubst_flags_t complain
)
1946 if (error_operand_p (datum
) || error_operand_p (component
))
1947 return error_mark_node
;
1949 datum
= mark_lvalue_use (datum
);
1950 component
= mark_rvalue_use (component
);
1952 ptrmem_type
= TREE_TYPE (component
);
1953 if (!TYPE_PTRMEM_P (ptrmem_type
))
1955 if (complain
& tf_error
)
1956 error ("%qE cannot be used as a member pointer, since it is of "
1957 "type %qT", component
, ptrmem_type
);
1958 return error_mark_node
;
1961 objtype
= TYPE_MAIN_VARIANT (TREE_TYPE (datum
));
1962 if (! MAYBE_CLASS_TYPE_P (objtype
))
1964 if (complain
& tf_error
)
1965 error ("cannot apply member pointer %qE to %qE, which is of "
1966 "non-class type %qT", component
, datum
, objtype
);
1967 return error_mark_node
;
1970 type
= TYPE_PTRMEM_POINTED_TO_TYPE (ptrmem_type
);
1971 ctype
= complete_type (TYPE_PTRMEM_CLASS_TYPE (ptrmem_type
));
1973 if (!COMPLETE_TYPE_P (ctype
))
1975 if (!same_type_p (ctype
, objtype
))
1981 binfo
= lookup_base (objtype
, ctype
, ba_check
, NULL
, complain
);
1986 if (complain
& tf_error
)
1987 error ("pointer to member type %qT incompatible with object "
1988 "type %qT", type
, objtype
);
1989 return error_mark_node
;
1991 else if (binfo
== error_mark_node
)
1992 return error_mark_node
;
1995 if (TYPE_PTRDATAMEM_P (ptrmem_type
))
1997 bool is_lval
= real_lvalue_p (datum
);
2000 /* Compute the type of the field, as described in [expr.ref].
2001 There's no such thing as a mutable pointer-to-member, so
2002 things are not as complex as they are for references to
2003 non-static data members. */
2004 type
= cp_build_qualified_type (type
,
2005 (cp_type_quals (type
)
2006 | cp_type_quals (TREE_TYPE (datum
))));
2008 datum
= build_address (datum
);
2010 /* Convert object to the correct base. */
2013 datum
= build_base_path (PLUS_EXPR
, datum
, binfo
, 1, complain
);
2014 if (datum
== error_mark_node
)
2015 return error_mark_node
;
2018 /* Build an expression for "object + offset" where offset is the
2019 value stored in the pointer-to-data-member. */
2020 ptype
= build_pointer_type (type
);
2021 datum
= fold_build_pointer_plus (fold_convert (ptype
, datum
), component
);
2022 datum
= cp_build_fold_indirect_ref (datum
);
2023 if (datum
== error_mark_node
)
2024 return error_mark_node
;
2026 /* If the object expression was an rvalue, return an rvalue. */
2028 datum
= move (datum
);
2033 /* 5.5/6: In a .* expression whose object expression is an rvalue, the
2034 program is ill-formed if the second operand is a pointer to member
2035 function with ref-qualifier & (for C++2A: unless its cv-qualifier-seq
2036 is const). In a .* expression whose object expression is an lvalue,
2037 the program is ill-formed if the second operand is a pointer to member
2038 function with ref-qualifier &&. */
2039 if (FUNCTION_REF_QUALIFIED (type
))
2041 bool lval
= lvalue_p (datum
);
2042 if (lval
&& FUNCTION_RVALUE_QUALIFIED (type
))
2044 if (complain
& tf_error
)
2045 error ("pointer-to-member-function type %qT requires an rvalue",
2047 return error_mark_node
;
2049 else if (!lval
&& !FUNCTION_RVALUE_QUALIFIED (type
))
2051 if ((type_memfn_quals (type
)
2052 & (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
))
2055 if (complain
& tf_error
)
2056 error ("pointer-to-member-function type %qT requires "
2057 "an lvalue", ptrmem_type
);
2058 return error_mark_node
;
2060 else if (cxx_dialect
< cxx2a
)
2062 if (complain
& tf_warning_or_error
)
2063 pedwarn (input_location
, OPT_Wpedantic
,
2064 "pointer-to-member-function type %qT requires "
2065 "an lvalue before C++2a", ptrmem_type
);
2067 return error_mark_node
;
2071 return build2 (OFFSET_REF
, type
, datum
, component
);
2075 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
2078 build_functional_cast (tree exp
, tree parms
, tsubst_flags_t complain
)
2080 /* This is either a call to a constructor,
2081 or a C cast in C++'s `functional' notation. */
2083 /* The type to which we are casting. */
2085 vec
<tree
, va_gc
> *parmvec
;
2087 if (error_operand_p (exp
) || parms
== error_mark_node
)
2088 return error_mark_node
;
2090 if (TREE_CODE (exp
) == TYPE_DECL
)
2092 type
= TREE_TYPE (exp
);
2094 if (DECL_ARTIFICIAL (exp
))
2095 cp_warn_deprecated_use (type
);
2100 /* We need to check this explicitly, since value-initialization of
2101 arrays is allowed in other situations. */
2102 if (TREE_CODE (type
) == ARRAY_TYPE
)
2104 if (complain
& tf_error
)
2105 error ("functional cast to array type %qT", type
);
2106 return error_mark_node
;
2109 if (tree anode
= type_uses_auto (type
))
2111 if (!CLASS_PLACEHOLDER_TEMPLATE (anode
))
2113 if (complain
& tf_error
)
2114 error_at (DECL_SOURCE_LOCATION (TEMPLATE_TYPE_DECL (anode
)),
2115 "invalid use of %qT", anode
);
2116 return error_mark_node
;
2120 if (complain
& tf_error
)
2121 error ("cannot deduce template arguments for %qT from ()", anode
);
2122 return error_mark_node
;
2125 type
= do_auto_deduction (type
, parms
, anode
, complain
,
2129 if (processing_template_decl
)
2133 /* Diagnose this even in a template. We could also try harder
2134 to give all the usual errors when the type and args are
2136 if (TYPE_REF_P (type
) && !parms
)
2138 if (complain
& tf_error
)
2139 error ("invalid value-initialization of reference type");
2140 return error_mark_node
;
2143 t
= build_min (CAST_EXPR
, type
, parms
);
2144 /* We don't know if it will or will not have side effects. */
2145 TREE_SIDE_EFFECTS (t
) = 1;
2149 if (! MAYBE_CLASS_TYPE_P (type
))
2151 if (parms
== NULL_TREE
)
2153 if (VOID_TYPE_P (type
))
2155 return build_value_init (cv_unqualified (type
), complain
);
2158 /* This must build a C cast. */
2159 parms
= build_x_compound_expr_from_list (parms
, ELK_FUNC_CAST
, complain
);
2160 return cp_build_c_cast (type
, parms
, complain
);
2163 /* Prepare to evaluate as a call to a constructor. If this expression
2164 is actually used, for example,
2166 return X (arg1, arg2, ...);
2168 then the slot being initialized will be filled in. */
2170 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
2171 return error_mark_node
;
2172 if (abstract_virtuals_error_sfinae (ACU_CAST
, type
, complain
))
2173 return error_mark_node
;
2177 If the expression list is a single-expression, the type
2178 conversion is equivalent (in definedness, and if defined in
2179 meaning) to the corresponding cast expression. */
2180 if (parms
&& TREE_CHAIN (parms
) == NULL_TREE
)
2181 return cp_build_c_cast (type
, TREE_VALUE (parms
), complain
);
2185 The expression T(), where T is a simple-type-specifier for a
2186 non-array complete object type or the (possibly cv-qualified)
2187 void type, creates an rvalue of the specified type, which is
2188 value-initialized. */
2190 if (parms
== NULL_TREE
)
2192 exp
= build_value_init (type
, complain
);
2193 exp
= get_target_expr_sfinae (exp
, complain
);
2197 /* Call the constructor. */
2198 parmvec
= make_tree_vector ();
2199 for (; parms
!= NULL_TREE
; parms
= TREE_CHAIN (parms
))
2200 vec_safe_push (parmvec
, TREE_VALUE (parms
));
2201 exp
= build_special_member_call (NULL_TREE
, complete_ctor_identifier
,
2202 &parmvec
, type
, LOOKUP_NORMAL
, complain
);
2203 release_tree_vector (parmvec
);
2205 if (exp
== error_mark_node
)
2206 return error_mark_node
;
2208 return build_cplus_new (type
, exp
, complain
);
2212 /* Add new exception specifier SPEC, to the LIST we currently have.
2213 If it's already in LIST then do nothing.
2214 Moan if it's bad and we're allowed to. COMPLAIN < 0 means we
2215 know what we're doing. */
2218 add_exception_specifier (tree list
, tree spec
, tsubst_flags_t complain
)
2223 diagnostic_t diag_type
= DK_UNSPECIFIED
; /* none */
2225 if (spec
== error_mark_node
)
2228 gcc_assert (spec
&& (!list
|| TREE_VALUE (list
)));
2230 /* [except.spec] 1, type in an exception specifier shall not be
2231 incomplete, or pointer or ref to incomplete other than pointer
2233 is_ptr
= TYPE_PTR_P (core
);
2234 if (is_ptr
|| TYPE_REF_P (core
))
2235 core
= TREE_TYPE (core
);
2238 else if (VOID_TYPE_P (core
))
2240 else if (TREE_CODE (core
) == TEMPLATE_TYPE_PARM
)
2242 else if (processing_template_decl
)
2247 /* 15.4/1 says that types in an exception specifier must be complete,
2248 but it seems more reasonable to only require this on definitions
2249 and calls. So just give a pedwarn at this point; we will give an
2250 error later if we hit one of those two cases. */
2251 if (!COMPLETE_TYPE_P (complete_type (core
)))
2252 diag_type
= DK_PEDWARN
; /* pedwarn */
2259 for (probe
= list
; probe
; probe
= TREE_CHAIN (probe
))
2260 if (same_type_p (TREE_VALUE (probe
), spec
))
2263 list
= tree_cons (NULL_TREE
, spec
, list
);
2266 diag_type
= DK_ERROR
; /* error */
2268 if (diag_type
!= DK_UNSPECIFIED
2269 && (complain
& tf_warning_or_error
))
2270 cxx_incomplete_type_diagnostic (NULL_TREE
, core
, diag_type
);
2275 /* Like nothrow_spec_p, but don't abort on deferred noexcept. */
2278 nothrow_spec_p_uninst (const_tree spec
)
2280 if (DEFERRED_NOEXCEPT_SPEC_P (spec
))
2282 return nothrow_spec_p (spec
);
2285 /* Combine the two exceptions specifier lists LIST and ADD, and return
2289 merge_exception_specifiers (tree list
, tree add
)
2291 tree noex
, orig_list
;
2293 /* No exception-specifier or noexcept(false) are less strict than
2294 anything else. Prefer the newer variant (LIST). */
2295 if (!list
|| list
== noexcept_false_spec
)
2297 else if (!add
|| add
== noexcept_false_spec
)
2300 /* noexcept(true) and throw() are stricter than anything else.
2301 As above, prefer the more recent one (LIST). */
2302 if (nothrow_spec_p_uninst (add
))
2305 /* Two implicit noexcept specs (e.g. on a destructor) are equivalent. */
2306 if (UNEVALUATED_NOEXCEPT_SPEC_P (add
)
2307 && UNEVALUATED_NOEXCEPT_SPEC_P (list
))
2309 /* We should have instantiated other deferred noexcept specs by now. */
2310 gcc_assert (!DEFERRED_NOEXCEPT_SPEC_P (add
));
2312 if (nothrow_spec_p_uninst (list
))
2314 noex
= TREE_PURPOSE (list
);
2315 gcc_checking_assert (!TREE_PURPOSE (add
)
2316 || errorcount
|| !flag_exceptions
2317 || cp_tree_equal (noex
, TREE_PURPOSE (add
)));
2319 /* Combine the dynamic-exception-specifiers, if any. */
2321 for (; add
&& TREE_VALUE (add
); add
= TREE_CHAIN (add
))
2323 tree spec
= TREE_VALUE (add
);
2326 for (probe
= orig_list
; probe
&& TREE_VALUE (probe
);
2327 probe
= TREE_CHAIN (probe
))
2328 if (same_type_p (TREE_VALUE (probe
), spec
))
2332 spec
= build_tree_list (NULL_TREE
, spec
);
2333 TREE_CHAIN (spec
) = list
;
2338 /* Keep the noexcept-specifier at the beginning of the list. */
2339 if (noex
!= TREE_PURPOSE (list
))
2340 list
= tree_cons (noex
, TREE_VALUE (list
), TREE_CHAIN (list
));
2345 /* Subroutine of build_call. Ensure that each of the types in the
2346 exception specification is complete. Technically, 15.4/1 says that
2347 they need to be complete when we see a declaration of the function,
2348 but we should be able to get away with only requiring this when the
2349 function is defined or called. See also add_exception_specifier. */
2352 require_complete_eh_spec_types (tree fntype
, tree decl
)
2355 /* Don't complain about calls to op new. */
2356 if (decl
&& DECL_ARTIFICIAL (decl
))
2358 for (raises
= TYPE_RAISES_EXCEPTIONS (fntype
); raises
;
2359 raises
= TREE_CHAIN (raises
))
2361 tree type
= TREE_VALUE (raises
);
2362 if (type
&& !COMPLETE_TYPE_P (type
))
2366 ("call to function %qD which throws incomplete type %q#T",
2369 error ("call to function which throws incomplete type %q#T",
2376 #include "gt-cp-typeck2.h"