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"
35 #include "gcc-rich-location.h"
38 process_init_constructor (tree type
, tree init
, int nested
,
39 tsubst_flags_t complain
);
42 /* Print an error message stemming from an attempt to use
43 BASETYPE as a base class for TYPE. */
46 error_not_base_type (tree basetype
, tree type
)
48 if (TREE_CODE (basetype
) == FUNCTION_DECL
)
49 basetype
= DECL_CONTEXT (basetype
);
50 error ("type %qT is not a base type for type %qT", basetype
, type
);
51 return error_mark_node
;
55 binfo_or_else (tree base
, tree type
)
57 tree binfo
= lookup_base (type
, base
, ba_unique
,
58 NULL
, tf_warning_or_error
);
60 if (binfo
== error_mark_node
)
63 error_not_base_type (base
, type
);
67 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
68 value may not be changed thereafter. */
71 cxx_readonly_error (location_t loc
, tree arg
, enum lvalue_use errstring
)
74 /* This macro is used to emit diagnostics to ensure that all format
75 strings are complete sentences, visible to gettext and checked at
78 #define ERROR_FOR_ASSIGNMENT(LOC, AS, ASM, IN, DE, ARG) \
83 error_at (LOC, AS, ARG); \
86 error_at (LOC, ASM, ARG); \
89 error_at (LOC, IN, ARG); \
92 error_at (LOC, DE, ARG); \
99 /* Handle C++-specific things first. */
102 && DECL_LANG_SPECIFIC (arg
)
103 && DECL_IN_AGGR_P (arg
)
104 && !TREE_STATIC (arg
))
105 ERROR_FOR_ASSIGNMENT (loc
,
106 G_("assignment of constant field %qD"),
107 G_("constant field %qD used as %<asm%> output"),
108 G_("increment of constant field %qD"),
109 G_("decrement of constant field %qD"),
111 else if (INDIRECT_REF_P (arg
)
112 && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (arg
, 0)))
113 && (VAR_P (TREE_OPERAND (arg
, 0))
114 || TREE_CODE (TREE_OPERAND (arg
, 0)) == PARM_DECL
))
115 ERROR_FOR_ASSIGNMENT (loc
,
116 G_("assignment of read-only reference %qD"),
117 G_("read-only reference %qD used as %<asm%> output"),
118 G_("increment of read-only reference %qD"),
119 G_("decrement of read-only reference %qD"),
120 TREE_OPERAND (arg
, 0));
122 readonly_error (loc
, arg
, errstring
);
125 /* Structure that holds information about declarations whose type was
126 incomplete and we could not check whether it was abstract or not. */
128 struct GTY((chain_next ("%h.next"), for_user
)) pending_abstract_type
{
129 /* Declaration which we are checking for abstractness. It is either
130 a DECL node, or an IDENTIFIER_NODE if we do not have a full
131 declaration available. */
134 /* Type which will be checked for abstractness. */
137 /* Kind of use in an unnamed declarator. */
138 enum abstract_class_use use
;
140 /* Position of the declaration. This is only needed for IDENTIFIER_NODEs,
141 because DECLs already carry locus information. */
144 /* Link to the next element in list. */
145 struct pending_abstract_type
* next
;
148 struct abstract_type_hasher
: ggc_ptr_hash
<pending_abstract_type
>
150 typedef tree compare_type
;
151 static hashval_t
hash (pending_abstract_type
*);
152 static bool equal (pending_abstract_type
*, tree
);
155 /* Compute the hash value of the node VAL. This function is used by the
156 hash table abstract_pending_vars. */
159 abstract_type_hasher::hash (pending_abstract_type
*pat
)
161 return (hashval_t
) TYPE_UID (pat
->type
);
165 /* Compare node VAL1 with the type VAL2. This function is used by the
166 hash table abstract_pending_vars. */
169 abstract_type_hasher::equal (pending_abstract_type
*pat1
, tree type2
)
171 return (pat1
->type
== type2
);
174 /* Hash table that maintains pending_abstract_type nodes, for which we still
175 need to check for type abstractness. The key of the table is the type
176 of the declaration. */
177 static GTY (()) hash_table
<abstract_type_hasher
> *abstract_pending_vars
= NULL
;
179 static int abstract_virtuals_error_sfinae (tree
, tree
, abstract_class_use
, tsubst_flags_t
);
181 /* This function is called after TYPE is completed, and will check if there
182 are pending declarations for which we still need to verify the abstractness
183 of TYPE, and emit a diagnostic (through abstract_virtuals_error) if TYPE
184 turned out to be incomplete. */
187 complete_type_check_abstract (tree type
)
189 struct pending_abstract_type
*pat
;
190 location_t cur_loc
= input_location
;
192 gcc_assert (COMPLETE_TYPE_P (type
));
194 if (!abstract_pending_vars
)
197 /* Retrieve the list of pending declarations for this type. */
198 pending_abstract_type
**slot
199 = abstract_pending_vars
->find_slot_with_hash (type
, TYPE_UID (type
),
206 /* If the type is not abstract, do not do anything. */
207 if (CLASSTYPE_PURE_VIRTUALS (type
))
209 struct pending_abstract_type
*prev
= 0, *next
;
211 /* Reverse the list to emit the errors in top-down order. */
212 for (; pat
; pat
= next
)
220 /* Go through the list, and call abstract_virtuals_error for each
221 element: it will issue a diagnostic if the type is abstract. */
224 gcc_assert (type
== pat
->type
);
226 /* Tweak input_location so that the diagnostic appears at the correct
227 location. Notice that this is only needed if the decl is an
229 input_location
= pat
->locus
;
230 abstract_virtuals_error_sfinae (pat
->decl
, pat
->type
, pat
->use
,
231 tf_warning_or_error
);
236 abstract_pending_vars
->clear_slot (slot
);
238 input_location
= cur_loc
;
242 /* If TYPE has abstract virtual functions, issue an error about trying
243 to create an object of that type. DECL is the object declared, or
244 NULL_TREE if the declaration is unavailable, in which case USE specifies
245 the kind of invalid use. Returns 1 if an error occurred; zero if
249 abstract_virtuals_error_sfinae (tree decl
, tree type
, abstract_class_use use
,
250 tsubst_flags_t complain
)
252 vec
<tree
, va_gc
> *pure
;
254 /* This function applies only to classes. Any other entity can never
256 if (!CLASS_TYPE_P (type
))
258 type
= TYPE_MAIN_VARIANT (type
);
261 /* Instantiation here seems to be required by the standard,
262 but breaks e.g. boost::bind. FIXME! */
263 /* In SFINAE, non-N3276 context, force instantiation. */
264 if (!(complain
& (tf_error
|tf_decltype
)))
265 complete_type (type
);
268 /* If the type is incomplete, we register it within a hash table,
269 so that we can check again once it is completed. This makes sense
270 only for objects for which we have a declaration or at least a
272 if (!COMPLETE_TYPE_P (type
) && (complain
& tf_error
))
274 struct pending_abstract_type
*pat
;
276 gcc_assert (!decl
|| DECL_P (decl
) || identifier_p (decl
));
278 if (!abstract_pending_vars
)
279 abstract_pending_vars
280 = hash_table
<abstract_type_hasher
>::create_ggc (31);
282 pending_abstract_type
**slot
283 = abstract_pending_vars
->find_slot_with_hash (type
, TYPE_UID (type
),
286 pat
= ggc_alloc
<pending_abstract_type
> ();
290 pat
->locus
= ((decl
&& DECL_P (decl
))
291 ? DECL_SOURCE_LOCATION (decl
)
300 if (!TYPE_SIZE (type
))
301 /* TYPE is being defined, and during that time
302 CLASSTYPE_PURE_VIRTUALS holds the inline friends. */
305 pure
= CLASSTYPE_PURE_VIRTUALS (type
);
309 if (!(complain
& tf_error
))
312 auto_diagnostic_group d
;
316 error ("cannot declare variable %q+D to be of abstract "
317 "type %qT", decl
, type
);
318 else if (TREE_CODE (decl
) == PARM_DECL
)
320 if (DECL_NAME (decl
))
321 error ("cannot declare parameter %q+D to be of abstract type %qT",
324 error ("cannot declare parameter to be of abstract type %qT",
327 else if (TREE_CODE (decl
) == FIELD_DECL
)
328 error ("cannot declare field %q+D to be of abstract type %qT",
330 else if (TREE_CODE (decl
) == FUNCTION_DECL
331 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
332 error ("invalid abstract return type for member function %q+#D", decl
);
333 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
334 error ("invalid abstract return type for function %q+#D", decl
);
335 else if (identifier_p (decl
))
336 /* Here we do not have location information. */
337 error ("invalid abstract type %qT for %qE", type
, decl
);
339 error ("invalid abstract type for %q+D", decl
);
344 error ("creating array of %qT, which is an abstract class type", type
);
347 error ("invalid cast to abstract class type %qT", type
);
350 error ("invalid new-expression of abstract class type %qT", type
);
353 error ("invalid abstract return type %qT", type
);
356 error ("invalid abstract parameter type %qT", type
);
359 error ("expression of abstract class type %qT cannot "
360 "be used in throw-expression", type
);
363 error ("cannot declare catch parameter to be of abstract "
364 "class type %qT", type
);
367 error ("cannot allocate an object of abstract type %qT", type
);
370 /* Only go through this once. */
376 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type
)),
377 " because the following virtual functions are pure within %qT:",
380 FOR_EACH_VEC_ELT (*pure
, ix
, fn
)
381 if (! DECL_CLONED_FUNCTION_P (fn
)
382 || DECL_COMPLETE_DESTRUCTOR_P (fn
))
383 inform (DECL_SOURCE_LOCATION (fn
), "\t%#qD", fn
);
385 /* Now truncate the vector. This leaves it non-null, so we know
386 there are pure virtuals, but empty so we don't list them out
395 abstract_virtuals_error_sfinae (tree decl
, tree type
, tsubst_flags_t complain
)
397 return abstract_virtuals_error_sfinae (decl
, type
, ACU_UNKNOWN
, complain
);
401 abstract_virtuals_error_sfinae (abstract_class_use use
, tree type
,
402 tsubst_flags_t complain
)
404 return abstract_virtuals_error_sfinae (NULL_TREE
, type
, use
, complain
);
408 /* Wrapper for the above function in the common case of wanting errors. */
411 abstract_virtuals_error (tree decl
, tree type
)
413 return abstract_virtuals_error_sfinae (decl
, type
, tf_warning_or_error
);
417 abstract_virtuals_error (abstract_class_use use
, tree type
)
419 return abstract_virtuals_error_sfinae (use
, type
, tf_warning_or_error
);
422 /* Print an inform about the declaration of the incomplete type TYPE. */
425 cxx_incomplete_type_inform (const_tree type
)
427 if (!TYPE_MAIN_DECL (type
))
430 location_t loc
= DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type
));
431 tree ptype
= strip_top_quals (CONST_CAST_TREE (type
));
433 if (current_class_type
434 && TYPE_BEING_DEFINED (current_class_type
)
435 && same_type_p (ptype
, current_class_type
))
436 inform (loc
, "definition of %q#T is not complete until "
437 "the closing brace", ptype
);
438 else if (!TYPE_TEMPLATE_INFO (ptype
))
439 inform (loc
, "forward declaration of %q#T", ptype
);
441 inform (loc
, "declaration of %q#T", ptype
);
444 /* Print an error message for invalid use of an incomplete type.
445 VALUE is the expression that was used (or 0 if that isn't known)
446 and TYPE is the type that was invalid. DIAG_KIND indicates the
447 type of diagnostic (see diagnostic.def). */
450 cxx_incomplete_type_diagnostic (location_t loc
, const_tree value
,
451 const_tree type
, diagnostic_t diag_kind
)
453 bool is_decl
= false, complained
= false;
455 gcc_assert (diag_kind
== DK_WARNING
456 || diag_kind
== DK_PEDWARN
457 || diag_kind
== DK_ERROR
);
459 /* Avoid duplicate error message. */
460 if (TREE_CODE (type
) == ERROR_MARK
)
463 if (value
!= 0 && (VAR_P (value
)
464 || TREE_CODE (value
) == PARM_DECL
465 || TREE_CODE (value
) == FIELD_DECL
))
467 complained
= emit_diagnostic (diag_kind
, DECL_SOURCE_LOCATION (value
), 0,
468 "%qD has incomplete type", value
);
472 /* We must print an error message. Be clever about what it says. */
474 switch (TREE_CODE (type
))
480 complained
= emit_diagnostic (diag_kind
, loc
, 0,
481 "invalid use of incomplete type %q#T",
484 cxx_incomplete_type_inform (type
);
488 emit_diagnostic (diag_kind
, loc
, 0,
489 "invalid use of %qT", type
);
493 if (TYPE_DOMAIN (type
))
495 type
= TREE_TYPE (type
);
498 emit_diagnostic (diag_kind
, loc
, 0,
499 "invalid use of array with unspecified bounds");
505 tree member
= TREE_OPERAND (value
, 1);
506 if (is_overloaded_fn (member
))
507 member
= get_first_fn (member
);
509 if (DECL_FUNCTION_MEMBER_P (member
)
510 && ! flag_ms_extensions
)
512 gcc_rich_location
richloc (loc
);
513 /* If "member" has no arguments (other than "this"), then
514 add a fix-it hint. */
515 if (type_num_arguments (TREE_TYPE (member
)) == 1)
516 richloc
.add_fixit_insert_after ("()");
517 emit_diagnostic (diag_kind
, &richloc
, 0,
518 "invalid use of member function %qD "
519 "(did you forget the %<()%> ?)", member
);
522 emit_diagnostic (diag_kind
, loc
, 0,
523 "invalid use of member %qD "
524 "(did you forget the %<&%> ?)", member
);
528 case TEMPLATE_TYPE_PARM
:
531 if (CLASS_PLACEHOLDER_TEMPLATE (type
))
532 emit_diagnostic (diag_kind
, loc
, 0,
533 "invalid use of placeholder %qT", type
);
535 emit_diagnostic (diag_kind
, loc
, 0,
536 "invalid use of %qT", type
);
539 emit_diagnostic (diag_kind
, loc
, 0,
540 "invalid use of template type parameter %qT", type
);
543 case BOUND_TEMPLATE_TEMPLATE_PARM
:
544 emit_diagnostic (diag_kind
, loc
, 0,
545 "invalid use of template template parameter %qT",
551 emit_diagnostic (diag_kind
, loc
, 0,
552 "invalid use of dependent type %qT", type
);
556 if (type
== init_list_type_node
)
558 emit_diagnostic (diag_kind
, loc
, 0,
559 "invalid use of brace-enclosed initializer list");
562 gcc_assert (type
== unknown_type_node
);
563 if (value
&& TREE_CODE (value
) == COMPONENT_REF
)
565 else if (value
&& TREE_CODE (value
) == ADDR_EXPR
)
566 emit_diagnostic (diag_kind
, loc
, 0,
567 "address of overloaded function with no contextual "
569 else if (value
&& TREE_CODE (value
) == OVERLOAD
)
570 emit_diagnostic (diag_kind
, loc
, 0,
571 "overloaded function with no contextual type information");
573 emit_diagnostic (diag_kind
, loc
, 0,
574 "insufficient contextual information to determine type");
582 /* Print an error message for invalid use of an incomplete type.
583 VALUE is the expression that was used (or 0 if that isn't known)
584 and TYPE is the type that was invalid. */
587 cxx_incomplete_type_error (location_t loc
, const_tree value
, const_tree type
)
589 cxx_incomplete_type_diagnostic (loc
, value
, type
, DK_ERROR
);
593 /* The recursive part of split_nonconstant_init. DEST is an lvalue
594 expression to which INIT should be assigned. INIT is a CONSTRUCTOR.
595 Return true if the whole of the value was initialized by the
596 generated statements. */
599 split_nonconstant_init_1 (tree dest
, tree init
)
601 unsigned HOST_WIDE_INT idx
;
602 tree field_index
, value
;
603 tree type
= TREE_TYPE (dest
);
604 tree inner_type
= NULL
;
605 bool array_type_p
= false;
606 bool complete_p
= true;
607 HOST_WIDE_INT num_split_elts
= 0;
609 switch (TREE_CODE (type
))
612 inner_type
= TREE_TYPE (type
);
614 if ((TREE_SIDE_EFFECTS (init
)
615 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
616 || vla_type_p (type
))
618 /* For an array, we only need/want a single cleanup region rather
619 than one per element. */
620 tree code
= build_vec_init (dest
, NULL_TREE
, init
, false, 1,
621 tf_warning_or_error
);
629 case QUAL_UNION_TYPE
:
630 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), idx
,
633 /* The current implementation of this algorithm assumes that
634 the field was set for all the elements. This is usually done
635 by process_init_constructor. */
636 gcc_assert (field_index
);
639 inner_type
= TREE_TYPE (field_index
);
641 if (TREE_CODE (value
) == CONSTRUCTOR
)
646 sub
= build4 (ARRAY_REF
, inner_type
, dest
, field_index
,
647 NULL_TREE
, NULL_TREE
);
649 sub
= build3 (COMPONENT_REF
, inner_type
, dest
, field_index
,
652 if (!split_nonconstant_init_1 (sub
, value
))
655 CONSTRUCTOR_ELTS (init
)->ordered_remove (idx
--);
658 else if (!initializer_constant_valid_p (value
, inner_type
))
663 /* FIXME: Ordered removal is O(1) so the whole function is
664 worst-case quadratic. This could be fixed using an aside
665 bitmap to record which elements must be removed and remove
666 them all at the same time. Or by merging
667 split_non_constant_init into process_init_constructor_array,
668 that is separating constants from non-constants while building
670 CONSTRUCTOR_ELTS (init
)->ordered_remove (idx
);
673 if (TREE_CODE (field_index
) == RANGE_EXPR
)
675 /* Use build_vec_init to initialize a range. */
676 tree low
= TREE_OPERAND (field_index
, 0);
677 tree hi
= TREE_OPERAND (field_index
, 1);
678 sub
= build4 (ARRAY_REF
, inner_type
, dest
, low
,
679 NULL_TREE
, NULL_TREE
);
680 sub
= cp_build_addr_expr (sub
, tf_warning_or_error
);
681 tree max
= size_binop (MINUS_EXPR
, hi
, low
);
682 code
= build_vec_init (sub
, max
, value
, false, 0,
683 tf_warning_or_error
);
685 if (tree_fits_shwi_p (max
))
686 num_split_elts
+= tree_to_shwi (max
);
691 sub
= build4 (ARRAY_REF
, inner_type
, dest
, field_index
,
692 NULL_TREE
, NULL_TREE
);
694 sub
= build3 (COMPONENT_REF
, inner_type
, dest
, field_index
,
697 code
= build2 (INIT_EXPR
, inner_type
, sub
, value
);
698 code
= build_stmt (input_location
, EXPR_STMT
, code
);
699 code
= maybe_cleanup_point_expr_void (code
);
702 = cxx_maybe_build_cleanup (sub
, tf_warning_or_error
))
703 finish_eh_cleanup (cleanup
);
712 if (!initializer_constant_valid_p (init
, type
))
715 tree cons
= copy_node (init
);
716 CONSTRUCTOR_ELTS (init
) = NULL
;
717 code
= build2 (MODIFY_EXPR
, type
, dest
, cons
);
718 code
= build_stmt (input_location
, EXPR_STMT
, code
);
720 num_split_elts
+= CONSTRUCTOR_NELTS (init
);
728 /* The rest of the initializer is now a constant. */
729 TREE_CONSTANT (init
) = 1;
731 /* We didn't split out anything. */
732 if (num_split_elts
== 0)
735 return complete_p
&& complete_ctor_at_level_p (TREE_TYPE (init
),
736 num_split_elts
, inner_type
);
739 /* A subroutine of store_init_value. Splits non-constant static
740 initializer INIT into a constant part and generates code to
741 perform the non-constant part of the initialization to DEST.
742 Returns the code for the runtime init. */
745 split_nonconstant_init (tree dest
, tree init
)
749 if (TREE_CODE (init
) == TARGET_EXPR
)
750 init
= TARGET_EXPR_INITIAL (init
);
751 if (TREE_CODE (init
) == CONSTRUCTOR
)
753 init
= cp_fully_fold (init
);
754 code
= push_stmt_list ();
755 if (split_nonconstant_init_1 (dest
, init
))
757 code
= pop_stmt_list (code
);
758 DECL_INITIAL (dest
) = init
;
759 TREE_READONLY (dest
) = 0;
761 else if (TREE_CODE (init
) == STRING_CST
762 && array_of_runtime_bound_p (TREE_TYPE (dest
)))
763 code
= build_vec_init (dest
, NULL_TREE
, init
, /*value-init*/false,
764 /*from array*/1, tf_warning_or_error
);
766 code
= build2 (INIT_EXPR
, TREE_TYPE (dest
), dest
, init
);
771 /* Perform appropriate conversions on the initial value of a variable,
772 store it in the declaration DECL,
773 and print any error messages that are appropriate.
774 If the init is invalid, store an ERROR_MARK.
776 C++: Note that INIT might be a TREE_LIST, which would mean that it is
777 a base class initializer for some aggregate type, hopefully compatible
778 with DECL. If INIT is a single element, and DECL is an aggregate
779 type, we silently convert INIT into a TREE_LIST, allowing a constructor
782 If INIT is a TREE_LIST and there is no constructor, turn INIT
783 into a CONSTRUCTOR and use standard initialization techniques.
784 Perhaps a warning should be generated?
786 Returns code to be executed if initialization could not be performed
787 for static variable. In that case, caller must emit the code. */
790 store_init_value (tree decl
, tree init
, vec
<tree
, va_gc
>** cleanups
, int flags
)
794 /* If variable's type was invalidly declared, just ignore it. */
796 type
= TREE_TYPE (decl
);
797 if (TREE_CODE (type
) == ERROR_MARK
)
800 if (MAYBE_CLASS_TYPE_P (type
))
802 if (TREE_CODE (init
) == TREE_LIST
)
804 error ("constructor syntax used, but no constructor declared "
805 "for type %qT", type
);
806 init
= build_constructor_from_list (init_list_type_node
, nreverse (init
));
810 /* End of special C++ code. */
812 if (flags
& LOOKUP_ALREADY_DIGESTED
)
815 /* Digest the specified initializer into an expression. */
816 value
= digest_init_flags (type
, init
, flags
, tf_warning_or_error
);
818 if (TREE_CODE (type
) == ARRAY_TYPE
819 && TYPE_STRING_FLAG (TREE_TYPE (type
))
820 && TREE_CODE (value
) == CONSTRUCTOR
)
821 value
= braced_list_to_string (type
, value
);
823 value
= extend_ref_init_temps (decl
, value
, cleanups
);
825 /* In C++11 constant expression is a semantic, not syntactic, property.
826 In C++98, make sure that what we thought was a constant expression at
827 template definition time is still constant and otherwise perform this
828 as optimization, e.g. to fold SIZEOF_EXPRs in the initializer. */
829 if (decl_maybe_constant_var_p (decl
) || TREE_STATIC (decl
))
833 value
= fold_non_dependent_expr (value
);
834 if (DECL_DECLARED_CONSTEXPR_P (decl
)
835 || (DECL_IN_AGGR_P (decl
)
836 && DECL_INITIALIZED_IN_CLASS_P (decl
)
837 && !DECL_VAR_DECLARED_INLINE_P (decl
)))
839 /* Diagnose a non-constant initializer for constexpr variable or
840 non-inline in-class-initialized static data member. */
841 if (!require_constant_expression (value
))
842 value
= error_mark_node
;
844 value
= cxx_constant_init (value
, decl
);
847 value
= maybe_constant_init (value
, decl
, true);
848 if (TREE_CODE (value
) == CONSTRUCTOR
&& cp_has_mutable_p (type
))
849 /* Poison this CONSTRUCTOR so it can't be copied to another
850 constexpr variable. */
851 CONSTRUCTOR_MUTABLE_POISON (value
) = true;
852 const_init
= (reduced_constant_expression_p (value
)
853 || error_operand_p (value
));
854 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = const_init
;
855 /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
856 if (!TYPE_REF_P (type
))
857 TREE_CONSTANT (decl
) = const_init
&& decl_maybe_constant_var_p (decl
);
861 value
= cp_fully_fold (value
);
863 /* Handle aggregate NSDMI in non-constant initializers, too. */
864 value
= replace_placeholders (value
, decl
);
866 /* DECL may change value; purge caches. */
867 clear_cv_and_fold_caches ();
869 /* If the initializer is not a constant, fill in DECL_INITIAL with
870 the bits that are constant, and then return an expression that
871 will perform the dynamic initialization. */
872 if (value
!= error_mark_node
873 && (TREE_SIDE_EFFECTS (value
)
875 || ! reduced_constant_expression_p (value
)))
876 return split_nonconstant_init (decl
, value
);
877 /* If the value is a constant, just put it in DECL_INITIAL. If DECL
878 is an automatic variable, the middle end will turn this into a
879 dynamic initialization later. */
880 DECL_INITIAL (decl
) = value
;
885 /* Give diagnostic about narrowing conversions within { }, or as part of
886 a converted constant expression. If CONST_ONLY, only check
890 check_narrowing (tree type
, tree init
, tsubst_flags_t complain
, bool const_only
)
892 tree ftype
= unlowered_expr_type (init
);
896 if (((!warn_narrowing
|| !(complain
& tf_warning
))
897 && cxx_dialect
== cxx98
)
898 || !ARITHMETIC_TYPE_P (type
)
899 /* Don't emit bogus warnings with e.g. value-dependent trees. */
900 || instantiation_dependent_expression_p (init
))
903 if (BRACE_ENCLOSED_INITIALIZER_P (init
)
904 && TREE_CODE (type
) == COMPLEX_TYPE
)
906 tree elttype
= TREE_TYPE (type
);
907 if (CONSTRUCTOR_NELTS (init
) > 0)
908 ok
&= check_narrowing (elttype
, CONSTRUCTOR_ELT (init
, 0)->value
,
910 if (CONSTRUCTOR_NELTS (init
) > 1)
911 ok
&= check_narrowing (elttype
, CONSTRUCTOR_ELT (init
, 1)->value
,
916 init
= maybe_constant_value (init
);
918 /* If we were asked to only check constants, return early. */
919 if (const_only
&& !TREE_CONSTANT (init
))
922 if (CP_INTEGRAL_TYPE_P (type
)
923 && TREE_CODE (ftype
) == REAL_TYPE
)
925 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype
)
926 && CP_INTEGRAL_TYPE_P (type
))
928 if (TREE_CODE (ftype
) == ENUMERAL_TYPE
)
929 /* Check for narrowing based on the values of the enumeration. */
930 ftype
= ENUM_UNDERLYING_TYPE (ftype
);
931 if ((tree_int_cst_lt (TYPE_MAX_VALUE (type
),
932 TYPE_MAX_VALUE (ftype
))
933 || tree_int_cst_lt (TYPE_MIN_VALUE (ftype
),
934 TYPE_MIN_VALUE (type
)))
935 && (TREE_CODE (init
) != INTEGER_CST
936 || !int_fits_type_p (init
, type
)))
939 else if (TREE_CODE (ftype
) == REAL_TYPE
940 && TREE_CODE (type
) == REAL_TYPE
)
942 if (TYPE_PRECISION (type
) < TYPE_PRECISION (ftype
))
944 if (TREE_CODE (init
) == REAL_CST
)
946 /* Issue 703: Loss of precision is OK as long as the value is
947 within the representable range of the new type. */
949 d
= TREE_REAL_CST (init
);
950 real_convert (&r
, TYPE_MODE (type
), &d
);
958 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype
)
959 && TREE_CODE (type
) == REAL_TYPE
)
962 if (TREE_CODE (init
) == INTEGER_CST
)
964 d
= real_value_from_int_cst (0, init
);
965 if (exact_real_truncate (TYPE_MODE (type
), &d
))
971 if (!ok
&& !CONSTANT_CLASS_P (init
) && (complain
& tf_warning_or_error
))
973 tree folded
= cp_fully_fold (init
);
974 if (TREE_CONSTANT (folded
) && check_narrowing (type
, folded
, tf_none
))
980 location_t loc
= cp_expr_loc_or_loc (init
, input_location
);
981 if (cxx_dialect
== cxx98
)
983 if (complain
& tf_warning
)
984 warning_at (loc
, OPT_Wnarrowing
, "narrowing conversion of %qE "
985 "from %qH to %qI is ill-formed in C++11",
989 else if (!CONSTANT_CLASS_P (init
))
991 if (complain
& tf_warning_or_error
)
993 auto_diagnostic_group d
;
994 if ((!almost_ok
|| pedantic
)
995 && pedwarn (loc
, OPT_Wnarrowing
,
996 "narrowing conversion of %qE from %qH to %qI",
999 inform (loc
, " the expression has a constant value but is not "
1000 "a C++ constant-expression");
1004 else if (complain
& tf_error
)
1006 int savederrorcount
= errorcount
;
1007 global_dc
->pedantic_errors
= 1;
1008 pedwarn (loc
, OPT_Wnarrowing
,
1009 "narrowing conversion of %qE from %qH to %qI ",
1011 if (errorcount
== savederrorcount
)
1013 global_dc
->pedantic_errors
= flag_pedantic_errors
;
1020 /* Process the initializer INIT for a variable of type TYPE, emitting
1021 diagnostics for invalid initializers and converting the initializer as
1024 For aggregate types, it assumes that reshape_init has already run, thus the
1025 initializer will have the right shape (brace elision has been undone).
1027 NESTED is non-zero iff we are being called for an element of a CONSTRUCTOR,
1028 2 iff the element of a CONSTRUCTOR is inside another CONSTRUCTOR. */
1031 digest_init_r (tree type
, tree init
, int nested
, int flags
,
1032 tsubst_flags_t complain
)
1034 enum tree_code code
= TREE_CODE (type
);
1036 if (error_operand_p (init
))
1037 return error_mark_node
;
1041 /* We must strip the outermost array type when completing the type,
1042 because the its bounds might be incomplete at the moment. */
1043 if (!complete_type_or_maybe_complain (code
== ARRAY_TYPE
1044 ? TREE_TYPE (type
) : type
, NULL_TREE
,
1046 return error_mark_node
;
1048 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue
1049 (g++.old-deja/g++.law/casts2.C). */
1050 if (TREE_CODE (init
) == NON_LVALUE_EXPR
)
1051 init
= TREE_OPERAND (init
, 0);
1053 location_t loc
= cp_expr_loc_or_loc (init
, input_location
);
1055 /* Initialization of an array of chars from a string constant. The initializer
1056 can be optionally enclosed in braces, but reshape_init has already removed
1057 them if they were present. */
1058 if (code
== ARRAY_TYPE
)
1060 if (nested
&& !TYPE_DOMAIN (type
))
1061 /* C++ flexible array members have a null domain. */
1062 pedwarn (loc
, OPT_Wpedantic
,
1063 "initialization of a flexible array member");
1065 tree typ1
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
1066 if (char_type_p (typ1
)
1068 && TREE_CODE (init
) == STRING_CST
)
1070 tree char_type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init
)));
1072 if (TYPE_PRECISION (typ1
) == BITS_PER_UNIT
)
1074 if (char_type
!= char_type_node
1075 && char_type
!= signed_char_type_node
1076 && char_type
!= unsigned_char_type_node
)
1078 if (complain
& tf_error
)
1079 error_at (loc
, "char-array initialized from wide string");
1080 return error_mark_node
;
1085 if (char_type
== char_type_node
1086 || char_type
== signed_char_type_node
1087 || char_type
== unsigned_char_type_node
)
1089 if (complain
& tf_error
)
1091 "int-array initialized from non-wide string");
1092 return error_mark_node
;
1094 else if (char_type
!= typ1
)
1096 if (complain
& tf_error
)
1097 error_at (loc
, "int-array initialized from incompatible "
1099 return error_mark_node
;
1103 if (nested
== 2 && !TYPE_DOMAIN (type
))
1105 if (complain
& tf_error
)
1106 error_at (loc
, "initialization of flexible array member "
1107 "in a nested context");
1108 return error_mark_node
;
1111 if (type
!= TREE_TYPE (init
)
1112 && !variably_modified_type_p (type
, NULL_TREE
))
1114 init
= copy_node (init
);
1115 TREE_TYPE (init
) = type
;
1117 if (TYPE_DOMAIN (type
) && TREE_CONSTANT (TYPE_SIZE (type
)))
1119 /* Not a flexible array member. */
1120 int size
= TREE_INT_CST_LOW (TYPE_SIZE (type
));
1121 size
= (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
1122 /* In C it is ok to subtract 1 from the length of the string
1123 because it's ok to ignore the terminating null char that is
1124 counted in the length of the constant, but in C++ this would
1126 if (size
< TREE_STRING_LENGTH (init
))
1128 permerror (loc
, "initializer-string for array "
1129 "of chars is too long");
1131 init
= build_string (size
, TREE_STRING_POINTER (init
));
1132 TREE_TYPE (init
) = type
;
1139 /* Handle scalar types (including conversions) and references. */
1140 if ((code
!= COMPLEX_TYPE
|| BRACE_ENCLOSED_INITIALIZER_P (init
))
1141 && (SCALAR_TYPE_P (type
) || code
== REFERENCE_TYPE
))
1144 flags
|= LOOKUP_NO_NARROWING
;
1145 init
= convert_for_initialization (0, type
, init
, flags
,
1146 ICR_INIT
, NULL_TREE
, 0,
1152 /* Come here only for aggregates: records, arrays, unions, complex numbers
1154 gcc_assert (code
== ARRAY_TYPE
1155 || VECTOR_TYPE_P (type
)
1156 || code
== RECORD_TYPE
1157 || code
== UNION_TYPE
1158 || code
== COMPLEX_TYPE
);
1160 /* "If T is a class type and the initializer list has a single
1161 element of type cv U, where U is T or a class derived from T,
1162 the object is initialized from that element." */
1164 && cxx_dialect
>= cxx11
1165 && BRACE_ENCLOSED_INITIALIZER_P (init
)
1166 && CONSTRUCTOR_NELTS (init
) == 1
1167 && ((CLASS_TYPE_P (type
) && !CLASSTYPE_NON_AGGREGATE (type
))
1168 || VECTOR_TYPE_P (type
)))
1170 tree elt
= CONSTRUCTOR_ELT (init
, 0)->value
;
1171 if (reference_related_p (type
, TREE_TYPE (elt
)))
1172 /* We should have fixed this in reshape_init. */
1176 if (BRACE_ENCLOSED_INITIALIZER_P (init
)
1177 && !TYPE_NON_AGGREGATE_CLASS (type
))
1178 return process_init_constructor (type
, init
, nested
, complain
);
1181 if (COMPOUND_LITERAL_P (init
) && code
== ARRAY_TYPE
)
1183 if (complain
& tf_error
)
1184 error_at (loc
, "cannot initialize aggregate of type %qT with "
1185 "a compound literal", type
);
1187 return error_mark_node
;
1190 if (code
== ARRAY_TYPE
1191 && !BRACE_ENCLOSED_INITIALIZER_P (init
))
1193 /* Allow the result of build_array_copy and of
1194 build_value_init_noctor. */
1195 if ((TREE_CODE (init
) == VEC_INIT_EXPR
1196 || TREE_CODE (init
) == CONSTRUCTOR
)
1197 && (same_type_ignoring_top_level_qualifiers_p
1198 (type
, TREE_TYPE (init
))))
1201 if (complain
& tf_error
)
1202 error_at (loc
, "array must be initialized with a brace-enclosed"
1204 return error_mark_node
;
1207 return convert_for_initialization (NULL_TREE
, type
, init
,
1209 ICR_INIT
, NULL_TREE
, 0,
1215 digest_init (tree type
, tree init
, tsubst_flags_t complain
)
1217 return digest_init_r (type
, init
, 0, LOOKUP_IMPLICIT
, complain
);
1221 digest_init_flags (tree type
, tree init
, int flags
, tsubst_flags_t complain
)
1223 return digest_init_r (type
, init
, 0, flags
, complain
);
1226 /* Process the initializer INIT for an NSDMI DECL (a FIELD_DECL). */
1228 digest_nsdmi_init (tree decl
, tree init
, tsubst_flags_t complain
)
1230 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1232 tree type
= TREE_TYPE (decl
);
1233 int flags
= LOOKUP_IMPLICIT
;
1234 if (DIRECT_LIST_INIT_P (init
))
1235 flags
= LOOKUP_NORMAL
;
1236 if (BRACE_ENCLOSED_INITIALIZER_P (init
)
1237 && CP_AGGREGATE_TYPE_P (type
))
1238 init
= reshape_init (type
, init
, complain
);
1239 init
= digest_init_flags (type
, init
, flags
, complain
);
1240 if (TREE_CODE (init
) == TARGET_EXPR
)
1241 /* This represents the whole initialization. */
1242 TARGET_EXPR_DIRECT_INIT_P (init
) = true;
1246 /* Set of flags used within process_init_constructor to describe the
1248 #define PICFLAG_ERRONEOUS 1
1249 #define PICFLAG_NOT_ALL_CONSTANT 2
1250 #define PICFLAG_NOT_ALL_SIMPLE 4
1251 #define PICFLAG_SIDE_EFFECTS 8
1253 /* Given an initializer INIT, return the flag (PICFLAG_*) which better
1257 picflag_from_initializer (tree init
)
1259 if (init
== error_mark_node
)
1260 return PICFLAG_ERRONEOUS
;
1261 else if (!TREE_CONSTANT (init
))
1263 if (TREE_SIDE_EFFECTS (init
))
1264 return PICFLAG_SIDE_EFFECTS
;
1266 return PICFLAG_NOT_ALL_CONSTANT
;
1268 else if (!initializer_constant_valid_p (init
, TREE_TYPE (init
)))
1269 return PICFLAG_NOT_ALL_SIMPLE
;
1273 /* Adjust INIT for going into a CONSTRUCTOR. */
1276 massage_init_elt (tree type
, tree init
, int nested
, tsubst_flags_t complain
)
1278 init
= digest_init_r (type
, init
, nested
? 2 : 1, LOOKUP_IMPLICIT
, complain
);
1279 /* Strip a simple TARGET_EXPR when we know this is an initializer. */
1280 if (SIMPLE_TARGET_EXPR_P (init
))
1281 init
= TARGET_EXPR_INITIAL (init
);
1282 /* When we defer constant folding within a statement, we may want to
1283 defer this folding as well. */
1284 tree t
= fold_non_dependent_expr (init
, complain
);
1285 t
= maybe_constant_init (t
);
1286 if (TREE_CONSTANT (t
))
1291 /* Subroutine of process_init_constructor, which will process an initializer
1292 INIT for an array or vector of type TYPE. Returns the flags (PICFLAG_*)
1293 which describe the initializers. */
1296 process_init_constructor_array (tree type
, tree init
, int nested
,
1297 tsubst_flags_t complain
)
1299 unsigned HOST_WIDE_INT i
, len
= 0;
1301 bool unbounded
= false;
1302 constructor_elt
*ce
;
1303 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (init
);
1305 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
1306 || VECTOR_TYPE_P (type
));
1308 if (TREE_CODE (type
) == ARRAY_TYPE
)
1310 /* C++ flexible array members have a null domain. */
1311 tree domain
= TYPE_DOMAIN (type
);
1312 if (domain
&& TREE_CONSTANT (TYPE_MAX_VALUE (domain
)))
1313 len
= wi::ext (wi::to_offset (TYPE_MAX_VALUE (domain
))
1314 - wi::to_offset (TYPE_MIN_VALUE (domain
)) + 1,
1315 TYPE_PRECISION (TREE_TYPE (domain
)),
1316 TYPE_SIGN (TREE_TYPE (domain
))).to_uhwi ();
1318 unbounded
= true; /* Take as many as there are. */
1320 if (nested
== 2 && !domain
&& !vec_safe_is_empty (v
))
1322 if (complain
& tf_error
)
1323 error_at (cp_expr_loc_or_loc (init
, input_location
),
1324 "initialization of flexible array member "
1325 "in a nested context");
1326 return PICFLAG_ERRONEOUS
;
1330 /* Vectors are like simple fixed-size arrays. */
1331 unbounded
= !TYPE_VECTOR_SUBPARTS (type
).is_constant (&len
);
1333 /* There must not be more initializers than needed. */
1334 if (!unbounded
&& vec_safe_length (v
) > len
)
1336 if (complain
& tf_error
)
1337 error ("too many initializers for %qT", type
);
1339 return PICFLAG_ERRONEOUS
;
1342 FOR_EACH_VEC_SAFE_ELT (v
, i
, ce
)
1345 ce
->index
= size_int (i
);
1346 else if (!check_array_designated_initializer (ce
, i
))
1347 ce
->index
= error_mark_node
;
1348 gcc_assert (ce
->value
);
1350 = massage_init_elt (TREE_TYPE (type
), ce
->value
, nested
, complain
);
1353 (ce
->value
== error_mark_node
1354 || (same_type_ignoring_top_level_qualifiers_p
1355 (strip_array_types (TREE_TYPE (type
)),
1356 strip_array_types (TREE_TYPE (ce
->value
)))));
1358 flags
|= picflag_from_initializer (ce
->value
);
1361 /* No more initializers. If the array is unbounded, we are done. Otherwise,
1362 we must add initializers ourselves. */
1364 for (; i
< len
; ++i
)
1368 if (type_build_ctor_call (TREE_TYPE (type
)))
1370 /* If this type needs constructors run for default-initialization,
1371 we can't rely on the back end to do it for us, so make the
1372 initialization explicit by list-initializing from T{}. */
1373 next
= build_constructor (init_list_type_node
, NULL
);
1374 next
= massage_init_elt (TREE_TYPE (type
), next
, nested
, complain
);
1375 if (initializer_zerop (next
))
1376 /* The default zero-initialization is fine for us; don't
1377 add anything to the CONSTRUCTOR. */
1380 else if (!zero_init_p (TREE_TYPE (type
)))
1381 next
= build_zero_init (TREE_TYPE (type
),
1382 /*nelts=*/NULL_TREE
,
1383 /*static_storage_p=*/false);
1385 /* The default zero-initialization is fine for us; don't
1386 add anything to the CONSTRUCTOR. */
1391 flags
|= picflag_from_initializer (next
);
1393 && (initializer_constant_valid_p (next
, TREE_TYPE (next
))
1394 == null_pointer_node
))
1396 tree range
= build2 (RANGE_EXPR
, size_type_node
,
1397 build_int_cst (size_type_node
, i
),
1398 build_int_cst (size_type_node
, len
- 1));
1399 CONSTRUCTOR_APPEND_ELT (v
, range
, next
);
1403 CONSTRUCTOR_APPEND_ELT (v
, size_int (i
), next
);
1406 /* Don't bother checking all the other elements. */
1410 CONSTRUCTOR_ELTS (init
) = v
;
1414 /* Subroutine of process_init_constructor, which will process an initializer
1415 INIT for a class of type TYPE. Returns the flags (PICFLAG_*) which describe
1416 the initializers. */
1419 process_init_constructor_record (tree type
, tree init
, int nested
,
1420 tsubst_flags_t complain
)
1422 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1426 gcc_assert (TREE_CODE (type
) == RECORD_TYPE
);
1427 gcc_assert (!CLASSTYPE_VBASECLASSES (type
));
1428 gcc_assert (!TYPE_BINFO (type
)
1429 || cxx_dialect
>= cxx17
1430 || !BINFO_N_BASE_BINFOS (TYPE_BINFO (type
)));
1431 gcc_assert (!TYPE_POLYMORPHIC_P (type
));
1435 unsigned HOST_WIDE_INT idx
= 0;
1436 int designator_skip
= -1;
1437 /* Generally, we will always have an index for each initializer (which is
1438 a FIELD_DECL, put by reshape_init), but compound literals don't go trough
1439 reshape_init. So we need to handle both cases. */
1440 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
1445 if (TREE_CODE (field
) != FIELD_DECL
1446 || (DECL_ARTIFICIAL (field
)
1447 && !(cxx_dialect
>= cxx17
&& DECL_FIELD_IS_BASE (field
))))
1450 if (DECL_UNNAMED_BIT_FIELD (field
))
1453 /* If this is a bitfield, first convert to the declared type. */
1454 type
= TREE_TYPE (field
);
1455 if (DECL_BIT_FIELD_TYPE (field
))
1456 type
= DECL_BIT_FIELD_TYPE (field
);
1457 if (type
== error_mark_node
)
1458 return PICFLAG_ERRONEOUS
;
1461 if (idx
< CONSTRUCTOR_NELTS (init
))
1463 constructor_elt
*ce
= &(*CONSTRUCTOR_ELTS (init
))[idx
];
1466 /* We can have either a FIELD_DECL or an IDENTIFIER_NODE. The
1467 latter case can happen in templates where lookup has to be
1469 gcc_assert (TREE_CODE (ce
->index
) == FIELD_DECL
1470 || identifier_p (ce
->index
));
1471 if (ce
->index
== field
|| ce
->index
== DECL_NAME (field
))
1473 else if (ANON_AGGR_TYPE_P (type
)
1474 && search_anon_aggr (type
,
1475 TREE_CODE (ce
->index
) == FIELD_DECL
1476 ? DECL_NAME (ce
->index
)
1478 /* If the element is an anonymous union object and the
1479 initializer list is a designated-initializer-list, the
1480 anonymous union object is initialized by the
1481 designated-initializer-list { D }, where D is the
1482 designated-initializer-clause naming a member of the
1483 anonymous union object. */
1484 next
= build_constructor_single (init_list_type_node
,
1485 ce
->index
, ce
->value
);
1489 if (designator_skip
== -1)
1490 designator_skip
= 1;
1495 designator_skip
= 0;
1501 gcc_assert (ce
->value
);
1502 next
= massage_init_elt (type
, next
, nested
, complain
);
1507 /* Already handled above. */;
1508 else if (DECL_INITIAL (field
))
1512 /* We're using an NSDMI past a field with implicit
1513 zero-init. Go back and make it explicit. */
1515 vec_safe_truncate (v
, 0);
1518 /* C++14 aggregate NSDMI. */
1519 next
= get_nsdmi (field
, /*ctor*/false, complain
);
1520 if (!CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
)
1521 && find_placeholders (next
))
1522 CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
) = 1;
1524 else if (type_build_ctor_call (TREE_TYPE (field
)))
1526 /* If this type needs constructors run for
1527 default-initialization, we can't rely on the back end to do it
1528 for us, so build up TARGET_EXPRs. If the type in question is
1529 a class, just build one up; if it's an array, recurse. */
1530 next
= build_constructor (init_list_type_node
, NULL
);
1531 next
= massage_init_elt (TREE_TYPE (field
), next
, nested
, complain
);
1533 /* Warn when some struct elements are implicitly initialized. */
1534 if ((complain
& tf_warning
)
1535 && !EMPTY_CONSTRUCTOR_P (init
))
1536 warning (OPT_Wmissing_field_initializers
,
1537 "missing initializer for member %qD", field
);
1541 const_tree fldtype
= TREE_TYPE (field
);
1542 if (TYPE_REF_P (fldtype
))
1544 if (complain
& tf_error
)
1545 error ("member %qD is uninitialized reference", field
);
1547 return PICFLAG_ERRONEOUS
;
1549 else if (CLASSTYPE_REF_FIELDS_NEED_INIT (fldtype
))
1551 if (complain
& tf_error
)
1552 error ("member %qD with uninitialized reference fields", field
);
1554 return PICFLAG_ERRONEOUS
;
1557 /* Warn when some struct elements are implicitly initialized
1558 to zero. However, avoid issuing the warning for flexible
1559 array members since they need not have any elements. */
1560 if ((TREE_CODE (fldtype
) != ARRAY_TYPE
|| TYPE_DOMAIN (fldtype
))
1561 && (complain
& tf_warning
)
1562 && !EMPTY_CONSTRUCTOR_P (init
))
1563 warning (OPT_Wmissing_field_initializers
,
1564 "missing initializer for member %qD", field
);
1566 if (!zero_init_p (fldtype
)
1568 next
= build_zero_init (TREE_TYPE (field
), /*nelts=*/NULL_TREE
,
1569 /*static_storage_p=*/false);
1572 /* The default zero-initialization is fine for us; don't
1573 add anything to the CONSTRUCTOR. */
1579 /* If this is a bitfield, now convert to the lowered type. */
1580 if (type
!= TREE_TYPE (field
))
1581 next
= cp_convert_and_check (TREE_TYPE (field
), next
, complain
);
1582 flags
|= picflag_from_initializer (next
);
1583 CONSTRUCTOR_APPEND_ELT (v
, field
, next
);
1586 if (idx
< CONSTRUCTOR_NELTS (init
))
1588 if (complain
& tf_error
)
1590 constructor_elt
*ce
= &(*CONSTRUCTOR_ELTS (init
))[idx
];
1591 /* For better diagnostics, try to find out if it is really
1592 the case of too many initializers or if designators are
1593 in incorrect order. */
1594 if (designator_skip
== 1 && ce
->index
)
1596 gcc_assert (TREE_CODE (ce
->index
) == FIELD_DECL
1597 || identifier_p (ce
->index
));
1598 for (field
= TYPE_FIELDS (type
);
1599 field
; field
= DECL_CHAIN (field
))
1601 if (TREE_CODE (field
) != FIELD_DECL
1602 || (DECL_ARTIFICIAL (field
)
1603 && !(cxx_dialect
>= cxx17
1604 && DECL_FIELD_IS_BASE (field
))))
1607 if (DECL_UNNAMED_BIT_FIELD (field
))
1610 if (ce
->index
== field
|| ce
->index
== DECL_NAME (field
))
1612 if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
1615 = search_anon_aggr (TREE_TYPE (field
),
1616 TREE_CODE (ce
->index
) == FIELD_DECL
1617 ? DECL_NAME (ce
->index
)
1628 error ("designator order for field %qD does not match declaration "
1629 "order in %qT", field
, type
);
1631 error ("too many initializers for %qT", type
);
1634 return PICFLAG_ERRONEOUS
;
1637 CONSTRUCTOR_ELTS (init
) = v
;
1641 /* Subroutine of process_init_constructor, which will process a single
1642 initializer INIT for a union of type TYPE. Returns the flags (PICFLAG_*)
1643 which describe the initializer. */
1646 process_init_constructor_union (tree type
, tree init
, int nested
,
1647 tsubst_flags_t complain
)
1649 constructor_elt
*ce
;
1652 /* If the initializer was empty, use the union's NSDMI if it has one.
1653 Otherwise use default zero initialization. */
1654 if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init
)))
1656 for (tree field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
1658 if (TREE_CODE (field
) == FIELD_DECL
1659 && DECL_INITIAL (field
) != NULL_TREE
)
1661 tree val
= get_nsdmi (field
, /*in_ctor=*/false, complain
);
1662 if (!CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
)
1663 && find_placeholders (val
))
1664 CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init
) = 1;
1665 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (init
), field
, val
);
1670 if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init
)))
1674 len
= CONSTRUCTOR_ELTS (init
)->length ();
1677 if (!(complain
& tf_error
))
1678 return PICFLAG_ERRONEOUS
;
1679 error ("too many initializers for %qT", type
);
1680 CONSTRUCTOR_ELTS (init
)->block_remove (1, len
-1);
1683 ce
= &(*CONSTRUCTOR_ELTS (init
))[0];
1685 /* If this element specifies a field, initialize via that field. */
1688 if (TREE_CODE (ce
->index
) == FIELD_DECL
)
1690 else if (identifier_p (ce
->index
))
1692 /* This can happen within a cast, see g++.dg/opt/cse2.C. */
1693 tree name
= ce
->index
;
1695 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
1696 if (DECL_NAME (field
) == name
)
1700 if (complain
& tf_error
)
1701 error ("no field %qD found in union being initialized",
1703 ce
->value
= error_mark_node
;
1709 gcc_assert (TREE_CODE (ce
->index
) == INTEGER_CST
1710 || TREE_CODE (ce
->index
) == RANGE_EXPR
);
1711 if (complain
& tf_error
)
1712 error ("index value instead of field name in union initializer");
1713 ce
->value
= error_mark_node
;
1718 /* Find the first named field. ANSI decided in September 1990
1719 that only named fields count here. */
1720 tree field
= TYPE_FIELDS (type
);
1721 while (field
&& (!DECL_NAME (field
) || TREE_CODE (field
) != FIELD_DECL
))
1722 field
= TREE_CHAIN (field
);
1723 if (field
== NULL_TREE
)
1725 if (complain
& tf_error
)
1726 error ("too many initializers for %qT", type
);
1727 ce
->value
= error_mark_node
;
1732 if (ce
->value
&& ce
->value
!= error_mark_node
)
1733 ce
->value
= massage_init_elt (TREE_TYPE (ce
->index
), ce
->value
, nested
,
1736 return picflag_from_initializer (ce
->value
);
1739 /* Process INIT, a constructor for a variable of aggregate type TYPE. The
1740 constructor is a brace-enclosed initializer, and will be modified in-place.
1742 Each element is converted to the right type through digest_init, and
1743 missing initializers are added following the language rules (zero-padding,
1746 After the execution, the initializer will have TREE_CONSTANT if all elts are
1747 constant, and TREE_STATIC set if, in addition, all elts are simple enough
1748 constants that the assembler and linker can compute them.
1750 The function returns the initializer itself, or error_mark_node in case
1754 process_init_constructor (tree type
, tree init
, int nested
,
1755 tsubst_flags_t complain
)
1759 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init
));
1761 if (TREE_CODE (type
) == ARRAY_TYPE
|| VECTOR_TYPE_P (type
))
1762 flags
= process_init_constructor_array (type
, init
, nested
, complain
);
1763 else if (TREE_CODE (type
) == RECORD_TYPE
)
1764 flags
= process_init_constructor_record (type
, init
, nested
, complain
);
1765 else if (TREE_CODE (type
) == UNION_TYPE
)
1766 flags
= process_init_constructor_union (type
, init
, nested
, complain
);
1770 if (flags
& PICFLAG_ERRONEOUS
)
1771 return error_mark_node
;
1773 TREE_TYPE (init
) = type
;
1774 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
) == NULL_TREE
)
1775 cp_complete_array_type (&TREE_TYPE (init
), init
, /*do_default=*/0);
1776 if (flags
& PICFLAG_SIDE_EFFECTS
)
1778 TREE_CONSTANT (init
) = false;
1779 TREE_SIDE_EFFECTS (init
) = true;
1781 else if (flags
& PICFLAG_NOT_ALL_CONSTANT
)
1782 /* Make sure TREE_CONSTANT isn't set from build_constructor. */
1783 TREE_CONSTANT (init
) = false;
1786 TREE_CONSTANT (init
) = 1;
1787 if (!(flags
& PICFLAG_NOT_ALL_SIMPLE
))
1788 TREE_STATIC (init
) = 1;
1793 /* Given a structure or union value DATUM, construct and return
1794 the structure or union component which results from narrowing
1795 that value to the base specified in BASETYPE. For example, given the
1798 class L { int ii; };
1799 class A : L { ... };
1800 class B : L { ... };
1801 class C : A, B { ... };
1809 x.A::ii refers to the ii member of the L part of
1810 the A part of the C object named by X. In this case,
1811 DATUM would be x, and BASETYPE would be A.
1813 I used to think that this was nonconformant, that the standard specified
1814 that first we look up ii in A, then convert x to an L& and pull out the
1815 ii part. But in fact, it does say that we convert x to an A&; A here
1816 is known as the "naming class". (jason 2000-12-19)
1818 BINFO_P points to a variable initialized either to NULL_TREE or to the
1819 binfo for the specific base subobject we want to convert to. */
1822 build_scoped_ref (tree datum
, tree basetype
, tree
* binfo_p
)
1826 if (datum
== error_mark_node
)
1827 return error_mark_node
;
1831 binfo
= lookup_base (TREE_TYPE (datum
), basetype
, ba_check
,
1832 NULL
, tf_warning_or_error
);
1834 if (!binfo
|| binfo
== error_mark_node
)
1836 *binfo_p
= NULL_TREE
;
1838 error_not_base_type (basetype
, TREE_TYPE (datum
));
1839 return error_mark_node
;
1843 return build_base_path (PLUS_EXPR
, datum
, binfo
, 1,
1844 tf_warning_or_error
);
1847 /* Build a reference to an object specified by the C++ `->' operator.
1848 Usually this just involves dereferencing the object, but if the
1849 `->' operator is overloaded, then such overloads must be
1850 performed until an object which does not have the `->' operator
1851 overloaded is found. An error is reported when circular pointer
1852 delegation is detected. */
1855 build_x_arrow (location_t loc
, tree expr
, tsubst_flags_t complain
)
1857 tree orig_expr
= expr
;
1858 tree type
= TREE_TYPE (expr
);
1859 tree last_rval
= NULL_TREE
;
1860 vec
<tree
, va_gc
> *types_memoized
= NULL
;
1862 if (type
== error_mark_node
)
1863 return error_mark_node
;
1865 if (processing_template_decl
)
1867 if (type
&& TYPE_PTR_P (type
)
1868 && !dependent_scope_p (TREE_TYPE (type
)))
1869 /* Pointer to current instantiation, don't treat as dependent. */;
1870 else if (type_dependent_expression_p (expr
))
1871 return build_min_nt_loc (loc
, ARROW_EXPR
, expr
);
1872 expr
= build_non_dependent_expr (expr
);
1875 if (MAYBE_CLASS_TYPE_P (type
))
1877 struct tinst_level
*actual_inst
= current_instantiation ();
1880 while ((expr
= build_new_op (loc
, COMPONENT_REF
,
1881 LOOKUP_NORMAL
, expr
, NULL_TREE
, NULL_TREE
,
1884 if (expr
== error_mark_node
)
1885 return error_mark_node
;
1887 /* This provides a better instantiation backtrace in case of
1889 if (fn
&& DECL_USE_TEMPLATE (fn
))
1890 push_tinst_level_loc (fn
,
1891 (current_instantiation () != actual_inst
)
1892 ? DECL_SOURCE_LOCATION (fn
)
1896 if (vec_member (TREE_TYPE (expr
), types_memoized
))
1898 if (complain
& tf_error
)
1899 error ("circular pointer delegation detected");
1900 return error_mark_node
;
1903 vec_safe_push (types_memoized
, TREE_TYPE (expr
));
1907 while (current_instantiation () != actual_inst
)
1910 if (last_rval
== NULL_TREE
)
1912 if (complain
& tf_error
)
1913 error ("base operand of %<->%> has non-pointer type %qT", type
);
1914 return error_mark_node
;
1917 if (TYPE_REF_P (TREE_TYPE (last_rval
)))
1918 last_rval
= convert_from_reference (last_rval
);
1921 last_rval
= decay_conversion (expr
, complain
);
1923 if (TYPE_PTR_P (TREE_TYPE (last_rval
)))
1925 if (processing_template_decl
)
1927 expr
= build_min (ARROW_EXPR
, TREE_TYPE (TREE_TYPE (last_rval
)),
1929 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (last_rval
);
1933 return cp_build_indirect_ref (last_rval
, RO_ARROW
, complain
);
1936 if (complain
& tf_error
)
1939 error ("result of %<operator->()%> yields non-pointer result");
1941 error ("base operand of %<->%> is not a pointer");
1943 return error_mark_node
;
1946 /* Return an expression for "DATUM .* COMPONENT". DATUM has not
1947 already been checked out to be of aggregate type. */
1950 build_m_component_ref (tree datum
, tree component
, tsubst_flags_t complain
)
1958 if (error_operand_p (datum
) || error_operand_p (component
))
1959 return error_mark_node
;
1961 datum
= mark_lvalue_use (datum
);
1962 component
= mark_rvalue_use (component
);
1964 ptrmem_type
= TREE_TYPE (component
);
1965 if (!TYPE_PTRMEM_P (ptrmem_type
))
1967 if (complain
& tf_error
)
1968 error ("%qE cannot be used as a member pointer, since it is of "
1969 "type %qT", component
, ptrmem_type
);
1970 return error_mark_node
;
1973 objtype
= TYPE_MAIN_VARIANT (TREE_TYPE (datum
));
1974 if (! MAYBE_CLASS_TYPE_P (objtype
))
1976 if (complain
& tf_error
)
1977 error ("cannot apply member pointer %qE to %qE, which is of "
1978 "non-class type %qT", component
, datum
, objtype
);
1979 return error_mark_node
;
1982 type
= TYPE_PTRMEM_POINTED_TO_TYPE (ptrmem_type
);
1983 ctype
= complete_type (TYPE_PTRMEM_CLASS_TYPE (ptrmem_type
));
1985 if (!COMPLETE_TYPE_P (ctype
))
1987 if (!same_type_p (ctype
, objtype
))
1993 binfo
= lookup_base (objtype
, ctype
, ba_check
, NULL
, complain
);
1998 if (complain
& tf_error
)
1999 error ("pointer to member type %qT incompatible with object "
2000 "type %qT", type
, objtype
);
2001 return error_mark_node
;
2003 else if (binfo
== error_mark_node
)
2004 return error_mark_node
;
2007 if (TYPE_PTRDATAMEM_P (ptrmem_type
))
2009 bool is_lval
= real_lvalue_p (datum
);
2012 /* Compute the type of the field, as described in [expr.ref].
2013 There's no such thing as a mutable pointer-to-member, so
2014 things are not as complex as they are for references to
2015 non-static data members. */
2016 type
= cp_build_qualified_type (type
,
2017 (cp_type_quals (type
)
2018 | cp_type_quals (TREE_TYPE (datum
))));
2020 datum
= build_address (datum
);
2022 /* Convert object to the correct base. */
2025 datum
= build_base_path (PLUS_EXPR
, datum
, binfo
, 1, complain
);
2026 if (datum
== error_mark_node
)
2027 return error_mark_node
;
2030 /* Build an expression for "object + offset" where offset is the
2031 value stored in the pointer-to-data-member. */
2032 ptype
= build_pointer_type (type
);
2033 datum
= fold_build_pointer_plus (fold_convert (ptype
, datum
), component
);
2034 datum
= cp_build_fold_indirect_ref (datum
);
2035 if (datum
== error_mark_node
)
2036 return error_mark_node
;
2038 /* If the object expression was an rvalue, return an rvalue. */
2040 datum
= move (datum
);
2045 /* 5.5/6: In a .* expression whose object expression is an rvalue, the
2046 program is ill-formed if the second operand is a pointer to member
2047 function with ref-qualifier & (for C++2A: unless its cv-qualifier-seq
2048 is const). In a .* expression whose object expression is an lvalue,
2049 the program is ill-formed if the second operand is a pointer to member
2050 function with ref-qualifier &&. */
2051 if (FUNCTION_REF_QUALIFIED (type
))
2053 bool lval
= lvalue_p (datum
);
2054 if (lval
&& FUNCTION_RVALUE_QUALIFIED (type
))
2056 if (complain
& tf_error
)
2057 error ("pointer-to-member-function type %qT requires an rvalue",
2059 return error_mark_node
;
2061 else if (!lval
&& !FUNCTION_RVALUE_QUALIFIED (type
))
2063 if ((type_memfn_quals (type
)
2064 & (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
))
2067 if (complain
& tf_error
)
2068 error ("pointer-to-member-function type %qT requires "
2069 "an lvalue", ptrmem_type
);
2070 return error_mark_node
;
2072 else if (cxx_dialect
< cxx2a
)
2074 if (complain
& tf_warning_or_error
)
2075 pedwarn (input_location
, OPT_Wpedantic
,
2076 "pointer-to-member-function type %qT requires "
2077 "an lvalue before C++2a", ptrmem_type
);
2079 return error_mark_node
;
2083 return build2 (OFFSET_REF
, type
, datum
, component
);
2087 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
2090 build_functional_cast (tree exp
, tree parms
, tsubst_flags_t complain
)
2092 /* This is either a call to a constructor,
2093 or a C cast in C++'s `functional' notation. */
2095 /* The type to which we are casting. */
2097 vec
<tree
, va_gc
> *parmvec
;
2099 if (error_operand_p (exp
) || parms
== error_mark_node
)
2100 return error_mark_node
;
2102 if (TREE_CODE (exp
) == TYPE_DECL
)
2104 type
= TREE_TYPE (exp
);
2106 if (DECL_ARTIFICIAL (exp
))
2107 cp_warn_deprecated_use (type
);
2112 /* We need to check this explicitly, since value-initialization of
2113 arrays is allowed in other situations. */
2114 if (TREE_CODE (type
) == ARRAY_TYPE
)
2116 if (complain
& tf_error
)
2117 error ("functional cast to array type %qT", type
);
2118 return error_mark_node
;
2121 if (tree anode
= type_uses_auto (type
))
2123 if (!CLASS_PLACEHOLDER_TEMPLATE (anode
))
2125 if (complain
& tf_error
)
2126 error_at (DECL_SOURCE_LOCATION (TEMPLATE_TYPE_DECL (anode
)),
2127 "invalid use of %qT", anode
);
2128 return error_mark_node
;
2132 if (complain
& tf_error
)
2133 error ("cannot deduce template arguments for %qT from ()", anode
);
2134 return error_mark_node
;
2137 type
= do_auto_deduction (type
, parms
, anode
, complain
,
2141 if (processing_template_decl
)
2145 /* Diagnose this even in a template. We could also try harder
2146 to give all the usual errors when the type and args are
2148 if (TYPE_REF_P (type
) && !parms
)
2150 if (complain
& tf_error
)
2151 error ("invalid value-initialization of reference type");
2152 return error_mark_node
;
2155 t
= build_min (CAST_EXPR
, type
, parms
);
2156 /* We don't know if it will or will not have side effects. */
2157 TREE_SIDE_EFFECTS (t
) = 1;
2161 if (! MAYBE_CLASS_TYPE_P (type
))
2163 if (parms
== NULL_TREE
)
2165 if (VOID_TYPE_P (type
))
2167 return build_value_init (cv_unqualified (type
), complain
);
2170 /* This must build a C cast. */
2171 parms
= build_x_compound_expr_from_list (parms
, ELK_FUNC_CAST
, complain
);
2172 return cp_build_c_cast (type
, parms
, complain
);
2175 /* Prepare to evaluate as a call to a constructor. If this expression
2176 is actually used, for example,
2178 return X (arg1, arg2, ...);
2180 then the slot being initialized will be filled in. */
2182 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
2183 return error_mark_node
;
2184 if (abstract_virtuals_error_sfinae (ACU_CAST
, type
, complain
))
2185 return error_mark_node
;
2189 If the expression list is a single-expression, the type
2190 conversion is equivalent (in definedness, and if defined in
2191 meaning) to the corresponding cast expression. */
2192 if (parms
&& TREE_CHAIN (parms
) == NULL_TREE
)
2193 return cp_build_c_cast (type
, TREE_VALUE (parms
), complain
);
2197 The expression T(), where T is a simple-type-specifier for a
2198 non-array complete object type or the (possibly cv-qualified)
2199 void type, creates an rvalue of the specified type, which is
2200 value-initialized. */
2202 if (parms
== NULL_TREE
)
2204 exp
= build_value_init (type
, complain
);
2205 exp
= get_target_expr_sfinae (exp
, complain
);
2209 /* Call the constructor. */
2210 parmvec
= make_tree_vector ();
2211 for (; parms
!= NULL_TREE
; parms
= TREE_CHAIN (parms
))
2212 vec_safe_push (parmvec
, TREE_VALUE (parms
));
2213 exp
= build_special_member_call (NULL_TREE
, complete_ctor_identifier
,
2214 &parmvec
, type
, LOOKUP_NORMAL
, complain
);
2215 release_tree_vector (parmvec
);
2217 if (exp
== error_mark_node
)
2218 return error_mark_node
;
2220 return build_cplus_new (type
, exp
, complain
);
2224 /* Add new exception specifier SPEC, to the LIST we currently have.
2225 If it's already in LIST then do nothing.
2226 Moan if it's bad and we're allowed to. COMPLAIN < 0 means we
2227 know what we're doing. */
2230 add_exception_specifier (tree list
, tree spec
, tsubst_flags_t complain
)
2235 diagnostic_t diag_type
= DK_UNSPECIFIED
; /* none */
2237 if (spec
== error_mark_node
)
2240 gcc_assert (spec
&& (!list
|| TREE_VALUE (list
)));
2242 /* [except.spec] 1, type in an exception specifier shall not be
2243 incomplete, or pointer or ref to incomplete other than pointer
2245 is_ptr
= TYPE_PTR_P (core
);
2246 if (is_ptr
|| TYPE_REF_P (core
))
2247 core
= TREE_TYPE (core
);
2250 else if (VOID_TYPE_P (core
))
2252 else if (TREE_CODE (core
) == TEMPLATE_TYPE_PARM
)
2254 else if (processing_template_decl
)
2259 /* 15.4/1 says that types in an exception specifier must be complete,
2260 but it seems more reasonable to only require this on definitions
2261 and calls. So just give a pedwarn at this point; we will give an
2262 error later if we hit one of those two cases. */
2263 if (!COMPLETE_TYPE_P (complete_type (core
)))
2264 diag_type
= DK_PEDWARN
; /* pedwarn */
2271 for (probe
= list
; probe
; probe
= TREE_CHAIN (probe
))
2272 if (same_type_p (TREE_VALUE (probe
), spec
))
2275 list
= tree_cons (NULL_TREE
, spec
, list
);
2278 diag_type
= DK_ERROR
; /* error */
2280 if (diag_type
!= DK_UNSPECIFIED
2281 && (complain
& tf_warning_or_error
))
2282 cxx_incomplete_type_diagnostic (NULL_TREE
, core
, diag_type
);
2287 /* Like nothrow_spec_p, but don't abort on deferred noexcept. */
2290 nothrow_spec_p_uninst (const_tree spec
)
2292 if (DEFERRED_NOEXCEPT_SPEC_P (spec
))
2294 return nothrow_spec_p (spec
);
2297 /* Combine the two exceptions specifier lists LIST and ADD, and return
2301 merge_exception_specifiers (tree list
, tree add
)
2303 tree noex
, orig_list
;
2305 /* No exception-specifier or noexcept(false) are less strict than
2306 anything else. Prefer the newer variant (LIST). */
2307 if (!list
|| list
== noexcept_false_spec
)
2309 else if (!add
|| add
== noexcept_false_spec
)
2312 /* noexcept(true) and throw() are stricter than anything else.
2313 As above, prefer the more recent one (LIST). */
2314 if (nothrow_spec_p_uninst (add
))
2317 /* Two implicit noexcept specs (e.g. on a destructor) are equivalent. */
2318 if (UNEVALUATED_NOEXCEPT_SPEC_P (add
)
2319 && UNEVALUATED_NOEXCEPT_SPEC_P (list
))
2321 /* We should have instantiated other deferred noexcept specs by now. */
2322 gcc_assert (!DEFERRED_NOEXCEPT_SPEC_P (add
));
2324 if (nothrow_spec_p_uninst (list
))
2326 noex
= TREE_PURPOSE (list
);
2327 gcc_checking_assert (!TREE_PURPOSE (add
)
2328 || errorcount
|| !flag_exceptions
2329 || cp_tree_equal (noex
, TREE_PURPOSE (add
)));
2331 /* Combine the dynamic-exception-specifiers, if any. */
2333 for (; add
&& TREE_VALUE (add
); add
= TREE_CHAIN (add
))
2335 tree spec
= TREE_VALUE (add
);
2338 for (probe
= orig_list
; probe
&& TREE_VALUE (probe
);
2339 probe
= TREE_CHAIN (probe
))
2340 if (same_type_p (TREE_VALUE (probe
), spec
))
2344 spec
= build_tree_list (NULL_TREE
, spec
);
2345 TREE_CHAIN (spec
) = list
;
2350 /* Keep the noexcept-specifier at the beginning of the list. */
2351 if (noex
!= TREE_PURPOSE (list
))
2352 list
= tree_cons (noex
, TREE_VALUE (list
), TREE_CHAIN (list
));
2357 /* Subroutine of build_call. Ensure that each of the types in the
2358 exception specification is complete. Technically, 15.4/1 says that
2359 they need to be complete when we see a declaration of the function,
2360 but we should be able to get away with only requiring this when the
2361 function is defined or called. See also add_exception_specifier. */
2364 require_complete_eh_spec_types (tree fntype
, tree decl
)
2367 /* Don't complain about calls to op new. */
2368 if (decl
&& DECL_ARTIFICIAL (decl
))
2370 for (raises
= TYPE_RAISES_EXCEPTIONS (fntype
); raises
;
2371 raises
= TREE_CHAIN (raises
))
2373 tree type
= TREE_VALUE (raises
);
2374 if (type
&& !COMPLETE_TYPE_P (type
))
2378 ("call to function %qD which throws incomplete type %q#T",
2381 error ("call to function which throws incomplete type %q#T",
2388 #include "gt-cp-typeck2.h"