1 /* Report error messages, build initializers, and perform
2 some front-end optimizations for C++ compiler.
3 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
6 Hacked by Michael Tiemann (tiemann@cygnus.com)
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
25 /* This file is part of the C++ front end.
26 It contains routines to build C++ expressions given their operands,
27 including computing the types of the result, C and C++ specific error
28 checks, and some optimization. */
32 #include "coretypes.h"
39 #include "diagnostic-core.h"
42 process_init_constructor (tree type, tree init);
45 /* Print an error message stemming from an attempt to use
46 BASETYPE as a base class for TYPE. */
49 error_not_base_type (tree basetype, tree type)
51 if (TREE_CODE (basetype) == FUNCTION_DECL)
52 basetype = DECL_CONTEXT (basetype);
53 error ("type %qT is not a base type for type %qT", basetype, type);
54 return error_mark_node;
58 binfo_or_else (tree base, tree type)
60 tree binfo = lookup_base (type, base, ba_unique, NULL);
62 if (binfo == error_mark_node)
65 error_not_base_type (base, type);
69 /* According to ARM $7.1.6, "A `const' object may be initialized, but its
70 value may not be changed thereafter. */
73 cxx_readonly_error (tree arg, enum lvalue_use errstring)
76 /* This macro is used to emit diagnostics to ensure that all format
77 strings are complete sentences, visible to gettext and checked at
80 #define ERROR_FOR_ASSIGNMENT(AS, ASM, IN, DE, ARG) \
101 /* Handle C++-specific things first. */
103 if (TREE_CODE (arg) == VAR_DECL
104 && DECL_LANG_SPECIFIC (arg)
105 && DECL_IN_AGGR_P (arg)
106 && !TREE_STATIC (arg))
107 ERROR_FOR_ASSIGNMENT (G_("assignment of "
108 "constant field %qD"),
109 G_("constant field %qD "
110 "used as %<asm%> output"),
112 "constant field %qD"),
114 "constant field %qD"),
116 else if (TREE_CODE (arg) == INDIRECT_REF
117 && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE
118 && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL
119 || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL))
120 ERROR_FOR_ASSIGNMENT (G_("assignment of "
121 "read-only reference %qD"),
122 G_("read-only reference %qD "
123 "used as %<asm%> output"),
125 "read-only reference %qD"),
127 "read-only reference %qD"),
128 TREE_OPERAND (arg, 0));
130 readonly_error (arg, errstring);
134 /* Structure that holds information about declarations whose type was
135 incomplete and we could not check whether it was abstract or not. */
137 struct GTY((chain_next ("%h.next"))) pending_abstract_type {
138 /* Declaration which we are checking for abstractness. It is either
139 a DECL node, or an IDENTIFIER_NODE if we do not have a full
140 declaration available. */
143 /* Type which will be checked for abstractness. */
146 /* Position of the declaration. This is only needed for IDENTIFIER_NODEs,
147 because DECLs already carry locus information. */
150 /* Link to the next element in list. */
151 struct pending_abstract_type* next;
155 /* Compute the hash value of the node VAL. This function is used by the
156 hash table abstract_pending_vars. */
159 pat_calc_hash (const void* val)
161 const struct pending_abstract_type *pat =
162 (const struct pending_abstract_type *) val;
163 return (hashval_t) TYPE_UID (pat->type);
167 /* Compare node VAL1 with the type VAL2. This function is used by the
168 hash table abstract_pending_vars. */
171 pat_compare (const void* val1, const void* val2)
173 const struct pending_abstract_type *const pat1 =
174 (const struct pending_abstract_type *) val1;
175 const_tree const type2 = (const_tree)val2;
177 return (pat1->type == type2);
180 /* Hash table that maintains pending_abstract_type nodes, for which we still
181 need to check for type abstractness. The key of the table is the type
182 of the declaration. */
183 static GTY ((param_is (struct pending_abstract_type)))
184 htab_t abstract_pending_vars = NULL;
187 /* This function is called after TYPE is completed, and will check if there
188 are pending declarations for which we still need to verify the abstractness
189 of TYPE, and emit a diagnostic (through abstract_virtuals_error) if TYPE
190 turned out to be incomplete. */
193 complete_type_check_abstract (tree type)
196 struct pending_abstract_type *pat;
197 location_t cur_loc = input_location;
199 gcc_assert (COMPLETE_TYPE_P (type));
201 if (!abstract_pending_vars)
204 /* Retrieve the list of pending declarations for this type. */
205 slot = htab_find_slot_with_hash (abstract_pending_vars, type,
206 (hashval_t)TYPE_UID (type), NO_INSERT);
209 pat = (struct pending_abstract_type*)*slot;
212 /* If the type is not abstract, do not do anything. */
213 if (CLASSTYPE_PURE_VIRTUALS (type))
215 struct pending_abstract_type *prev = 0, *next;
217 /* Reverse the list to emit the errors in top-down order. */
218 for (; pat; pat = next)
226 /* Go through the list, and call abstract_virtuals_error for each
227 element: it will issue a diagnostic if the type is abstract. */
230 gcc_assert (type == pat->type);
232 /* Tweak input_location so that the diagnostic appears at the correct
233 location. Notice that this is only needed if the decl is an
235 input_location = pat->locus;
236 abstract_virtuals_error (pat->decl, pat->type);
241 htab_clear_slot (abstract_pending_vars, slot);
243 input_location = cur_loc;
247 /* If TYPE has abstract virtual functions, issue an error about trying
248 to create an object of that type. DECL is the object declared, or
249 NULL_TREE if the declaration is unavailable. Returns 1 if an error
250 occurred; zero if all was well. */
253 abstract_virtuals_error (tree decl, tree type)
257 /* This function applies only to classes. Any other entity can never
259 if (!CLASS_TYPE_P (type))
261 type = TYPE_MAIN_VARIANT (type);
263 /* If the type is incomplete, we register it within a hash table,
264 so that we can check again once it is completed. This makes sense
265 only for objects for which we have a declaration or at least a
267 if (!COMPLETE_TYPE_P (type))
270 struct pending_abstract_type *pat;
272 gcc_assert (!decl || DECL_P (decl)
273 || TREE_CODE (decl) == IDENTIFIER_NODE);
275 if (!abstract_pending_vars)
276 abstract_pending_vars = htab_create_ggc (31, &pat_calc_hash,
279 slot = htab_find_slot_with_hash (abstract_pending_vars, type,
280 (hashval_t)TYPE_UID (type), INSERT);
282 pat = ggc_alloc_pending_abstract_type ();
285 pat->locus = ((decl && DECL_P (decl))
286 ? DECL_SOURCE_LOCATION (decl)
289 pat->next = (struct pending_abstract_type *) *slot;
295 if (!TYPE_SIZE (type))
296 /* TYPE is being defined, and during that time
297 CLASSTYPE_PURE_VIRTUALS holds the inline friends. */
300 pure = CLASSTYPE_PURE_VIRTUALS (type);
306 if (TREE_CODE (decl) == RESULT_DECL)
309 if (TREE_CODE (decl) == VAR_DECL)
310 error ("cannot declare variable %q+D to be of abstract "
311 "type %qT", decl, type);
312 else if (TREE_CODE (decl) == PARM_DECL)
313 error ("cannot declare parameter %q+D to be of abstract type %qT",
315 else if (TREE_CODE (decl) == FIELD_DECL)
316 error ("cannot declare field %q+D to be of abstract type %qT",
318 else if (TREE_CODE (decl) == FUNCTION_DECL
319 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
320 error ("invalid abstract return type for member function %q+#D", decl);
321 else if (TREE_CODE (decl) == FUNCTION_DECL)
322 error ("invalid abstract return type for function %q+#D", decl);
323 else if (TREE_CODE (decl) == IDENTIFIER_NODE)
324 /* Here we do not have location information. */
325 error ("invalid abstract type %qT for %qE", type, decl);
327 error ("invalid abstract type for %q+D", decl);
330 error ("cannot allocate an object of abstract type %qT", type);
332 /* Only go through this once. */
333 if (VEC_length (tree, pure))
338 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
339 " because the following virtual functions are pure within %qT:",
342 FOR_EACH_VEC_ELT (tree, pure, ix, fn)
343 inform (input_location, "\t%+#D", fn);
344 /* Now truncate the vector. This leaves it non-null, so we know
345 there are pure virtuals, but empty so we don't list them out
347 VEC_truncate (tree, pure, 0);
350 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
351 " since type %qT has pure virtual functions",
357 /* Print an error message for invalid use of an incomplete type.
358 VALUE is the expression that was used (or 0 if that isn't known)
359 and TYPE is the type that was invalid. DIAG_KIND indicates the
360 type of diagnostic (see diagnostic.def). */
363 cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
364 diagnostic_t diag_kind)
368 gcc_assert (diag_kind == DK_WARNING
369 || diag_kind == DK_PEDWARN
370 || diag_kind == DK_ERROR);
372 /* Avoid duplicate error message. */
373 if (TREE_CODE (type) == ERROR_MARK)
376 if (value != 0 && (TREE_CODE (value) == VAR_DECL
377 || TREE_CODE (value) == PARM_DECL
378 || TREE_CODE (value) == FIELD_DECL))
380 emit_diagnostic (diag_kind, input_location, 0,
381 "%q+D has incomplete type", value);
385 /* We must print an error message. Be clever about what it says. */
387 switch (TREE_CODE (type))
393 emit_diagnostic (diag_kind, input_location, 0,
394 "invalid use of incomplete type %q#T", type);
395 if (!TYPE_TEMPLATE_INFO (type))
396 emit_diagnostic (diag_kind, input_location, 0,
397 "forward declaration of %q+#T", type);
399 emit_diagnostic (diag_kind, input_location, 0,
400 "declaration of %q+#T", type);
404 emit_diagnostic (diag_kind, input_location, 0,
405 "invalid use of %qT", type);
409 if (TYPE_DOMAIN (type))
411 type = TREE_TYPE (type);
414 emit_diagnostic (diag_kind, input_location, 0,
415 "invalid use of array with unspecified bounds");
420 emit_diagnostic (diag_kind, input_location, 0,
421 "invalid use of member (did you forget the %<&%> ?)");
424 case TEMPLATE_TYPE_PARM:
426 emit_diagnostic (diag_kind, input_location, 0,
427 "invalid use of %<auto%>");
429 emit_diagnostic (diag_kind, input_location, 0,
430 "invalid use of template type parameter %qT", type);
433 case BOUND_TEMPLATE_TEMPLATE_PARM:
434 emit_diagnostic (diag_kind, input_location, 0,
435 "invalid use of template template parameter %qT",
440 emit_diagnostic (diag_kind, input_location, 0,
441 "invalid use of dependent type %qT", type);
445 gcc_assert (type == unknown_type_node);
446 if (value && TREE_CODE (value) == COMPONENT_REF)
448 else if (value && TREE_CODE (value) == ADDR_EXPR)
449 emit_diagnostic (diag_kind, input_location, 0,
450 "address of overloaded function with no contextual "
452 else if (value && TREE_CODE (value) == OVERLOAD)
453 emit_diagnostic (diag_kind, input_location, 0,
454 "overloaded function with no contextual type information");
456 emit_diagnostic (diag_kind, input_location, 0,
457 "insufficient contextual information to determine type");
465 /* Backward-compatibility interface to incomplete_type_diagnostic;
466 required by ../tree.c. */
467 #undef cxx_incomplete_type_error
469 cxx_incomplete_type_error (const_tree value, const_tree type)
471 cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
475 /* The recursive part of split_nonconstant_init. DEST is an lvalue
476 expression to which INIT should be assigned. INIT is a CONSTRUCTOR. */
479 split_nonconstant_init_1 (tree dest, tree *initp)
481 unsigned HOST_WIDE_INT idx;
483 tree field_index, value;
484 tree type = TREE_TYPE (dest);
485 tree inner_type = NULL;
486 bool array_type_p = false;
487 HOST_WIDE_INT num_type_elements, num_initialized_elements;
489 switch (TREE_CODE (type))
492 inner_type = TREE_TYPE (type);
498 case QUAL_UNION_TYPE:
499 num_initialized_elements = 0;
500 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), idx,
503 /* The current implementation of this algorithm assumes that
504 the field was set for all the elements. This is usually done
505 by process_init_constructor. */
506 gcc_assert (field_index);
509 inner_type = TREE_TYPE (field_index);
511 if (TREE_CODE (value) == CONSTRUCTOR)
516 sub = build4 (ARRAY_REF, inner_type, dest, field_index,
517 NULL_TREE, NULL_TREE);
519 sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
522 split_nonconstant_init_1 (sub, &value);
524 else if (!initializer_constant_valid_p (value, inner_type))
528 HOST_WIDE_INT inner_elements;
530 /* FIXME: Ordered removal is O(1) so the whole function is
531 worst-case quadratic. This could be fixed using an aside
532 bitmap to record which elements must be removed and remove
533 them all at the same time. Or by merging
534 split_non_constant_init into process_init_constructor_array,
535 that is separating constants from non-constants while building
537 VEC_ordered_remove (constructor_elt, CONSTRUCTOR_ELTS (init),
542 sub = build4 (ARRAY_REF, inner_type, dest, field_index,
543 NULL_TREE, NULL_TREE);
545 sub = build3 (COMPONENT_REF, inner_type, dest, field_index,
548 code = build2 (INIT_EXPR, inner_type, sub, value);
549 code = build_stmt (input_location, EXPR_STMT, code);
552 inner_elements = count_type_elements (inner_type, true);
553 if (inner_elements < 0)
554 num_initialized_elements = -1;
555 else if (num_initialized_elements >= 0)
556 num_initialized_elements += inner_elements;
561 num_type_elements = count_type_elements (type, true);
562 /* If all elements of the initializer are non-constant and
563 have been split out, we don't need the empty CONSTRUCTOR. */
564 if (num_type_elements > 0
565 && num_type_elements == num_initialized_elements)
570 if (!initializer_constant_valid_p (init, type))
573 tree cons = copy_node (init);
574 CONSTRUCTOR_ELTS (init) = NULL;
575 code = build2 (MODIFY_EXPR, type, dest, cons);
576 code = build_stmt (input_location, EXPR_STMT, code);
585 /* The rest of the initializer is now a constant. */
586 TREE_CONSTANT (init) = 1;
589 /* A subroutine of store_init_value. Splits non-constant static
590 initializer INIT into a constant part and generates code to
591 perform the non-constant part of the initialization to DEST.
592 Returns the code for the runtime init. */
595 split_nonconstant_init (tree dest, tree init)
599 if (TREE_CODE (init) == CONSTRUCTOR)
601 code = push_stmt_list ();
602 split_nonconstant_init_1 (dest, &init);
603 code = pop_stmt_list (code);
604 DECL_INITIAL (dest) = init;
605 TREE_READONLY (dest) = 0;
608 code = build2 (INIT_EXPR, TREE_TYPE (dest), dest, init);
613 /* Perform appropriate conversions on the initial value of a variable,
614 store it in the declaration DECL,
615 and print any error messages that are appropriate.
616 If the init is invalid, store an ERROR_MARK.
618 C++: Note that INIT might be a TREE_LIST, which would mean that it is
619 a base class initializer for some aggregate type, hopefully compatible
620 with DECL. If INIT is a single element, and DECL is an aggregate
621 type, we silently convert INIT into a TREE_LIST, allowing a constructor
624 If INIT is a TREE_LIST and there is no constructor, turn INIT
625 into a CONSTRUCTOR and use standard initialization techniques.
626 Perhaps a warning should be generated?
628 Returns code to be executed if initialization could not be performed
629 for static variable. In that case, caller must emit the code. */
632 store_init_value (tree decl, tree init, int flags)
636 /* If variable's type was invalidly declared, just ignore it. */
638 type = TREE_TYPE (decl);
639 if (TREE_CODE (type) == ERROR_MARK)
642 if (MAYBE_CLASS_TYPE_P (type))
644 if (TREE_CODE (init) == TREE_LIST)
646 error ("constructor syntax used, but no constructor declared "
647 "for type %qT", type);
648 init = build_constructor_from_list (init_list_type_node, nreverse (init));
651 else if (TREE_CODE (init) == TREE_LIST
652 && TREE_TYPE (init) != unknown_type_node)
654 gcc_assert (TREE_CODE (decl) != RESULT_DECL);
656 if (TREE_CODE (init) == TREE_LIST
657 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
659 error ("cannot initialize arrays using this syntax");
663 /* We get here with code like `int a (2);' */
664 init = build_x_compound_expr_from_list (init, ELK_INIT,
665 tf_warning_or_error);
668 /* End of special C++ code. */
670 if (flags & LOOKUP_ALREADY_DIGESTED)
673 /* Digest the specified initializer into an expression. */
674 value = digest_init_flags (type, init, flags);
676 /* In C++0x constant expression is a semantic, not syntactic, property.
677 In C++98, make sure that what we thought was a constant expression at
678 template definition time is still constant. */
679 if ((cxx_dialect >= cxx0x
680 || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
681 && (decl_maybe_constant_var_p (decl)
682 || TREE_STATIC (decl)))
685 value = fold_non_dependent_expr (value);
686 value = maybe_constant_init (value);
687 if (DECL_DECLARED_CONSTEXPR_P (decl))
688 /* Diagnose a non-constant initializer for constexpr. */
689 value = cxx_constant_value (value);
690 const_init = (reduced_constant_expression_p (value)
691 || error_operand_p (value));
692 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init;
693 TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl);
696 /* If the initializer is not a constant, fill in DECL_INITIAL with
697 the bits that are constant, and then return an expression that
698 will perform the dynamic initialization. */
699 if (value != error_mark_node
700 && (TREE_SIDE_EFFECTS (value)
701 || ! initializer_constant_valid_p (value, TREE_TYPE (value))))
702 return split_nonconstant_init (decl, value);
703 /* If the value is a constant, just put it in DECL_INITIAL. If DECL
704 is an automatic variable, the middle end will turn this into a
705 dynamic initialization later. */
706 DECL_INITIAL (decl) = value;
711 /* Give errors about narrowing conversions within { }. */
714 check_narrowing (tree type, tree init)
716 tree ftype = unlowered_expr_type (init);
720 if (!ARITHMETIC_TYPE_P (type))
723 init = maybe_constant_value (init);
725 if (TREE_CODE (type) == INTEGER_TYPE
726 && TREE_CODE (ftype) == REAL_TYPE)
728 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
729 && CP_INTEGRAL_TYPE_P (type))
731 if (TYPE_PRECISION (type) < TYPE_PRECISION (ftype)
732 && (TREE_CODE (init) != INTEGER_CST
733 || !int_fits_type_p (init, type)))
736 else if (TREE_CODE (ftype) == REAL_TYPE
737 && TREE_CODE (type) == REAL_TYPE)
739 if (TYPE_PRECISION (type) < TYPE_PRECISION (ftype))
741 if (TREE_CODE (init) == REAL_CST)
743 /* Issue 703: Loss of precision is OK as long as the value is
744 within the representable range of the new type. */
746 d = TREE_REAL_CST (init);
747 real_convert (&r, TYPE_MODE (type), &d);
755 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
756 && TREE_CODE (type) == REAL_TYPE)
759 if (TREE_CODE (init) == INTEGER_CST)
761 d = real_value_from_int_cst (0, init);
762 if (exact_real_truncate (TYPE_MODE (type), &d))
768 permerror (input_location, "narrowing conversion of %qE from %qT to %qT inside { }",
772 /* Process the initializer INIT for a variable of type TYPE, emitting
773 diagnostics for invalid initializers and converting the initializer as
776 For aggregate types, it assumes that reshape_init has already run, thus the
777 initializer will have the right shape (brace elision has been undone).
779 NESTED is true iff we are being called for an element of a CONSTRUCTOR. */
782 digest_init_r (tree type, tree init, bool nested, int flags)
784 enum tree_code code = TREE_CODE (type);
786 if (error_operand_p (init))
787 return error_mark_node;
791 /* We must strip the outermost array type when completing the type,
792 because the its bounds might be incomplete at the moment. */
793 if (!complete_type_or_else (TREE_CODE (type) == ARRAY_TYPE
794 ? TREE_TYPE (type) : type, NULL_TREE))
795 return error_mark_node;
797 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue
798 (g++.old-deja/g++.law/casts2.C). */
799 if (TREE_CODE (init) == NON_LVALUE_EXPR)
800 init = TREE_OPERAND (init, 0);
802 /* Initialization of an array of chars from a string constant. The initializer
803 can be optionally enclosed in braces, but reshape_init has already removed
804 them if they were present. */
805 if (code == ARRAY_TYPE)
807 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
808 if (char_type_p (typ1)
810 && TREE_CODE (init) == STRING_CST)
812 tree char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
814 if (TYPE_PRECISION (typ1) == BITS_PER_UNIT)
816 if (char_type != char_type_node)
818 error ("char-array initialized from wide string");
819 return error_mark_node;
824 if (char_type == char_type_node)
826 error ("int-array initialized from non-wide string");
827 return error_mark_node;
829 else if (char_type != typ1)
831 error ("int-array initialized from incompatible wide string");
832 return error_mark_node;
836 TREE_TYPE (init) = type;
837 if (TYPE_DOMAIN (type) != 0 && TREE_CONSTANT (TYPE_SIZE (type)))
839 int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
840 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
841 /* In C it is ok to subtract 1 from the length of the string
842 because it's ok to ignore the terminating null char that is
843 counted in the length of the constant, but in C++ this would
845 if (size < TREE_STRING_LENGTH (init))
846 permerror (input_location, "initializer-string for array of chars is too long");
852 /* Handle scalar types (including conversions) and references. */
853 if ((TREE_CODE (type) != COMPLEX_TYPE
854 || BRACE_ENCLOSED_INITIALIZER_P (init))
855 && (SCALAR_TYPE_P (type) || code == REFERENCE_TYPE))
859 if (cxx_dialect != cxx98 && nested)
860 check_narrowing (type, init);
861 init = convert_for_initialization (0, type, init, flags,
862 ICR_INIT, NULL_TREE, 0,
863 tf_warning_or_error);
866 /* Skip any conversions since we'll be outputting the underlying
868 while (CONVERT_EXPR_P (*exp)
869 || TREE_CODE (*exp) == NON_LVALUE_EXPR)
870 exp = &TREE_OPERAND (*exp, 0);
872 *exp = cplus_expand_constant (*exp);
877 /* Come here only for aggregates: records, arrays, unions, complex numbers
879 gcc_assert (TREE_CODE (type) == ARRAY_TYPE
880 || TREE_CODE (type) == VECTOR_TYPE
881 || TREE_CODE (type) == RECORD_TYPE
882 || TREE_CODE (type) == UNION_TYPE
883 || TREE_CODE (type) == COMPLEX_TYPE);
885 if (BRACE_ENCLOSED_INITIALIZER_P (init)
886 && !TYPE_NON_AGGREGATE_CLASS (type))
887 return process_init_constructor (type, init);
890 if (COMPOUND_LITERAL_P (init) && TREE_CODE (type) == ARRAY_TYPE)
892 error ("cannot initialize aggregate of type %qT with "
893 "a compound literal", type);
895 return error_mark_node;
898 if (TREE_CODE (type) == ARRAY_TYPE
899 && !BRACE_ENCLOSED_INITIALIZER_P (init))
901 /* Allow the result of build_array_copy and of
902 build_value_init_noctor. */
903 if ((TREE_CODE (init) == TARGET_EXPR
904 || TREE_CODE (init) == CONSTRUCTOR)
905 && (same_type_ignoring_top_level_qualifiers_p
906 (type, TREE_TYPE (init))))
909 error ("array must be initialized with a brace-enclosed"
911 return error_mark_node;
914 return convert_for_initialization (NULL_TREE, type, init,
916 ICR_INIT, NULL_TREE, 0,
917 tf_warning_or_error);
922 digest_init (tree type, tree init)
924 return digest_init_r (type, init, false, LOOKUP_IMPLICIT);
928 digest_init_flags (tree type, tree init, int flags)
930 return digest_init_r (type, init, false, flags);
933 /* Set of flags used within process_init_constructor to describe the
935 #define PICFLAG_ERRONEOUS 1
936 #define PICFLAG_NOT_ALL_CONSTANT 2
937 #define PICFLAG_NOT_ALL_SIMPLE 4
939 /* Given an initializer INIT, return the flag (PICFLAG_*) which better
943 picflag_from_initializer (tree init)
945 if (init == error_mark_node)
946 return PICFLAG_ERRONEOUS;
947 else if (!TREE_CONSTANT (init))
948 return PICFLAG_NOT_ALL_CONSTANT;
949 else if (!initializer_constant_valid_p (init, TREE_TYPE (init)))
950 return PICFLAG_NOT_ALL_SIMPLE;
954 /* Subroutine of process_init_constructor, which will process an initializer
955 INIT for an array or vector of type TYPE. Returns the flags (PICFLAG_*)
956 which describe the initializers. */
959 process_init_constructor_array (tree type, tree init)
961 unsigned HOST_WIDE_INT i, len = 0;
963 bool unbounded = false;
965 VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (init);
967 gcc_assert (TREE_CODE (type) == ARRAY_TYPE
968 || TREE_CODE (type) == VECTOR_TYPE);
970 if (TREE_CODE (type) == ARRAY_TYPE)
972 tree domain = TYPE_DOMAIN (type);
974 len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain))
975 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain))
978 unbounded = true; /* Take as many as there are. */
981 /* Vectors are like simple fixed-size arrays. */
982 len = TYPE_VECTOR_SUBPARTS (type);
984 /* There must not be more initializers than needed. */
985 if (!unbounded && VEC_length (constructor_elt, v) > len)
986 error ("too many initializers for %qT", type);
988 FOR_EACH_VEC_ELT (constructor_elt, v, i, ce)
992 gcc_assert (TREE_CODE (ce->index) == INTEGER_CST);
993 if (compare_tree_int (ce->index, i) != 0)
995 ce->value = error_mark_node;
996 sorry ("non-trivial designated initializers not supported");
1000 ce->index = size_int (i);
1001 gcc_assert (ce->value);
1002 ce->value = digest_init_r (TREE_TYPE (type), ce->value, true, LOOKUP_IMPLICIT);
1004 if (ce->value != error_mark_node)
1005 gcc_assert (same_type_ignoring_top_level_qualifiers_p
1006 (TREE_TYPE (type), TREE_TYPE (ce->value)));
1008 flags |= picflag_from_initializer (ce->value);
1011 /* No more initializers. If the array is unbounded, we are done. Otherwise,
1012 we must add initializers ourselves. */
1014 for (; i < len; ++i)
1018 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)))
1020 /* If this type needs constructors run for default-initialization,
1021 we can't rely on the back end to do it for us, so build up
1022 TARGET_EXPRs. If the type in question is a class, just build
1023 one up; if it's an array, recurse. */
1024 if (MAYBE_CLASS_TYPE_P (TREE_TYPE (type)))
1025 next = build_functional_cast (TREE_TYPE (type), NULL_TREE,
1026 tf_warning_or_error);
1028 next = build_constructor (init_list_type_node, NULL);
1029 next = digest_init (TREE_TYPE (type), next);
1031 else if (!zero_init_p (TREE_TYPE (type)))
1032 next = build_zero_init (TREE_TYPE (type),
1033 /*nelts=*/NULL_TREE,
1034 /*static_storage_p=*/false);
1036 /* The default zero-initialization is fine for us; don't
1037 add anything to the CONSTRUCTOR. */
1040 flags |= picflag_from_initializer (next);
1041 CONSTRUCTOR_APPEND_ELT (v, size_int (i), next);
1044 CONSTRUCTOR_ELTS (init) = v;
1048 /* Subroutine of process_init_constructor, which will process an initializer
1049 INIT for a class of type TYPE. Returns the flags (PICFLAG_*) which describe
1050 the initializers. */
1053 process_init_constructor_record (tree type, tree init)
1055 VEC(constructor_elt,gc) *v = NULL;
1058 unsigned HOST_WIDE_INT idx = 0;
1060 gcc_assert (TREE_CODE (type) == RECORD_TYPE);
1061 gcc_assert (!CLASSTYPE_VBASECLASSES (type));
1062 gcc_assert (!TYPE_BINFO (type)
1063 || !BINFO_N_BASE_BINFOS (TYPE_BINFO (type)));
1064 gcc_assert (!TYPE_POLYMORPHIC_P (type));
1066 /* Generally, we will always have an index for each initializer (which is
1067 a FIELD_DECL, put by reshape_init), but compound literals don't go trough
1068 reshape_init. So we need to handle both cases. */
1069 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
1074 if (!DECL_NAME (field) && DECL_C_BIT_FIELD (field))
1076 flags |= picflag_from_initializer (integer_zero_node);
1077 CONSTRUCTOR_APPEND_ELT (v, field, integer_zero_node);
1081 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
1084 /* If this is a bitfield, first convert to the declared type. */
1085 type = TREE_TYPE (field);
1086 if (DECL_BIT_FIELD_TYPE (field))
1087 type = DECL_BIT_FIELD_TYPE (field);
1089 if (idx < VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)))
1091 constructor_elt *ce = VEC_index (constructor_elt,
1092 CONSTRUCTOR_ELTS (init), idx);
1095 /* We can have either a FIELD_DECL or an IDENTIFIER_NODE. The
1096 latter case can happen in templates where lookup has to be
1098 gcc_assert (TREE_CODE (ce->index) == FIELD_DECL
1099 || TREE_CODE (ce->index) == IDENTIFIER_NODE);
1100 if (ce->index != field
1101 && ce->index != DECL_NAME (field))
1103 ce->value = error_mark_node;
1104 sorry ("non-trivial designated initializers not supported");
1108 gcc_assert (ce->value);
1109 next = digest_init_r (type, ce->value, true, LOOKUP_IMPLICIT);
1112 else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
1114 /* If this type needs constructors run for
1115 default-initialization, we can't rely on the back end to do it
1116 for us, so build up TARGET_EXPRs. If the type in question is
1117 a class, just build one up; if it's an array, recurse. */
1118 next = build_constructor (init_list_type_node, NULL);
1119 if (MAYBE_CLASS_TYPE_P (TREE_TYPE (field)))
1121 next = finish_compound_literal (TREE_TYPE (field), next);
1122 /* direct-initialize the target. No temporary is going
1124 if (TREE_CODE (next) == TARGET_EXPR)
1125 TARGET_EXPR_DIRECT_INIT_P (next) = true;
1128 next = digest_init_r (TREE_TYPE (field), next, true, LOOKUP_IMPLICIT);
1130 /* Warn when some struct elements are implicitly initialized. */
1131 warning (OPT_Wmissing_field_initializers,
1132 "missing initializer for member %qD", field);
1136 if (TREE_READONLY (field))
1137 error ("uninitialized const member %qD", field);
1138 else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
1139 error ("member %qD with uninitialized const fields", field);
1140 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
1141 error ("member %qD is uninitialized reference", field);
1143 /* Warn when some struct elements are implicitly initialized
1145 warning (OPT_Wmissing_field_initializers,
1146 "missing initializer for member %qD", field);
1148 if (!zero_init_p (TREE_TYPE (field)))
1149 next = build_zero_init (TREE_TYPE (field), /*nelts=*/NULL_TREE,
1150 /*static_storage_p=*/false);
1152 /* The default zero-initialization is fine for us; don't
1153 add anything to the CONSTRUCTOR. */
1157 /* If this is a bitfield, now convert to the lowered type. */
1158 if (type != TREE_TYPE (field))
1159 next = cp_convert_and_check (TREE_TYPE (field), next);
1160 flags |= picflag_from_initializer (next);
1161 CONSTRUCTOR_APPEND_ELT (v, field, next);
1164 if (idx < VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)))
1165 error ("too many initializers for %qT", type);
1167 CONSTRUCTOR_ELTS (init) = v;
1171 /* Subroutine of process_init_constructor, which will process a single
1172 initializer INIT for a union of type TYPE. Returns the flags (PICFLAG_*)
1173 which describe the initializer. */
1176 process_init_constructor_union (tree type, tree init)
1178 constructor_elt *ce;
1181 /* If the initializer was empty, use default zero initialization. */
1182 if (VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (init)))
1185 len = VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init));
1188 error ("too many initializers for %qT", type);
1189 VEC_block_remove (constructor_elt, CONSTRUCTOR_ELTS (init), 1, len-1);
1192 ce = VEC_index (constructor_elt, CONSTRUCTOR_ELTS (init), 0);
1194 /* If this element specifies a field, initialize via that field. */
1197 if (TREE_CODE (ce->index) == FIELD_DECL)
1199 else if (TREE_CODE (ce->index) == IDENTIFIER_NODE)
1201 /* This can happen within a cast, see g++.dg/opt/cse2.C. */
1202 tree name = ce->index;
1204 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1205 if (DECL_NAME (field) == name)
1209 error ("no field %qD found in union being initialized", field);
1210 ce->value = error_mark_node;
1216 gcc_assert (TREE_CODE (ce->index) == INTEGER_CST
1217 || TREE_CODE (ce->index) == RANGE_EXPR);
1218 error ("index value instead of field name in union initializer");
1219 ce->value = error_mark_node;
1224 /* Find the first named field. ANSI decided in September 1990
1225 that only named fields count here. */
1226 tree field = TYPE_FIELDS (type);
1227 while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
1228 field = TREE_CHAIN (field);
1229 if (field == NULL_TREE)
1231 error ("too many initializers for %qT", type);
1232 ce->value = error_mark_node;
1237 if (ce->value && ce->value != error_mark_node)
1238 ce->value = digest_init_r (TREE_TYPE (ce->index), ce->value, true, LOOKUP_IMPLICIT);
1240 return picflag_from_initializer (ce->value);
1243 /* Process INIT, a constructor for a variable of aggregate type TYPE. The
1244 constructor is a brace-enclosed initializer, and will be modified in-place.
1246 Each element is converted to the right type through digest_init, and
1247 missing initializers are added following the language rules (zero-padding,
1250 After the execution, the initializer will have TREE_CONSTANT if all elts are
1251 constant, and TREE_STATIC set if, in addition, all elts are simple enough
1252 constants that the assembler and linker can compute them.
1254 The function returns the initializer itself, or error_mark_node in case
1258 process_init_constructor (tree type, tree init)
1262 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
1264 if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == VECTOR_TYPE)
1265 flags = process_init_constructor_array (type, init);
1266 else if (TREE_CODE (type) == RECORD_TYPE)
1267 flags = process_init_constructor_record (type, init);
1268 else if (TREE_CODE (type) == UNION_TYPE)
1269 flags = process_init_constructor_union (type, init);
1273 if (flags & PICFLAG_ERRONEOUS)
1274 return error_mark_node;
1276 TREE_TYPE (init) = type;
1277 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE)
1278 cp_complete_array_type (&TREE_TYPE (init), init, /*do_default=*/0);
1279 if (!(flags & PICFLAG_NOT_ALL_CONSTANT))
1281 TREE_CONSTANT (init) = 1;
1282 if (!(flags & PICFLAG_NOT_ALL_SIMPLE))
1283 TREE_STATIC (init) = 1;
1288 /* Given a structure or union value DATUM, construct and return
1289 the structure or union component which results from narrowing
1290 that value to the base specified in BASETYPE. For example, given the
1293 class L { int ii; };
1294 class A : L { ... };
1295 class B : L { ... };
1296 class C : A, B { ... };
1304 x.A::ii refers to the ii member of the L part of
1305 the A part of the C object named by X. In this case,
1306 DATUM would be x, and BASETYPE would be A.
1308 I used to think that this was nonconformant, that the standard specified
1309 that first we look up ii in A, then convert x to an L& and pull out the
1310 ii part. But in fact, it does say that we convert x to an A&; A here
1311 is known as the "naming class". (jason 2000-12-19)
1313 BINFO_P points to a variable initialized either to NULL_TREE or to the
1314 binfo for the specific base subobject we want to convert to. */
1317 build_scoped_ref (tree datum, tree basetype, tree* binfo_p)
1321 if (datum == error_mark_node)
1322 return error_mark_node;
1326 binfo = lookup_base (TREE_TYPE (datum), basetype, ba_check, NULL);
1328 if (!binfo || binfo == error_mark_node)
1330 *binfo_p = NULL_TREE;
1332 error_not_base_type (basetype, TREE_TYPE (datum));
1333 return error_mark_node;
1337 return build_base_path (PLUS_EXPR, datum, binfo, 1);
1340 /* Build a reference to an object specified by the C++ `->' operator.
1341 Usually this just involves dereferencing the object, but if the
1342 `->' operator is overloaded, then such overloads must be
1343 performed until an object which does not have the `->' operator
1344 overloaded is found. An error is reported when circular pointer
1345 delegation is detected. */
1348 build_x_arrow (tree expr)
1350 tree orig_expr = expr;
1351 tree type = TREE_TYPE (expr);
1352 tree last_rval = NULL_TREE;
1353 VEC(tree,gc) *types_memoized = NULL;
1355 if (type == error_mark_node)
1356 return error_mark_node;
1358 if (processing_template_decl)
1360 if (type_dependent_expression_p (expr))
1361 return build_min_nt (ARROW_EXPR, expr);
1362 expr = build_non_dependent_expr (expr);
1365 if (MAYBE_CLASS_TYPE_P (type))
1367 while ((expr = build_new_op (COMPONENT_REF, LOOKUP_NORMAL, expr,
1368 NULL_TREE, NULL_TREE,
1369 /*overloaded_p=*/NULL,
1370 tf_warning_or_error)))
1372 if (expr == error_mark_node)
1373 return error_mark_node;
1375 if (vec_member (TREE_TYPE (expr), types_memoized))
1377 error ("circular pointer delegation detected");
1378 return error_mark_node;
1381 VEC_safe_push (tree, gc, types_memoized, TREE_TYPE (expr));
1385 if (last_rval == NULL_TREE)
1387 error ("base operand of %<->%> has non-pointer type %qT", type);
1388 return error_mark_node;
1391 if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE)
1392 last_rval = convert_from_reference (last_rval);
1395 last_rval = decay_conversion (expr);
1397 if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE)
1399 if (processing_template_decl)
1401 expr = build_min_non_dep (ARROW_EXPR, last_rval, orig_expr);
1402 /* It will be dereferenced. */
1403 TREE_TYPE (expr) = TREE_TYPE (TREE_TYPE (last_rval));
1407 return cp_build_indirect_ref (last_rval, RO_NULL, tf_warning_or_error);
1411 error ("result of %<operator->()%> yields non-pointer result");
1413 error ("base operand of %<->%> is not a pointer");
1414 return error_mark_node;
1417 /* Return an expression for "DATUM .* COMPONENT". DATUM has not
1418 already been checked out to be of aggregate type. */
1421 build_m_component_ref (tree datum, tree component)
1429 if (error_operand_p (datum) || error_operand_p (component))
1430 return error_mark_node;
1432 datum = mark_lvalue_use (datum);
1433 component = mark_rvalue_use (component);
1435 ptrmem_type = TREE_TYPE (component);
1436 if (!TYPE_PTR_TO_MEMBER_P (ptrmem_type))
1438 error ("%qE cannot be used as a member pointer, since it is of "
1440 component, ptrmem_type);
1441 return error_mark_node;
1444 objtype = TYPE_MAIN_VARIANT (TREE_TYPE (datum));
1445 if (! MAYBE_CLASS_TYPE_P (objtype))
1447 error ("cannot apply member pointer %qE to %qE, which is of "
1448 "non-class type %qT",
1449 component, datum, objtype);
1450 return error_mark_node;
1453 type = TYPE_PTRMEM_POINTED_TO_TYPE (ptrmem_type);
1454 ctype = complete_type (TYPE_PTRMEM_CLASS_TYPE (ptrmem_type));
1456 if (!COMPLETE_TYPE_P (ctype))
1458 if (!same_type_p (ctype, objtype))
1464 binfo = lookup_base (objtype, ctype, ba_check, NULL);
1469 error ("pointer to member type %qT incompatible with object "
1472 return error_mark_node;
1474 else if (binfo == error_mark_node)
1475 return error_mark_node;
1478 if (TYPE_PTRMEM_P (ptrmem_type))
1482 /* Compute the type of the field, as described in [expr.ref].
1483 There's no such thing as a mutable pointer-to-member, so
1484 things are not as complex as they are for references to
1485 non-static data members. */
1486 type = cp_build_qualified_type (type,
1487 (cp_type_quals (type)
1488 | cp_type_quals (TREE_TYPE (datum))));
1490 datum = build_address (datum);
1492 /* Convert object to the correct base. */
1494 datum = build_base_path (PLUS_EXPR, datum, binfo, 1);
1496 /* Build an expression for "object + offset" where offset is the
1497 value stored in the pointer-to-data-member. */
1498 ptype = build_pointer_type (type);
1499 datum = build2 (POINTER_PLUS_EXPR, ptype,
1500 fold_convert (ptype, datum),
1501 build_nop (sizetype, component));
1502 return cp_build_indirect_ref (datum, RO_NULL, tf_warning_or_error);
1505 return build2 (OFFSET_REF, type, datum, component);
1508 /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */
1511 build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
1513 /* This is either a call to a constructor,
1514 or a C cast in C++'s `functional' notation. */
1516 /* The type to which we are casting. */
1518 VEC(tree,gc) *parmvec;
1520 if (exp == error_mark_node || parms == error_mark_node)
1521 return error_mark_node;
1523 if (TREE_CODE (exp) == TYPE_DECL)
1524 type = TREE_TYPE (exp);
1528 if (TREE_CODE (type) == REFERENCE_TYPE && !parms)
1530 error ("invalid value-initialization of reference type");
1531 return error_mark_node;
1534 if (processing_template_decl)
1536 tree t = build_min (CAST_EXPR, type, parms);
1537 /* We don't know if it will or will not have side effects. */
1538 TREE_SIDE_EFFECTS (t) = 1;
1542 if (! MAYBE_CLASS_TYPE_P (type))
1544 if (parms == NULL_TREE)
1545 return cp_convert (type, integer_zero_node);
1547 /* This must build a C cast. */
1548 parms = build_x_compound_expr_from_list (parms, ELK_FUNC_CAST, complain);
1549 return cp_build_c_cast (type, parms, complain);
1552 /* Prepare to evaluate as a call to a constructor. If this expression
1553 is actually used, for example,
1555 return X (arg1, arg2, ...);
1557 then the slot being initialized will be filled in. */
1559 if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
1560 return error_mark_node;
1561 if (abstract_virtuals_error (NULL_TREE, type))
1562 return error_mark_node;
1566 If the expression list is a single-expression, the type
1567 conversion is equivalent (in definedness, and if defined in
1568 meaning) to the corresponding cast expression. */
1569 if (parms && TREE_CHAIN (parms) == NULL_TREE)
1570 return cp_build_c_cast (type, TREE_VALUE (parms), complain);
1574 The expression T(), where T is a simple-type-specifier for a
1575 non-array complete object type or the (possibly cv-qualified)
1576 void type, creates an rvalue of the specified type, which is
1577 value-initialized. */
1579 if (parms == NULL_TREE
1580 /* If there's a user-defined constructor, value-initialization is
1581 just calling the constructor, so fall through. */
1582 && !TYPE_HAS_USER_CONSTRUCTOR (type))
1584 exp = build_value_init (type, complain);
1585 exp = get_target_expr (exp);
1586 /* FIXME this is wrong */
1587 if (literal_type_p (type))
1588 TREE_CONSTANT (exp) = true;
1592 /* Call the constructor. */
1593 parmvec = make_tree_vector ();
1594 for (; parms != NULL_TREE; parms = TREE_CHAIN (parms))
1595 VEC_safe_push (tree, gc, parmvec, TREE_VALUE (parms));
1596 exp = build_special_member_call (NULL_TREE, complete_ctor_identifier,
1597 &parmvec, type, LOOKUP_NORMAL, complain);
1598 release_tree_vector (parmvec);
1600 if (exp == error_mark_node)
1601 return error_mark_node;
1603 return build_cplus_new (type, exp);
1607 /* Add new exception specifier SPEC, to the LIST we currently have.
1608 If it's already in LIST then do nothing.
1609 Moan if it's bad and we're allowed to. COMPLAIN < 0 means we
1610 know what we're doing. */
1613 add_exception_specifier (tree list, tree spec, int complain)
1618 diagnostic_t diag_type = DK_UNSPECIFIED; /* none */
1620 if (spec == error_mark_node)
1623 gcc_assert (spec && (!list || TREE_VALUE (list)));
1625 /* [except.spec] 1, type in an exception specifier shall not be
1626 incomplete, or pointer or ref to incomplete other than pointer
1628 is_ptr = TREE_CODE (core) == POINTER_TYPE;
1629 if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE)
1630 core = TREE_TYPE (core);
1633 else if (VOID_TYPE_P (core))
1635 else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM)
1637 else if (processing_template_decl)
1642 /* 15.4/1 says that types in an exception specifier must be complete,
1643 but it seems more reasonable to only require this on definitions
1644 and calls. So just give a pedwarn at this point; we will give an
1645 error later if we hit one of those two cases. */
1646 if (!COMPLETE_TYPE_P (complete_type (core)))
1647 diag_type = DK_PEDWARN; /* pedwarn */
1654 for (probe = list; probe; probe = TREE_CHAIN (probe))
1655 if (same_type_p (TREE_VALUE (probe), spec))
1658 list = tree_cons (NULL_TREE, spec, list);
1661 diag_type = DK_ERROR; /* error */
1663 if (diag_type != DK_UNSPECIFIED && complain)
1664 cxx_incomplete_type_diagnostic (NULL_TREE, core, diag_type);
1669 /* Combine the two exceptions specifier lists LIST and ADD, and return
1673 merge_exception_specifiers (tree list, tree add)
1677 /* For merging noexcept(true) and throw(), take the more recent one (LIST).
1678 A throw(type-list) spec takes precedence over a noexcept(false) spec.
1679 Any other noexcept-spec should only be merged with an equivalent one.
1680 So the !TREE_VALUE code below is correct for all cases. */
1681 else if (!TREE_VALUE (add))
1683 else if (!TREE_VALUE (list))
1687 tree orig_list = list;
1689 for (; add; add = TREE_CHAIN (add))
1691 tree spec = TREE_VALUE (add);
1694 for (probe = orig_list; probe; probe = TREE_CHAIN (probe))
1695 if (same_type_p (TREE_VALUE (probe), spec))
1699 spec = build_tree_list (NULL_TREE, spec);
1700 TREE_CHAIN (spec) = list;
1708 /* Subroutine of build_call. Ensure that each of the types in the
1709 exception specification is complete. Technically, 15.4/1 says that
1710 they need to be complete when we see a declaration of the function,
1711 but we should be able to get away with only requiring this when the
1712 function is defined or called. See also add_exception_specifier. */
1715 require_complete_eh_spec_types (tree fntype, tree decl)
1718 /* Don't complain about calls to op new. */
1719 if (decl && DECL_ARTIFICIAL (decl))
1721 for (raises = TYPE_RAISES_EXCEPTIONS (fntype); raises;
1722 raises = TREE_CHAIN (raises))
1724 tree type = TREE_VALUE (raises);
1725 if (type && !COMPLETE_TYPE_P (type))
1729 ("call to function %qD which throws incomplete type %q#T",
1732 error ("call to function which throws incomplete type %q#T",
1739 #include "gt-cp-typeck2.h"