1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
28 #include "tree-inline.h"
32 #include "splay-tree.h"
33 #include "gimple.h" /* gimple_has_body_p */
34 #include "hash-table.h"
36 static tree
bot_manip (tree
*, int *, void *);
37 static tree
bot_replace (tree
*, int *, void *);
38 static int list_hash_eq (const void *, const void *);
39 static hashval_t
list_hash_pieces (tree
, tree
, tree
);
40 static hashval_t
list_hash (const void *);
41 static tree
build_target_expr (tree
, tree
, tsubst_flags_t
);
42 static tree
count_trees_r (tree
*, int *, void *);
43 static tree
verify_stmt_tree_r (tree
*, int *, void *);
44 static tree
build_local_temp (tree
);
46 static tree
handle_java_interface_attribute (tree
*, tree
, tree
, int, bool *);
47 static tree
handle_com_interface_attribute (tree
*, tree
, tree
, int, bool *);
48 static tree
handle_init_priority_attribute (tree
*, tree
, tree
, int, bool *);
49 static tree
handle_abi_tag_attribute (tree
*, tree
, tree
, int, bool *);
51 /* If REF is an lvalue, returns the kind of lvalue that REF is.
52 Otherwise, returns clk_none. */
55 lvalue_kind (const_tree ref
)
57 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
58 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
60 /* Expressions of reference type are sometimes wrapped in
61 INDIRECT_REFs. INDIRECT_REFs are just internal compiler
62 representation, not part of the language, so we have to look
64 if (REFERENCE_REF_P (ref
))
65 return lvalue_kind (TREE_OPERAND (ref
, 0));
68 && TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
70 /* unnamed rvalue references are rvalues */
71 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref
))
72 && TREE_CODE (ref
) != PARM_DECL
74 && TREE_CODE (ref
) != COMPONENT_REF
75 /* Functions are always lvalues. */
76 && TREE_CODE (TREE_TYPE (TREE_TYPE (ref
))) != FUNCTION_TYPE
)
79 /* lvalue references and named rvalue references are lvalues. */
83 if (ref
== current_class_ptr
)
86 switch (TREE_CODE (ref
))
90 /* preincrements and predecrements are valid lvals, provided
91 what they refer to are valid lvals. */
92 case PREINCREMENT_EXPR
:
93 case PREDECREMENT_EXPR
:
95 case WITH_CLEANUP_EXPR
:
98 return lvalue_kind (TREE_OPERAND (ref
, 0));
101 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
102 /* Look at the member designator. */
103 if (!op1_lvalue_kind
)
105 else if (is_overloaded_fn (TREE_OPERAND (ref
, 1)))
106 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
107 situations. If we're seeing a COMPONENT_REF, it's a non-static
108 member, so it isn't an lvalue. */
109 op1_lvalue_kind
= clk_none
;
110 else if (TREE_CODE (TREE_OPERAND (ref
, 1)) != FIELD_DECL
)
111 /* This can be IDENTIFIER_NODE in a template. */;
112 else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
114 /* Clear the ordinary bit. If this object was a class
115 rvalue we want to preserve that information. */
116 op1_lvalue_kind
&= ~clk_ordinary
;
117 /* The lvalue is for a bitfield. */
118 op1_lvalue_kind
|= clk_bitfield
;
120 else if (DECL_PACKED (TREE_OPERAND (ref
, 1)))
121 op1_lvalue_kind
|= clk_packed
;
123 return op1_lvalue_kind
;
126 case COMPOUND_LITERAL_EXPR
:
130 /* CONST_DECL without TREE_STATIC are enumeration values and
131 thus not lvalues. With TREE_STATIC they are used by ObjC++
132 in objc_build_string_object and need to be considered as
134 if (! TREE_STATIC (ref
))
137 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
138 && DECL_LANG_SPECIFIC (ref
)
139 && DECL_IN_AGGR_P (ref
))
148 /* A scope ref in a template, left as SCOPE_REF to support later
151 gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref
)));
153 tree op
= TREE_OPERAND (ref
, 1);
154 if (TREE_CODE (op
) == FIELD_DECL
)
155 return (DECL_C_BIT_FIELD (op
) ? clk_bitfield
: clk_ordinary
);
157 return lvalue_kind (op
);
162 /* Disallow <? and >? as lvalues if either argument side-effects. */
163 if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 0))
164 || TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 1)))
166 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
167 op2_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 1));
171 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 1)
172 ? TREE_OPERAND (ref
, 1)
173 : TREE_OPERAND (ref
, 0));
174 op2_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 2));
182 return lvalue_kind (TREE_OPERAND (ref
, 1));
188 return (CLASS_TYPE_P (TREE_TYPE (ref
)) ? clk_class
: clk_none
);
191 /* We can see calls outside of TARGET_EXPR in templates. */
192 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
197 /* All functions (except non-static-member functions) are
199 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
200 ? clk_none
: clk_ordinary
);
203 /* We now represent a reference to a single static member function
205 /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
206 its argument unmodified and we assign it to a const_tree. */
207 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref
)));
209 case NON_DEPENDENT_EXPR
:
210 /* We just return clk_ordinary for NON_DEPENDENT_EXPR in C++98, but
211 in C++11 lvalues don't bind to rvalue references, so we need to
212 work harder to avoid bogus errors (c++/44870). */
213 if (cxx_dialect
< cxx0x
)
216 return lvalue_kind (TREE_OPERAND (ref
, 0));
219 if (!TREE_TYPE (ref
))
221 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
226 /* If one operand is not an lvalue at all, then this expression is
228 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
231 /* Otherwise, it's an lvalue, and it has all the odd properties
232 contributed by either operand. */
233 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
234 /* It's not an ordinary lvalue if it involves any other kind. */
235 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
236 op1_lvalue_kind
&= ~clk_ordinary
;
237 /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
238 A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
239 if ((op1_lvalue_kind
& (clk_rvalueref
|clk_class
))
240 && (op1_lvalue_kind
& (clk_bitfield
|clk_packed
)))
241 op1_lvalue_kind
= clk_none
;
242 return op1_lvalue_kind
;
245 /* Returns the kind of lvalue that REF is, in the sense of
246 [basic.lval]. This function should really be named lvalue_p; it
247 computes the C++ definition of lvalue. */
250 real_lvalue_p (const_tree ref
)
252 cp_lvalue_kind kind
= lvalue_kind (ref
);
253 if (kind
& (clk_rvalueref
|clk_class
))
259 /* This differs from real_lvalue_p in that class rvalues are considered
263 lvalue_p (const_tree ref
)
265 return (lvalue_kind (ref
) != clk_none
);
268 /* This differs from real_lvalue_p in that rvalues formed by dereferencing
269 rvalue references are considered rvalues. */
272 lvalue_or_rvalue_with_address_p (const_tree ref
)
274 cp_lvalue_kind kind
= lvalue_kind (ref
);
275 if (kind
& clk_class
)
278 return (kind
!= clk_none
);
281 /* Returns true if REF is an xvalue, false otherwise. */
284 xvalue_p (const_tree ref
)
286 return (lvalue_kind (ref
) == clk_rvalueref
);
289 /* Test whether DECL is a builtin that may appear in a
290 constant-expression. */
293 builtin_valid_in_constant_expr_p (const_tree decl
)
295 /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing
296 in constant-expressions. We may want to add other builtins later. */
297 return DECL_IS_BUILTIN_CONSTANT_P (decl
);
300 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
303 build_target_expr (tree decl
, tree value
, tsubst_flags_t complain
)
306 tree type
= TREE_TYPE (decl
);
308 #ifdef ENABLE_CHECKING
309 gcc_assert (VOID_TYPE_P (TREE_TYPE (value
))
310 || TREE_TYPE (decl
) == TREE_TYPE (value
)
311 /* On ARM ctors return 'this'. */
312 || (TYPE_PTR_P (TREE_TYPE (value
))
313 && TREE_CODE (value
) == CALL_EXPR
)
314 || useless_type_conversion_p (TREE_TYPE (decl
),
318 t
= cxx_maybe_build_cleanup (decl
, complain
);
319 if (t
== error_mark_node
)
320 return error_mark_node
;
321 t
= build4 (TARGET_EXPR
, type
, decl
, value
, t
, NULL_TREE
);
322 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
323 ignore the TARGET_EXPR. If there really turn out to be no
324 side-effects, then the optimizer should be able to get rid of
325 whatever code is generated anyhow. */
326 TREE_SIDE_EFFECTS (t
) = 1;
331 /* Return an undeclared local temporary of type TYPE for use in building a
335 build_local_temp (tree type
)
337 tree slot
= build_decl (input_location
,
338 VAR_DECL
, NULL_TREE
, type
);
339 DECL_ARTIFICIAL (slot
) = 1;
340 DECL_IGNORED_P (slot
) = 1;
341 DECL_CONTEXT (slot
) = current_function_decl
;
342 layout_decl (slot
, 0);
346 /* Set various status flags when building an AGGR_INIT_EXPR object T. */
349 process_aggr_init_operands (tree t
)
353 side_effects
= TREE_SIDE_EFFECTS (t
);
357 n
= TREE_OPERAND_LENGTH (t
);
358 for (i
= 1; i
< n
; i
++)
360 tree op
= TREE_OPERAND (t
, i
);
361 if (op
&& TREE_SIDE_EFFECTS (op
))
368 TREE_SIDE_EFFECTS (t
) = side_effects
;
371 /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
372 FN, and SLOT. NARGS is the number of call arguments which are specified
373 as a tree array ARGS. */
376 build_aggr_init_array (tree return_type
, tree fn
, tree slot
, int nargs
,
382 t
= build_vl_exp (AGGR_INIT_EXPR
, nargs
+ 3);
383 TREE_TYPE (t
) = return_type
;
384 AGGR_INIT_EXPR_FN (t
) = fn
;
385 AGGR_INIT_EXPR_SLOT (t
) = slot
;
386 for (i
= 0; i
< nargs
; i
++)
387 AGGR_INIT_EXPR_ARG (t
, i
) = args
[i
];
388 process_aggr_init_operands (t
);
392 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
393 target. TYPE is the type to be initialized.
395 Build an AGGR_INIT_EXPR to represent the initialization. This function
396 differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
397 to initialize another object, whereas a TARGET_EXPR can either
398 initialize another object or create its own temporary object, and as a
399 result building up a TARGET_EXPR requires that the type's destructor be
403 build_aggr_init_expr (tree type
, tree init
)
410 /* Don't build AGGR_INIT_EXPR in a template. */
411 if (processing_template_decl
)
414 if (TREE_CODE (init
) == CALL_EXPR
)
415 fn
= CALL_EXPR_FN (init
);
416 else if (TREE_CODE (init
) == AGGR_INIT_EXPR
)
417 fn
= AGGR_INIT_EXPR_FN (init
);
419 return convert (type
, init
);
421 is_ctor
= (TREE_CODE (fn
) == ADDR_EXPR
422 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
423 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
425 /* We split the CALL_EXPR into its function and its arguments here.
426 Then, in expand_expr, we put them back together. The reason for
427 this is that this expression might be a default argument
428 expression. In that case, we need a new temporary every time the
429 expression is used. That's what break_out_target_exprs does; it
430 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
431 temporary slot. Then, expand_expr builds up a call-expression
432 using the new slot. */
434 /* If we don't need to use a constructor to create an object of this
435 type, don't mess with AGGR_INIT_EXPR. */
436 if (is_ctor
|| TREE_ADDRESSABLE (type
))
438 slot
= build_local_temp (type
);
440 if (TREE_CODE(init
) == CALL_EXPR
)
441 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
442 call_expr_nargs (init
),
443 CALL_EXPR_ARGP (init
));
445 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
446 aggr_init_expr_nargs (init
),
447 AGGR_INIT_EXPR_ARGP (init
));
448 TREE_SIDE_EFFECTS (rval
) = 1;
449 AGGR_INIT_VIA_CTOR_P (rval
) = is_ctor
;
450 TREE_NOTHROW (rval
) = TREE_NOTHROW (init
);
458 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
459 target. TYPE is the type that this initialization should appear to
462 Build an encapsulation of the initialization to perform
463 and return it so that it can be processed by language-independent
464 and language-specific expression expanders. */
467 build_cplus_new (tree type
, tree init
, tsubst_flags_t complain
)
469 tree rval
= build_aggr_init_expr (type
, init
);
472 if (!complete_type_or_maybe_complain (type
, init
, complain
))
473 return error_mark_node
;
475 /* Make sure that we're not trying to create an instance of an
477 if (abstract_virtuals_error_sfinae (NULL_TREE
, type
, complain
))
478 return error_mark_node
;
480 if (TREE_CODE (rval
) == AGGR_INIT_EXPR
)
481 slot
= AGGR_INIT_EXPR_SLOT (rval
);
482 else if (TREE_CODE (rval
) == CALL_EXPR
483 || TREE_CODE (rval
) == CONSTRUCTOR
)
484 slot
= build_local_temp (type
);
488 rval
= build_target_expr (slot
, rval
, complain
);
490 if (rval
!= error_mark_node
)
491 TARGET_EXPR_IMPLICIT_P (rval
) = 1;
496 /* Subroutine of build_vec_init_expr: Build up a single element
497 intialization as a proxy for the full array initialization to get things
498 marked as used and any appropriate diagnostics.
500 Since we're deferring building the actual constructor calls until
501 gimplification time, we need to build one now and throw it away so
502 that the relevant constructor gets mark_used before cgraph decides
503 what functions are needed. Here we assume that init is either
504 NULL_TREE, void_type_node (indicating value-initialization), or
505 another array to copy. */
508 build_vec_init_elt (tree type
, tree init
, tsubst_flags_t complain
)
510 tree inner_type
= strip_array_types (type
);
511 vec
<tree
, va_gc
> *argvec
;
513 if (integer_zerop (array_type_nelts_total (type
))
514 || !CLASS_TYPE_P (inner_type
))
515 /* No interesting initialization to do. */
516 return integer_zero_node
;
517 else if (init
== void_type_node
)
518 return build_value_init (inner_type
, complain
);
520 gcc_assert (init
== NULL_TREE
521 || (same_type_ignoring_top_level_qualifiers_p
522 (type
, TREE_TYPE (init
))));
524 argvec
= make_tree_vector ();
527 tree init_type
= strip_array_types (TREE_TYPE (init
));
528 tree dummy
= build_dummy_object (init_type
);
529 if (!real_lvalue_p (init
))
530 dummy
= move (dummy
);
531 argvec
->quick_push (dummy
);
533 init
= build_special_member_call (NULL_TREE
, complete_ctor_identifier
,
534 &argvec
, inner_type
, LOOKUP_NORMAL
,
536 release_tree_vector (argvec
);
538 /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
539 we don't want one here because we aren't creating a temporary. */
540 if (TREE_CODE (init
) == TARGET_EXPR
)
541 init
= TARGET_EXPR_INITIAL (init
);
546 /* Return a TARGET_EXPR which expresses the initialization of an array to
547 be named later, either default-initialization or copy-initialization
548 from another array of the same type. */
551 build_vec_init_expr (tree type
, tree init
, tsubst_flags_t complain
)
554 bool value_init
= false;
555 tree elt_init
= build_vec_init_elt (type
, init
, complain
);
557 if (init
== void_type_node
)
563 slot
= build_local_temp (type
);
564 init
= build2 (VEC_INIT_EXPR
, type
, slot
, init
);
565 TREE_SIDE_EFFECTS (init
) = true;
566 SET_EXPR_LOCATION (init
, input_location
);
568 if (cxx_dialect
>= cxx0x
569 && potential_constant_expression (elt_init
))
570 VEC_INIT_EXPR_IS_CONSTEXPR (init
) = true;
571 VEC_INIT_EXPR_VALUE_INIT (init
) = value_init
;
576 /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
577 that requires a constant expression. */
580 diagnose_non_constexpr_vec_init (tree expr
)
582 tree type
= TREE_TYPE (VEC_INIT_EXPR_SLOT (expr
));
584 if (VEC_INIT_EXPR_VALUE_INIT (expr
))
585 init
= void_type_node
;
587 init
= VEC_INIT_EXPR_INIT (expr
);
589 elt_init
= build_vec_init_elt (type
, init
, tf_warning_or_error
);
590 require_potential_constant_expression (elt_init
);
594 build_array_copy (tree init
)
596 return build_vec_init_expr (TREE_TYPE (init
), init
, tf_warning_or_error
);
599 /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
603 build_target_expr_with_type (tree init
, tree type
, tsubst_flags_t complain
)
605 gcc_assert (!VOID_TYPE_P (type
));
607 if (TREE_CODE (init
) == TARGET_EXPR
608 || init
== error_mark_node
)
610 else if (CLASS_TYPE_P (type
) && type_has_nontrivial_copy_init (type
)
611 && !VOID_TYPE_P (TREE_TYPE (init
))
612 && TREE_CODE (init
) != COND_EXPR
613 && TREE_CODE (init
) != CONSTRUCTOR
614 && TREE_CODE (init
) != VA_ARG_EXPR
)
615 /* We need to build up a copy constructor call. A void initializer
616 means we're being called from bot_manip. COND_EXPR is a special
617 case because we already have copies on the arms and we don't want
618 another one here. A CONSTRUCTOR is aggregate initialization, which
619 is handled separately. A VA_ARG_EXPR is magic creation of an
620 aggregate; there's no additional work to be done. */
621 return force_rvalue (init
, complain
);
623 return force_target_expr (type
, init
, complain
);
626 /* Like the above function, but without the checking. This function should
627 only be used by code which is deliberately trying to subvert the type
628 system, such as call_builtin_trap. Or build_over_call, to avoid
629 infinite recursion. */
632 force_target_expr (tree type
, tree init
, tsubst_flags_t complain
)
636 gcc_assert (!VOID_TYPE_P (type
));
638 slot
= build_local_temp (type
);
639 return build_target_expr (slot
, init
, complain
);
642 /* Like build_target_expr_with_type, but use the type of INIT. */
645 get_target_expr_sfinae (tree init
, tsubst_flags_t complain
)
647 if (TREE_CODE (init
) == AGGR_INIT_EXPR
)
648 return build_target_expr (AGGR_INIT_EXPR_SLOT (init
), init
, complain
);
649 else if (TREE_CODE (init
) == VEC_INIT_EXPR
)
650 return build_target_expr (VEC_INIT_EXPR_SLOT (init
), init
, complain
);
652 return build_target_expr_with_type (init
, TREE_TYPE (init
), complain
);
656 get_target_expr (tree init
)
658 return get_target_expr_sfinae (init
, tf_warning_or_error
);
661 /* If EXPR is a bitfield reference, convert it to the declared type of
662 the bitfield, and return the resulting expression. Otherwise,
663 return EXPR itself. */
666 convert_bitfield_to_declared_type (tree expr
)
670 bitfield_type
= is_bitfield_expr_with_lowered_type (expr
);
672 expr
= convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type
),
677 /* EXPR is being used in an rvalue context. Return a version of EXPR
678 that is marked as an rvalue. */
685 if (error_operand_p (expr
))
688 expr
= mark_rvalue_use (expr
);
692 Non-class rvalues always have cv-unqualified types. */
693 type
= TREE_TYPE (expr
);
694 if (!CLASS_TYPE_P (type
) && cv_qualified_p (type
))
695 type
= cv_unqualified (type
);
697 /* We need to do this for rvalue refs as well to get the right answer
698 from decltype; see c++/36628. */
699 if (!processing_template_decl
&& lvalue_or_rvalue_with_address_p (expr
))
700 expr
= build1 (NON_LVALUE_EXPR
, type
, expr
);
701 else if (type
!= TREE_TYPE (expr
))
702 expr
= build_nop (type
, expr
);
708 /* Hash an ARRAY_TYPE. K is really of type `tree'. */
711 cplus_array_hash (const void* k
)
714 const_tree
const t
= (const_tree
) k
;
716 hash
= TYPE_UID (TREE_TYPE (t
));
718 hash
^= TYPE_UID (TYPE_DOMAIN (t
));
722 typedef struct cplus_array_info
{
727 /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
728 of type `cplus_array_info*'. */
731 cplus_array_compare (const void * k1
, const void * k2
)
733 const_tree
const t1
= (const_tree
) k1
;
734 const cplus_array_info
*const t2
= (const cplus_array_info
*) k2
;
736 return (TREE_TYPE (t1
) == t2
->type
&& TYPE_DOMAIN (t1
) == t2
->domain
);
739 /* Hash table containing dependent array types, which are unsuitable for
740 the language-independent type hash table. */
741 static GTY ((param_is (union tree_node
))) htab_t cplus_array_htab
;
743 /* Like build_array_type, but handle special C++ semantics. */
746 build_cplus_array_type (tree elt_type
, tree index_type
)
750 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
751 return error_mark_node
;
753 if (processing_template_decl
754 && (dependent_type_p (elt_type
)
755 || (index_type
&& !TREE_CONSTANT (TYPE_MAX_VALUE (index_type
)))))
758 cplus_array_info cai
;
761 if (cplus_array_htab
== NULL
)
762 cplus_array_htab
= htab_create_ggc (61, &cplus_array_hash
,
763 &cplus_array_compare
, NULL
);
765 hash
= TYPE_UID (elt_type
);
767 hash
^= TYPE_UID (index_type
);
769 cai
.domain
= index_type
;
771 e
= htab_find_slot_with_hash (cplus_array_htab
, &cai
, hash
, INSERT
);
773 /* We have found the type: we're done. */
777 /* Build a new array type. */
778 t
= cxx_make_type (ARRAY_TYPE
);
779 TREE_TYPE (t
) = elt_type
;
780 TYPE_DOMAIN (t
) = index_type
;
782 /* Store it in the hash table. */
785 /* Set the canonical type for this new node. */
786 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
787 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
788 SET_TYPE_STRUCTURAL_EQUALITY (t
);
789 else if (TYPE_CANONICAL (elt_type
) != elt_type
791 && TYPE_CANONICAL (index_type
) != index_type
))
793 = build_cplus_array_type
794 (TYPE_CANONICAL (elt_type
),
795 index_type
? TYPE_CANONICAL (index_type
) : index_type
);
797 TYPE_CANONICAL (t
) = t
;
802 if (!TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
803 && !(index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
))
804 && (TYPE_CANONICAL (elt_type
) != elt_type
805 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
)))
806 /* Make sure that the canonical type is on the appropriate
808 build_cplus_array_type
809 (TYPE_CANONICAL (elt_type
),
810 index_type
? TYPE_CANONICAL (index_type
) : index_type
);
811 t
= build_array_type (elt_type
, index_type
);
814 /* Push these needs up so that initialization takes place
817 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
818 TYPE_NEEDS_CONSTRUCTING (t
) = needs_ctor
;
820 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
821 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
) = needs_dtor
;
823 /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the
824 element type as well, so fix it up if needed. */
825 if (elt_type
!= TYPE_MAIN_VARIANT (elt_type
))
827 tree m
= build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type
),
830 if (TYPE_MAIN_VARIANT (t
) != m
)
832 if (COMPLETE_TYPE_P (t
) && !COMPLETE_TYPE_P (m
))
834 /* m was built before the element type was complete, so we
835 also need to copy the layout info from t. */
836 tree size
= TYPE_SIZE (t
);
837 tree size_unit
= TYPE_SIZE_UNIT (t
);
838 unsigned int align
= TYPE_ALIGN (t
);
839 unsigned int user_align
= TYPE_USER_ALIGN (t
);
840 enum machine_mode mode
= TYPE_MODE (t
);
841 for (tree var
= m
; var
; var
= TYPE_NEXT_VARIANT (var
))
843 TYPE_SIZE (var
) = size
;
844 TYPE_SIZE_UNIT (var
) = size_unit
;
845 TYPE_ALIGN (var
) = align
;
846 TYPE_USER_ALIGN (var
) = user_align
;
847 SET_TYPE_MODE (var
, mode
);
848 TYPE_NEEDS_CONSTRUCTING (var
) = needs_ctor
;
849 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (var
) = needs_dtor
;
853 TYPE_MAIN_VARIANT (t
) = m
;
854 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
855 TYPE_NEXT_VARIANT (m
) = t
;
859 /* Avoid spurious warnings with VLAs (c++/54583). */
860 if (TYPE_SIZE (t
) && EXPR_P (TYPE_SIZE (t
)))
861 TREE_NO_WARNING (TYPE_SIZE (t
)) = 1;
866 /* Return an ARRAY_TYPE with element type ELT and length N. */
869 build_array_of_n_type (tree elt
, int n
)
871 return build_cplus_array_type (elt
, build_index_type (size_int (n
- 1)));
874 /* Return a reference type node referring to TO_TYPE. If RVAL is
875 true, return an rvalue reference type, otherwise return an lvalue
876 reference type. If a type node exists, reuse it, otherwise create
879 cp_build_reference_type (tree to_type
, bool rval
)
882 lvalue_ref
= build_reference_type (to_type
);
886 /* This code to create rvalue reference types is based on and tied
887 to the code creating lvalue reference types in the middle-end
888 functions build_reference_type_for_mode and build_reference_type.
890 It works by putting the rvalue reference type nodes after the
891 lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
892 they will effectively be ignored by the middle end. */
894 for (t
= lvalue_ref
; (t
= TYPE_NEXT_REF_TO (t
)); )
895 if (TYPE_REF_IS_RVALUE (t
))
898 t
= build_distinct_type_copy (lvalue_ref
);
900 TYPE_REF_IS_RVALUE (t
) = true;
901 TYPE_NEXT_REF_TO (t
) = TYPE_NEXT_REF_TO (lvalue_ref
);
902 TYPE_NEXT_REF_TO (lvalue_ref
) = t
;
904 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
905 SET_TYPE_STRUCTURAL_EQUALITY (t
);
906 else if (TYPE_CANONICAL (to_type
) != to_type
)
908 = cp_build_reference_type (TYPE_CANONICAL (to_type
), rval
);
910 TYPE_CANONICAL (t
) = t
;
918 /* Returns EXPR cast to rvalue reference type, like std::move. */
923 tree type
= TREE_TYPE (expr
);
924 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
925 type
= cp_build_reference_type (type
, /*rval*/true);
926 return build_static_cast (type
, expr
, tf_warning_or_error
);
929 /* Used by the C++ front end to build qualified array types. However,
930 the C version of this function does not properly maintain canonical
931 types (which are not used in C). */
933 c_build_qualified_type (tree type
, int type_quals
)
935 return cp_build_qualified_type (type
, type_quals
);
939 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
940 arrays correctly. In particular, if TYPE is an array of T's, and
941 TYPE_QUALS is non-empty, returns an array of qualified T's.
943 FLAGS determines how to deal with ill-formed qualifications. If
944 tf_ignore_bad_quals is set, then bad qualifications are dropped
945 (this is permitted if TYPE was introduced via a typedef or template
946 type parameter). If bad qualifications are dropped and tf_warning
947 is set, then a warning is issued for non-const qualifications. If
948 tf_ignore_bad_quals is not set and tf_error is not set, we
949 return error_mark_node. Otherwise, we issue an error, and ignore
952 Qualification of a reference type is valid when the reference came
953 via a typedef or template type argument. [dcl.ref] No such
954 dispensation is provided for qualifying a function type. [dcl.fct]
955 DR 295 queries this and the proposed resolution brings it into line
956 with qualifying a reference. We implement the DR. We also behave
957 in a similar manner for restricting non-pointer types. */
960 cp_build_qualified_type_real (tree type
,
962 tsubst_flags_t complain
)
965 int bad_quals
= TYPE_UNQUALIFIED
;
967 if (type
== error_mark_node
)
970 if (type_quals
== cp_type_quals (type
))
973 if (TREE_CODE (type
) == ARRAY_TYPE
)
975 /* In C++, the qualification really applies to the array element
976 type. Obtain the appropriately qualified element type. */
979 = cp_build_qualified_type_real (TREE_TYPE (type
),
983 if (element_type
== error_mark_node
)
984 return error_mark_node
;
986 /* See if we already have an identically qualified type. Tests
987 should be equivalent to those in check_qualified_type. */
988 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
989 if (TREE_TYPE (t
) == element_type
990 && TYPE_NAME (t
) == TYPE_NAME (type
)
991 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
)
992 && attribute_list_equal (TYPE_ATTRIBUTES (t
),
993 TYPE_ATTRIBUTES (type
)))
998 t
= build_cplus_array_type (element_type
, TYPE_DOMAIN (type
));
1000 /* Keep the typedef name. */
1001 if (TYPE_NAME (t
) != TYPE_NAME (type
))
1003 t
= build_variant_type_copy (t
);
1004 TYPE_NAME (t
) = TYPE_NAME (type
);
1008 /* Even if we already had this variant, we update
1009 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1010 they changed since the variant was originally created.
1012 This seems hokey; if there is some way to use a previous
1013 variant *without* coming through here,
1014 TYPE_NEEDS_CONSTRUCTING will never be updated. */
1015 TYPE_NEEDS_CONSTRUCTING (t
)
1016 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
1017 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
1018 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
1021 else if (TYPE_PTRMEMFUNC_P (type
))
1023 /* For a pointer-to-member type, we can't just return a
1024 cv-qualified version of the RECORD_TYPE. If we do, we
1025 haven't changed the field that contains the actual pointer to
1026 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
1029 t
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
1030 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
1031 return build_ptrmemfunc_type (t
);
1033 else if (TREE_CODE (type
) == TYPE_PACK_EXPANSION
)
1035 tree t
= PACK_EXPANSION_PATTERN (type
);
1037 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
1038 return make_pack_expansion (t
);
1041 /* A reference or method type shall not be cv-qualified.
1042 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1043 (in CD1) we always ignore extra cv-quals on functions. */
1044 if (type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
)
1045 && (TREE_CODE (type
) == REFERENCE_TYPE
1046 || TREE_CODE (type
) == FUNCTION_TYPE
1047 || TREE_CODE (type
) == METHOD_TYPE
))
1049 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1050 bad_quals
|= type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
1051 type_quals
&= ~(TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
1054 /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1055 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1056 type_quals
|= type_memfn_quals (type
);
1058 /* A restrict-qualified type must be a pointer (or reference)
1059 to object or incomplete type. */
1060 if ((type_quals
& TYPE_QUAL_RESTRICT
)
1061 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
1062 && TREE_CODE (type
) != TYPENAME_TYPE
1063 && !POINTER_TYPE_P (type
))
1065 bad_quals
|= TYPE_QUAL_RESTRICT
;
1066 type_quals
&= ~TYPE_QUAL_RESTRICT
;
1069 if (bad_quals
== TYPE_UNQUALIFIED
1070 || (complain
& tf_ignore_bad_quals
))
1072 else if (!(complain
& tf_error
))
1073 return error_mark_node
;
1076 tree bad_type
= build_qualified_type (ptr_type_node
, bad_quals
);
1077 error ("%qV qualifiers cannot be applied to %qT",
1081 /* Retrieve (or create) the appropriately qualified variant. */
1082 result
= build_qualified_type (type
, type_quals
);
1084 /* Preserve exception specs and ref-qualifier since build_qualified_type
1085 doesn't know about them. */
1086 if (TREE_CODE (result
) == FUNCTION_TYPE
1087 || TREE_CODE (result
) == METHOD_TYPE
)
1089 result
= build_exception_variant (result
, TYPE_RAISES_EXCEPTIONS (type
));
1090 result
= build_ref_qualified_type (result
, type_memfn_rqual (type
));
1093 /* If this was a pointer-to-method type, and we just made a copy,
1094 then we need to unshare the record that holds the cached
1095 pointer-to-member-function type, because these will be distinct
1096 between the unqualified and qualified types. */
1098 && TYPE_PTR_P (type
)
1099 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
1100 && TYPE_LANG_SPECIFIC (result
) == TYPE_LANG_SPECIFIC (type
))
1101 TYPE_LANG_SPECIFIC (result
) = NULL
;
1103 /* We may also have ended up building a new copy of the canonical
1104 type of a pointer-to-method type, which could have the same
1105 sharing problem described above. */
1106 if (TYPE_CANONICAL (result
) != TYPE_CANONICAL (type
)
1107 && TYPE_PTR_P (type
)
1108 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
1109 && (TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result
))
1110 == TYPE_LANG_SPECIFIC (TYPE_CANONICAL (type
))))
1111 TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result
)) = NULL
;
1116 /* Return TYPE with const and volatile removed. */
1119 cv_unqualified (tree type
)
1123 if (type
== error_mark_node
)
1126 quals
= cp_type_quals (type
);
1127 quals
&= ~(TYPE_QUAL_CONST
|TYPE_QUAL_VOLATILE
);
1128 return cp_build_qualified_type (type
, quals
);
1131 /* Builds a qualified variant of T that is not a typedef variant.
1132 E.g. consider the following declarations:
1133 typedef const int ConstInt;
1134 typedef ConstInt* PtrConstInt;
1135 If T is PtrConstInt, this function returns a type representing
1137 In other words, if T is a typedef, the function returns the underlying type.
1138 The cv-qualification and attributes of the type returned match the
1140 They will always be compatible types.
1141 The returned type is built so that all of its subtypes
1142 recursively have their typedefs stripped as well.
1144 This is different from just returning TYPE_CANONICAL (T)
1145 Because of several reasons:
1146 * If T is a type that needs structural equality
1147 its TYPE_CANONICAL (T) will be NULL.
1148 * TYPE_CANONICAL (T) desn't carry type attributes
1149 and loses template parameter names. */
1152 strip_typedefs (tree t
)
1154 tree result
= NULL
, type
= NULL
, t0
= NULL
;
1156 if (!t
|| t
== error_mark_node
|| t
== TYPE_CANONICAL (t
))
1159 gcc_assert (TYPE_P (t
));
1161 switch (TREE_CODE (t
))
1164 type
= strip_typedefs (TREE_TYPE (t
));
1165 result
= build_pointer_type (type
);
1167 case REFERENCE_TYPE
:
1168 type
= strip_typedefs (TREE_TYPE (t
));
1169 result
= cp_build_reference_type (type
, TYPE_REF_IS_RVALUE (t
));
1172 t0
= strip_typedefs (TYPE_OFFSET_BASETYPE (t
));
1173 type
= strip_typedefs (TREE_TYPE (t
));
1174 result
= build_offset_type (t0
, type
);
1177 if (TYPE_PTRMEMFUNC_P (t
))
1179 t0
= strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t
));
1180 result
= build_ptrmemfunc_type (t0
);
1184 type
= strip_typedefs (TREE_TYPE (t
));
1185 t0
= strip_typedefs (TYPE_DOMAIN (t
));;
1186 result
= build_cplus_array_type (type
, t0
);
1191 tree arg_types
= NULL
, arg_node
, arg_type
;
1192 for (arg_node
= TYPE_ARG_TYPES (t
);
1194 arg_node
= TREE_CHAIN (arg_node
))
1196 if (arg_node
== void_list_node
)
1198 arg_type
= strip_typedefs (TREE_VALUE (arg_node
));
1199 gcc_assert (arg_type
);
1202 tree_cons (TREE_PURPOSE (arg_node
), arg_type
, arg_types
);
1206 arg_types
= nreverse (arg_types
);
1208 /* A list of parameters not ending with an ellipsis
1209 must end with void_list_node. */
1211 arg_types
= chainon (arg_types
, void_list_node
);
1213 type
= strip_typedefs (TREE_TYPE (t
));
1214 if (TREE_CODE (t
) == METHOD_TYPE
)
1216 tree class_type
= TREE_TYPE (TREE_VALUE (arg_types
));
1217 gcc_assert (class_type
);
1219 build_method_type_directly (class_type
, type
,
1220 TREE_CHAIN (arg_types
));
1224 result
= build_function_type (type
,
1226 result
= apply_memfn_quals (result
,
1227 type_memfn_quals (t
),
1228 type_memfn_rqual (t
));
1231 if (TYPE_RAISES_EXCEPTIONS (t
))
1232 result
= build_exception_variant (result
,
1233 TYPE_RAISES_EXCEPTIONS (t
));
1238 tree fullname
= TYPENAME_TYPE_FULLNAME (t
);
1239 if (TREE_CODE (fullname
) == TEMPLATE_ID_EXPR
1240 && TREE_OPERAND (fullname
, 1))
1242 tree args
= TREE_OPERAND (fullname
, 1);
1243 tree new_args
= copy_node (args
);
1244 bool changed
= false;
1245 for (int i
= 0; i
< TREE_VEC_LENGTH (args
); ++i
)
1247 tree arg
= TREE_VEC_ELT (args
, i
);
1250 strip_arg
= strip_typedefs (arg
);
1252 strip_arg
= strip_typedefs_expr (arg
);
1253 TREE_VEC_ELT (new_args
, i
) = strip_arg
;
1254 if (strip_arg
!= arg
)
1258 fullname
= lookup_template_function (TREE_OPERAND (fullname
, 0),
1261 ggc_free (new_args
);
1263 result
= make_typename_type (strip_typedefs (TYPE_CONTEXT (t
)),
1264 fullname
, typename_type
, tf_none
);
1268 result
= strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t
));
1269 if (result
== DECLTYPE_TYPE_EXPR (t
))
1272 result
= (finish_decltype_type
1274 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t
),
1282 result
= TYPE_MAIN_VARIANT (t
);
1283 if (TYPE_USER_ALIGN (t
) != TYPE_USER_ALIGN (result
)
1284 || TYPE_ALIGN (t
) != TYPE_ALIGN (result
))
1286 gcc_assert (TYPE_USER_ALIGN (t
));
1287 if (TYPE_ALIGN (t
) == TYPE_ALIGN (result
))
1288 result
= build_variant_type_copy (result
);
1290 result
= build_aligned_type (result
, TYPE_ALIGN (t
));
1291 TYPE_USER_ALIGN (result
) = true;
1293 if (TYPE_ATTRIBUTES (t
))
1294 result
= cp_build_type_attribute_variant (result
, TYPE_ATTRIBUTES (t
));
1295 return cp_build_qualified_type (result
, cp_type_quals (t
));
1298 /* Like strip_typedefs above, but works on expressions, so that in
1300 template<class T> struct A
1306 sizeof(TT) is replaced by sizeof(T). */
1309 strip_typedefs_expr (tree t
)
1313 enum tree_code code
;
1315 if (t
== NULL_TREE
|| t
== error_mark_node
)
1318 if (DECL_P (t
) || CONSTANT_CLASS_P (t
))
1321 /* Some expressions have type operands, so let's handle types here rather
1322 than check TYPE_P in multiple places below. */
1324 return strip_typedefs (t
);
1326 code
= TREE_CODE (t
);
1329 case IDENTIFIER_NODE
:
1330 case TEMPLATE_PARM_INDEX
:
1333 case ARGUMENT_PACK_SELECT
:
1338 tree type1
= strip_typedefs (TRAIT_EXPR_TYPE1 (t
));
1339 tree type2
= strip_typedefs (TRAIT_EXPR_TYPE2 (t
));
1340 if (type1
== TRAIT_EXPR_TYPE1 (t
)
1341 && type2
== TRAIT_EXPR_TYPE2 (t
))
1344 TRAIT_EXPR_TYPE1 (t
) = type1
;
1345 TRAIT_EXPR_TYPE2 (t
) = type2
;
1351 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
1352 bool changed
= false;
1354 for (it
= t
; it
; it
= TREE_CHAIN (it
))
1356 tree val
= strip_typedefs_expr (TREE_VALUE (t
));
1357 vec_safe_push (vec
, val
);
1358 if (val
!= TREE_VALUE (t
))
1360 gcc_assert (TREE_PURPOSE (it
) == NULL_TREE
);
1365 FOR_EACH_VEC_ELT_REVERSE (*vec
, i
, it
)
1366 r
= tree_cons (NULL_TREE
, it
, r
);
1370 release_tree_vector (vec
);
1376 bool changed
= false;
1377 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
1378 n
= TREE_VEC_LENGTH (t
);
1379 vec_safe_reserve (vec
, n
);
1380 for (i
= 0; i
< n
; ++i
)
1382 tree op
= strip_typedefs_expr (TREE_VEC_ELT (t
, i
));
1383 vec
->quick_push (op
);
1384 if (op
!= TREE_VEC_ELT (t
, i
))
1390 for (i
= 0; i
< n
; ++i
)
1391 TREE_VEC_ELT (r
, i
) = (*vec
)[i
];
1392 SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT
1393 (r
, GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (t
));
1397 release_tree_vector (vec
);
1403 bool changed
= false;
1404 vec
<constructor_elt
, va_gc
> *vec
1405 = vec_safe_copy (CONSTRUCTOR_ELTS (t
));
1406 n
= CONSTRUCTOR_NELTS (t
);
1407 type
= strip_typedefs (TREE_TYPE (t
));
1408 for (i
= 0; i
< n
; ++i
)
1410 constructor_elt
*e
= &(*vec
)[i
];
1411 tree op
= strip_typedefs_expr (e
->value
);
1417 gcc_checking_assert (e
->index
== strip_typedefs_expr (e
->index
));
1420 if (!changed
&& type
== TREE_TYPE (t
))
1428 TREE_TYPE (r
) = type
;
1429 CONSTRUCTOR_ELTS (r
) = vec
;
1435 error ("lambda-expression in a constant expression");
1436 return error_mark_node
;
1442 gcc_assert (EXPR_P (t
));
1444 n
= TREE_OPERAND_LENGTH (t
);
1445 ops
= XALLOCAVEC (tree
, n
);
1446 type
= TREE_TYPE (t
);
1451 case IMPLICIT_CONV_EXPR
:
1452 case DYNAMIC_CAST_EXPR
:
1453 case STATIC_CAST_EXPR
:
1454 case CONST_CAST_EXPR
:
1455 case REINTERPRET_CAST_EXPR
:
1458 type
= strip_typedefs (type
);
1462 for (i
= 0; i
< n
; ++i
)
1463 ops
[i
] = strip_typedefs_expr (TREE_OPERAND (t
, i
));
1467 /* If nothing changed, return t. */
1468 for (i
= 0; i
< n
; ++i
)
1469 if (ops
[i
] != TREE_OPERAND (t
, i
))
1471 if (i
== n
&& type
== TREE_TYPE (t
))
1475 TREE_TYPE (r
) = type
;
1476 for (i
= 0; i
< n
; ++i
)
1477 TREE_OPERAND (r
, i
) = ops
[i
];
1481 /* Makes a copy of BINFO and TYPE, which is to be inherited into a
1482 graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
1483 and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
1484 VIRT indicates whether TYPE is inherited virtually or not.
1485 IGO_PREV points at the previous binfo of the inheritance graph
1486 order chain. The newly copied binfo's TREE_CHAIN forms this
1489 The CLASSTYPE_VBASECLASSES vector of T is constructed in the
1490 correct order. That is in the order the bases themselves should be
1493 The BINFO_INHERITANCE of a virtual base class points to the binfo
1494 of the most derived type. ??? We could probably change this so that
1495 BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
1496 remove a field. They currently can only differ for primary virtual
1500 copy_binfo (tree binfo
, tree type
, tree t
, tree
*igo_prev
, int virt
)
1506 /* See if we've already made this virtual base. */
1507 new_binfo
= binfo_for_vbase (type
, t
);
1512 new_binfo
= make_tree_binfo (binfo
? BINFO_N_BASE_BINFOS (binfo
) : 0);
1513 BINFO_TYPE (new_binfo
) = type
;
1515 /* Chain it into the inheritance graph. */
1516 TREE_CHAIN (*igo_prev
) = new_binfo
;
1517 *igo_prev
= new_binfo
;
1519 if (binfo
&& !BINFO_DEPENDENT_BASE_P (binfo
))
1524 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), type
));
1526 BINFO_OFFSET (new_binfo
) = BINFO_OFFSET (binfo
);
1527 BINFO_VIRTUALS (new_binfo
) = BINFO_VIRTUALS (binfo
);
1529 /* We do not need to copy the accesses, as they are read only. */
1530 BINFO_BASE_ACCESSES (new_binfo
) = BINFO_BASE_ACCESSES (binfo
);
1532 /* Recursively copy base binfos of BINFO. */
1533 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
1535 tree new_base_binfo
;
1536 new_base_binfo
= copy_binfo (base_binfo
, BINFO_TYPE (base_binfo
),
1538 BINFO_VIRTUAL_P (base_binfo
));
1540 if (!BINFO_INHERITANCE_CHAIN (new_base_binfo
))
1541 BINFO_INHERITANCE_CHAIN (new_base_binfo
) = new_binfo
;
1542 BINFO_BASE_APPEND (new_binfo
, new_base_binfo
);
1546 BINFO_DEPENDENT_BASE_P (new_binfo
) = 1;
1550 /* Push it onto the list after any virtual bases it contains
1551 will have been pushed. */
1552 CLASSTYPE_VBASECLASSES (t
)->quick_push (new_binfo
);
1553 BINFO_VIRTUAL_P (new_binfo
) = 1;
1554 BINFO_INHERITANCE_CHAIN (new_binfo
) = TYPE_BINFO (t
);
1560 /* Hashing of lists so that we don't make duplicates.
1561 The entry point is `list_hash_canon'. */
1563 /* Now here is the hash table. When recording a list, it is added
1564 to the slot whose index is the hash code mod the table size.
1565 Note that the hash table is used for several kinds of lists.
1566 While all these live in the same table, they are completely independent,
1567 and the hash code is computed differently for each of these. */
1569 static GTY ((param_is (union tree_node
))) htab_t list_hash_table
;
1578 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
1579 for a node we are thinking about adding). */
1582 list_hash_eq (const void* entry
, const void* data
)
1584 const_tree
const t
= (const_tree
) entry
;
1585 const struct list_proxy
*const proxy
= (const struct list_proxy
*) data
;
1587 return (TREE_VALUE (t
) == proxy
->value
1588 && TREE_PURPOSE (t
) == proxy
->purpose
1589 && TREE_CHAIN (t
) == proxy
->chain
);
1592 /* Compute a hash code for a list (chain of TREE_LIST nodes
1593 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
1594 TREE_COMMON slots), by adding the hash codes of the individual entries. */
1597 list_hash_pieces (tree purpose
, tree value
, tree chain
)
1599 hashval_t hashcode
= 0;
1602 hashcode
+= TREE_HASH (chain
);
1605 hashcode
+= TREE_HASH (value
);
1609 hashcode
+= TREE_HASH (purpose
);
1615 /* Hash an already existing TREE_LIST. */
1618 list_hash (const void* p
)
1620 const_tree
const t
= (const_tree
) p
;
1621 return list_hash_pieces (TREE_PURPOSE (t
),
1626 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1627 object for an identical list if one already exists. Otherwise, build a
1628 new one, and record it as the canonical object. */
1631 hash_tree_cons (tree purpose
, tree value
, tree chain
)
1635 struct list_proxy proxy
;
1637 /* Hash the list node. */
1638 hashcode
= list_hash_pieces (purpose
, value
, chain
);
1639 /* Create a proxy for the TREE_LIST we would like to create. We
1640 don't actually create it so as to avoid creating garbage. */
1641 proxy
.purpose
= purpose
;
1642 proxy
.value
= value
;
1643 proxy
.chain
= chain
;
1644 /* See if it is already in the table. */
1645 slot
= htab_find_slot_with_hash (list_hash_table
, &proxy
, hashcode
,
1647 /* If not, create a new node. */
1649 *slot
= tree_cons (purpose
, value
, chain
);
1650 return (tree
) *slot
;
1653 /* Constructor for hashed lists. */
1656 hash_tree_chain (tree value
, tree chain
)
1658 return hash_tree_cons (NULL_TREE
, value
, chain
);
1662 debug_binfo (tree elem
)
1667 fprintf (stderr
, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
1669 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1670 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1671 debug_tree (BINFO_TYPE (elem
));
1672 if (BINFO_VTABLE (elem
))
1673 fprintf (stderr
, "vtable decl \"%s\"\n",
1674 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem
))));
1676 fprintf (stderr
, "no vtable decl yet\n");
1677 fprintf (stderr
, "virtuals:\n");
1678 virtuals
= BINFO_VIRTUALS (elem
);
1683 tree fndecl
= TREE_VALUE (virtuals
);
1684 fprintf (stderr
, "%s [%ld =? %ld]\n",
1685 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1686 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1688 virtuals
= TREE_CHAIN (virtuals
);
1692 /* Build a representation for the qualified name SCOPE::NAME. TYPE is
1693 the type of the result expression, if known, or NULL_TREE if the
1694 resulting expression is type-dependent. If TEMPLATE_P is true,
1695 NAME is known to be a template because the user explicitly used the
1696 "template" keyword after the "::".
1698 All SCOPE_REFs should be built by use of this function. */
1701 build_qualified_name (tree type
, tree scope
, tree name
, bool template_p
)
1704 if (type
== error_mark_node
1705 || scope
== error_mark_node
1706 || name
== error_mark_node
)
1707 return error_mark_node
;
1708 t
= build2 (SCOPE_REF
, type
, scope
, name
);
1709 QUALIFIED_NAME_IS_TEMPLATE (t
) = template_p
;
1710 PTRMEM_OK_P (t
) = true;
1712 t
= convert_from_reference (t
);
1716 /* Like check_qualified_type, but also check ref-qualifier and exception
1720 cp_check_qualified_type (const_tree cand
, const_tree base
, int type_quals
,
1721 cp_ref_qualifier rqual
, tree raises
)
1723 return (check_qualified_type (cand
, base
, type_quals
)
1724 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (cand
),
1726 && type_memfn_rqual (cand
) == rqual
);
1729 /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
1732 build_ref_qualified_type (tree type
, cp_ref_qualifier rqual
)
1736 if (rqual
== type_memfn_rqual (type
))
1739 int type_quals
= TYPE_QUALS (type
);
1740 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
1741 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1742 if (cp_check_qualified_type (t
, type
, type_quals
, rqual
, raises
))
1745 t
= build_variant_type_copy (type
);
1748 case REF_QUAL_RVALUE
:
1749 FUNCTION_RVALUE_QUALIFIED (t
) = 1;
1750 /* Intentional fall through */
1751 case REF_QUAL_LVALUE
:
1752 FUNCTION_REF_QUALIFIED (t
) = 1;
1755 FUNCTION_REF_QUALIFIED (t
) = 0;
1759 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
1760 /* Propagate structural equality. */
1761 SET_TYPE_STRUCTURAL_EQUALITY (t
);
1762 else if (TYPE_CANONICAL (type
) != type
)
1763 /* Build the underlying canonical type, since it is different
1765 TYPE_CANONICAL (t
) = build_ref_qualified_type (TYPE_CANONICAL (type
),
1768 /* T is its own canonical type. */
1769 TYPE_CANONICAL (t
) = t
;
1774 /* Returns nonzero if X is an expression for a (possibly overloaded)
1775 function. If "f" is a function or function template, "f", "c->f",
1776 "c.f", "C::f", and "f<int>" will all be considered possibly
1777 overloaded functions. Returns 2 if the function is actually
1778 overloaded, i.e., if it is impossible to know the type of the
1779 function without performing overload resolution. */
1782 is_overloaded_fn (tree x
)
1784 /* A baselink is also considered an overloaded function. */
1785 if (TREE_CODE (x
) == OFFSET_REF
1786 || TREE_CODE (x
) == COMPONENT_REF
)
1787 x
= TREE_OPERAND (x
, 1);
1789 x
= BASELINK_FUNCTIONS (x
);
1790 if (TREE_CODE (x
) == TEMPLATE_ID_EXPR
)
1791 x
= TREE_OPERAND (x
, 0);
1792 if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x
))
1793 || (TREE_CODE (x
) == OVERLOAD
&& OVL_CHAIN (x
)))
1795 return (TREE_CODE (x
) == FUNCTION_DECL
1796 || TREE_CODE (x
) == OVERLOAD
);
1799 /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
1800 (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
1804 dependent_name (tree x
)
1806 if (identifier_p (x
))
1808 if (TREE_CODE (x
) != COMPONENT_REF
1809 && TREE_CODE (x
) != OFFSET_REF
1810 && TREE_CODE (x
) != BASELINK
1811 && is_overloaded_fn (x
))
1812 return DECL_NAME (get_first_fn (x
));
1816 /* Returns true iff X is an expression for an overloaded function
1817 whose type cannot be known without performing overload
1821 really_overloaded_fn (tree x
)
1823 return is_overloaded_fn (x
) == 2;
1829 gcc_assert (is_overloaded_fn (from
));
1830 /* A baselink is also considered an overloaded function. */
1831 if (TREE_CODE (from
) == OFFSET_REF
1832 || TREE_CODE (from
) == COMPONENT_REF
)
1833 from
= TREE_OPERAND (from
, 1);
1834 if (BASELINK_P (from
))
1835 from
= BASELINK_FUNCTIONS (from
);
1836 if (TREE_CODE (from
) == TEMPLATE_ID_EXPR
)
1837 from
= TREE_OPERAND (from
, 0);
1842 get_first_fn (tree from
)
1844 return OVL_CURRENT (get_fns (from
));
1847 /* Return a new OVL node, concatenating it with the old one. */
1850 ovl_cons (tree decl
, tree chain
)
1852 tree result
= make_node (OVERLOAD
);
1853 TREE_TYPE (result
) = unknown_type_node
;
1854 OVL_FUNCTION (result
) = decl
;
1855 TREE_CHAIN (result
) = chain
;
1860 /* Build a new overloaded function. If this is the first one,
1861 just return it; otherwise, ovl_cons the _DECLs */
1864 build_overload (tree decl
, tree chain
)
1866 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
1868 return ovl_cons (decl
, chain
);
1871 /* Return the scope where the overloaded functions OVL were found. */
1874 ovl_scope (tree ovl
)
1876 if (TREE_CODE (ovl
) == OFFSET_REF
1877 || TREE_CODE (ovl
) == COMPONENT_REF
)
1878 ovl
= TREE_OPERAND (ovl
, 1);
1879 if (TREE_CODE (ovl
) == BASELINK
)
1880 return BINFO_TYPE (BASELINK_BINFO (ovl
));
1881 if (TREE_CODE (ovl
) == TEMPLATE_ID_EXPR
)
1882 ovl
= TREE_OPERAND (ovl
, 0);
1883 /* Skip using-declarations. */
1884 while (TREE_CODE (ovl
) == OVERLOAD
&& OVL_USED (ovl
) && OVL_CHAIN (ovl
))
1885 ovl
= OVL_CHAIN (ovl
);
1886 return CP_DECL_CONTEXT (OVL_CURRENT (ovl
));
1889 /* Return TRUE if FN is a non-static member function, FALSE otherwise.
1890 This function looks into BASELINK and OVERLOAD nodes. */
1893 non_static_member_function_p (tree fn
)
1895 if (fn
== NULL_TREE
)
1898 if (is_overloaded_fn (fn
))
1899 fn
= get_first_fn (fn
);
1902 && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn
));
1906 #define PRINT_RING_SIZE 4
1909 cxx_printable_name_internal (tree decl
, int v
, bool translate
)
1911 static unsigned int uid_ring
[PRINT_RING_SIZE
];
1912 static char *print_ring
[PRINT_RING_SIZE
];
1913 static bool trans_ring
[PRINT_RING_SIZE
];
1914 static int ring_counter
;
1917 /* Only cache functions. */
1919 || TREE_CODE (decl
) != FUNCTION_DECL
1920 || DECL_LANG_SPECIFIC (decl
) == 0)
1921 return lang_decl_name (decl
, v
, translate
);
1923 /* See if this print name is lying around. */
1924 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1925 if (uid_ring
[i
] == DECL_UID (decl
) && translate
== trans_ring
[i
])
1926 /* yes, so return it. */
1927 return print_ring
[i
];
1929 if (++ring_counter
== PRINT_RING_SIZE
)
1932 if (current_function_decl
!= NULL_TREE
)
1934 /* There may be both translated and untranslated versions of the
1936 for (i
= 0; i
< 2; i
++)
1938 if (uid_ring
[ring_counter
] == DECL_UID (current_function_decl
))
1940 if (ring_counter
== PRINT_RING_SIZE
)
1943 gcc_assert (uid_ring
[ring_counter
] != DECL_UID (current_function_decl
));
1946 free (print_ring
[ring_counter
]);
1948 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
, translate
));
1949 uid_ring
[ring_counter
] = DECL_UID (decl
);
1950 trans_ring
[ring_counter
] = translate
;
1951 return print_ring
[ring_counter
];
1955 cxx_printable_name (tree decl
, int v
)
1957 return cxx_printable_name_internal (decl
, v
, false);
1961 cxx_printable_name_translate (tree decl
, int v
)
1963 return cxx_printable_name_internal (decl
, v
, true);
1966 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
1967 listed in RAISES. */
1970 build_exception_variant (tree type
, tree raises
)
1975 if (comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (type
), ce_exact
))
1978 type_quals
= TYPE_QUALS (type
);
1979 cp_ref_qualifier rqual
= type_memfn_rqual (type
);
1980 for (v
= TYPE_MAIN_VARIANT (type
); v
; v
= TYPE_NEXT_VARIANT (v
))
1981 if (cp_check_qualified_type (v
, type
, type_quals
, rqual
, raises
))
1984 /* Need to build a new variant. */
1985 v
= build_variant_type_copy (type
);
1986 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
1990 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
1991 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
1995 bind_template_template_parm (tree t
, tree newargs
)
1997 tree decl
= TYPE_NAME (t
);
2000 t2
= cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM
);
2001 decl
= build_decl (input_location
,
2002 TYPE_DECL
, DECL_NAME (decl
), NULL_TREE
);
2004 /* These nodes have to be created to reflect new TYPE_DECL and template
2006 TEMPLATE_TYPE_PARM_INDEX (t2
) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t
));
2007 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2
)) = decl
;
2008 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
2009 = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t
), newargs
);
2011 TREE_TYPE (decl
) = t2
;
2012 TYPE_NAME (t2
) = decl
;
2013 TYPE_STUB_DECL (t2
) = decl
;
2015 SET_TYPE_STRUCTURAL_EQUALITY (t2
);
2020 /* Called from count_trees via walk_tree. */
2023 count_trees_r (tree
*tp
, int *walk_subtrees
, void *data
)
2033 /* Debugging function for measuring the rough complexity of a tree
2037 count_trees (tree t
)
2040 cp_walk_tree_without_duplicates (&t
, count_trees_r
, &n_trees
);
2044 /* Called from verify_stmt_tree via walk_tree. */
2047 verify_stmt_tree_r (tree
* tp
, int * /*walk_subtrees*/, void* data
)
2050 hash_table
<pointer_hash
<tree_node
> > *statements
2051 = static_cast <hash_table
<pointer_hash
<tree_node
> > *> (data
);
2054 if (!STATEMENT_CODE_P (TREE_CODE (t
)))
2057 /* If this statement is already present in the hash table, then
2058 there is a circularity in the statement tree. */
2059 gcc_assert (!statements
->find (t
));
2061 slot
= statements
->find_slot (t
, INSERT
);
2067 /* Debugging function to check that the statement T has not been
2068 corrupted. For now, this function simply checks that T contains no
2072 verify_stmt_tree (tree t
)
2074 hash_table
<pointer_hash
<tree_node
> > statements
;
2075 statements
.create (37);
2076 cp_walk_tree (&t
, verify_stmt_tree_r
, &statements
, NULL
);
2077 statements
.dispose ();
2080 /* Check if the type T depends on a type with no linkage and if so, return
2081 it. If RELAXED_P then do not consider a class type declared within
2082 a vague-linkage function to have no linkage. */
2085 no_linkage_check (tree t
, bool relaxed_p
)
2089 /* There's no point in checking linkage on template functions; we
2090 can't know their complete types. */
2091 if (processing_template_decl
)
2094 switch (TREE_CODE (t
))
2097 if (TYPE_PTRMEMFUNC_P (t
))
2099 /* Lambda types that don't have mangling scope have no linkage. We
2100 check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
2101 when we get here from pushtag none of the lambda information is
2102 set up yet, so we want to assume that the lambda has linkage and
2103 fix it up later if not. */
2104 if (CLASSTYPE_LAMBDA_EXPR (t
)
2105 && CLASSTYPE_LAMBDA_EXPR (t
) != error_mark_node
2106 && LAMBDA_TYPE_EXTRA_SCOPE (t
) == NULL_TREE
)
2110 if (!CLASS_TYPE_P (t
))
2114 /* Only treat anonymous types as having no linkage if they're at
2115 namespace scope. This is core issue 966. */
2116 if (TYPE_ANONYMOUS_P (t
) && TYPE_NAMESPACE_SCOPE_P (t
))
2119 for (r
= CP_TYPE_CONTEXT (t
); ; )
2121 /* If we're a nested type of a !TREE_PUBLIC class, we might not
2122 have linkage, or we might just be in an anonymous namespace.
2123 If we're in a TREE_PUBLIC class, we have linkage. */
2124 if (TYPE_P (r
) && !TREE_PUBLIC (TYPE_NAME (r
)))
2125 return no_linkage_check (TYPE_CONTEXT (t
), relaxed_p
);
2126 else if (TREE_CODE (r
) == FUNCTION_DECL
)
2128 if (!relaxed_p
|| !vague_linkage_p (r
))
2131 r
= CP_DECL_CONTEXT (r
);
2141 case REFERENCE_TYPE
:
2142 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
2146 r
= no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t
),
2150 return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t
), relaxed_p
);
2153 r
= no_linkage_check (TYPE_METHOD_BASETYPE (t
), relaxed_p
);
2160 for (parm
= TYPE_ARG_TYPES (t
);
2161 parm
&& parm
!= void_list_node
;
2162 parm
= TREE_CHAIN (parm
))
2164 r
= no_linkage_check (TREE_VALUE (parm
), relaxed_p
);
2168 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
2176 extern int depth_reached
;
2179 cxx_print_statistics (void)
2181 print_search_statistics ();
2182 print_class_statistics ();
2183 print_template_statistics ();
2184 if (GATHER_STATISTICS
)
2185 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
2189 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2190 (which is an ARRAY_TYPE). This counts only elements of the top
2194 array_type_nelts_top (tree type
)
2196 return fold_build2_loc (input_location
,
2197 PLUS_EXPR
, sizetype
,
2198 array_type_nelts (type
),
2202 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2203 (which is an ARRAY_TYPE). This one is a recursive count of all
2204 ARRAY_TYPEs that are clumped together. */
2207 array_type_nelts_total (tree type
)
2209 tree sz
= array_type_nelts_top (type
);
2210 type
= TREE_TYPE (type
);
2211 while (TREE_CODE (type
) == ARRAY_TYPE
)
2213 tree n
= array_type_nelts_top (type
);
2214 sz
= fold_build2_loc (input_location
,
2215 MULT_EXPR
, sizetype
, sz
, n
);
2216 type
= TREE_TYPE (type
);
2221 /* Called from break_out_target_exprs via mapcar. */
2224 bot_manip (tree
* tp
, int* walk_subtrees
, void* data
)
2226 splay_tree target_remap
= ((splay_tree
) data
);
2229 if (!TYPE_P (t
) && TREE_CONSTANT (t
) && !TREE_SIDE_EFFECTS (t
))
2231 /* There can't be any TARGET_EXPRs or their slot variables below this
2232 point. But we must make a copy, in case subsequent processing
2233 alters any part of it. For example, during gimplification a cast
2234 of the form (T) &X::f (where "f" is a member function) will lead
2235 to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
2237 *tp
= unshare_expr (t
);
2240 if (TREE_CODE (t
) == TARGET_EXPR
)
2244 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
2246 u
= build_cplus_new (TREE_TYPE (t
), TREE_OPERAND (t
, 1),
2247 tf_warning_or_error
);
2248 if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t
, 1)))
2249 AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u
, 1)) = true;
2252 u
= build_target_expr_with_type (TREE_OPERAND (t
, 1), TREE_TYPE (t
),
2253 tf_warning_or_error
);
2255 TARGET_EXPR_IMPLICIT_P (u
) = TARGET_EXPR_IMPLICIT_P (t
);
2256 TARGET_EXPR_LIST_INIT_P (u
) = TARGET_EXPR_LIST_INIT_P (t
);
2257 TARGET_EXPR_DIRECT_INIT_P (u
) = TARGET_EXPR_DIRECT_INIT_P (t
);
2259 /* Map the old variable to the new one. */
2260 splay_tree_insert (target_remap
,
2261 (splay_tree_key
) TREE_OPERAND (t
, 0),
2262 (splay_tree_value
) TREE_OPERAND (u
, 0));
2264 TREE_OPERAND (u
, 1) = break_out_target_exprs (TREE_OPERAND (u
, 1));
2266 /* Replace the old expression with the new version. */
2268 /* We don't have to go below this point; the recursive call to
2269 break_out_target_exprs will have handled anything below this
2275 /* Make a copy of this node. */
2276 t
= copy_tree_r (tp
, walk_subtrees
, NULL
);
2277 if (TREE_CODE (*tp
) == CALL_EXPR
)
2278 set_flags_from_callee (*tp
);
2282 /* Replace all remapped VAR_DECLs in T with their new equivalents.
2283 DATA is really a splay-tree mapping old variables to new
2287 bot_replace (tree
* t
, int* /*walk_subtrees*/, void* data
)
2289 splay_tree target_remap
= ((splay_tree
) data
);
2293 splay_tree_node n
= splay_tree_lookup (target_remap
,
2294 (splay_tree_key
) *t
);
2296 *t
= (tree
) n
->value
;
2298 else if (TREE_CODE (*t
) == PARM_DECL
2299 && DECL_NAME (*t
) == this_identifier
)
2301 /* In an NSDMI we need to replace the 'this' parameter we used for
2302 parsing with the real one for this function. */
2303 *t
= current_class_ptr
;
2305 else if (TREE_CODE (*t
) == CONVERT_EXPR
2306 && CONVERT_EXPR_VBASE_PATH (*t
))
2308 /* In an NSDMI build_base_path defers building conversions to virtual
2309 bases, and we handle it here. */
2310 tree basetype
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (*t
)));
2311 vec
<tree
, va_gc
> *vbases
= CLASSTYPE_VBASECLASSES (current_class_type
);
2313 FOR_EACH_VEC_SAFE_ELT (vbases
, i
, binfo
)
2314 if (BINFO_TYPE (binfo
) == basetype
)
2316 *t
= build_base_path (PLUS_EXPR
, TREE_OPERAND (*t
, 0), binfo
, true,
2317 tf_warning_or_error
);
2323 /* When we parse a default argument expression, we may create
2324 temporary variables via TARGET_EXPRs. When we actually use the
2325 default-argument expression, we make a copy of the expression
2326 and replace the temporaries with appropriate local versions. */
2329 break_out_target_exprs (tree t
)
2331 static int target_remap_count
;
2332 static splay_tree target_remap
;
2334 if (!target_remap_count
++)
2335 target_remap
= splay_tree_new (splay_tree_compare_pointers
,
2336 /*splay_tree_delete_key_fn=*/NULL
,
2337 /*splay_tree_delete_value_fn=*/NULL
);
2338 cp_walk_tree (&t
, bot_manip
, target_remap
, NULL
);
2339 cp_walk_tree (&t
, bot_replace
, target_remap
, NULL
);
2341 if (!--target_remap_count
)
2343 splay_tree_delete (target_remap
);
2344 target_remap
= NULL
;
2350 /* Similar to `build_nt', but for template definitions of dependent
2354 build_min_nt_loc (location_t loc
, enum tree_code code
, ...)
2361 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2365 t
= make_node (code
);
2366 SET_EXPR_LOCATION (t
, loc
);
2367 length
= TREE_CODE_LENGTH (code
);
2369 for (i
= 0; i
< length
; i
++)
2371 tree x
= va_arg (p
, tree
);
2372 TREE_OPERAND (t
, i
) = x
;
2380 /* Similar to `build', but for template definitions. */
2383 build_min (enum tree_code code
, tree tt
, ...)
2390 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2394 t
= make_node (code
);
2395 length
= TREE_CODE_LENGTH (code
);
2398 for (i
= 0; i
< length
; i
++)
2400 tree x
= va_arg (p
, tree
);
2401 TREE_OPERAND (t
, i
) = x
;
2402 if (x
&& !TYPE_P (x
) && TREE_SIDE_EFFECTS (x
))
2403 TREE_SIDE_EFFECTS (t
) = 1;
2410 /* Similar to `build', but for template definitions of non-dependent
2411 expressions. NON_DEP is the non-dependent expression that has been
2415 build_min_non_dep (enum tree_code code
, tree non_dep
, ...)
2422 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2424 va_start (p
, non_dep
);
2426 if (REFERENCE_REF_P (non_dep
))
2427 non_dep
= TREE_OPERAND (non_dep
, 0);
2429 t
= make_node (code
);
2430 length
= TREE_CODE_LENGTH (code
);
2431 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
2432 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
2434 for (i
= 0; i
< length
; i
++)
2436 tree x
= va_arg (p
, tree
);
2437 TREE_OPERAND (t
, i
) = x
;
2440 if (code
== COMPOUND_EXPR
&& TREE_CODE (non_dep
) != COMPOUND_EXPR
)
2441 /* This should not be considered a COMPOUND_EXPR, because it
2442 resolves to an overload. */
2443 COMPOUND_EXPR_OVERLOADED (t
) = 1;
2446 return convert_from_reference (t
);
2449 /* Similar to `build_nt_call_vec', but for template definitions of
2450 non-dependent expressions. NON_DEP is the non-dependent expression
2451 that has been built. */
2454 build_min_non_dep_call_vec (tree non_dep
, tree fn
, vec
<tree
, va_gc
> *argvec
)
2456 tree t
= build_nt_call_vec (fn
, argvec
);
2457 if (REFERENCE_REF_P (non_dep
))
2458 non_dep
= TREE_OPERAND (non_dep
, 0);
2459 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
2460 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
2461 return convert_from_reference (t
);
2465 get_type_decl (tree t
)
2467 if (TREE_CODE (t
) == TYPE_DECL
)
2470 return TYPE_STUB_DECL (t
);
2471 gcc_assert (t
== error_mark_node
);
2475 /* Returns the namespace that contains DECL, whether directly or
2479 decl_namespace_context (tree decl
)
2483 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2485 else if (TYPE_P (decl
))
2486 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
2488 decl
= CP_DECL_CONTEXT (decl
);
2492 /* Returns true if decl is within an anonymous namespace, however deeply
2493 nested, or false otherwise. */
2496 decl_anon_ns_mem_p (const_tree decl
)
2500 if (decl
== NULL_TREE
|| decl
== error_mark_node
)
2502 if (TREE_CODE (decl
) == NAMESPACE_DECL
2503 && DECL_NAME (decl
) == NULL_TREE
)
2505 /* Classes and namespaces inside anonymous namespaces have
2506 TREE_PUBLIC == 0, so we can shortcut the search. */
2507 else if (TYPE_P (decl
))
2508 return (TREE_PUBLIC (TYPE_MAIN_DECL (decl
)) == 0);
2509 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2510 return (TREE_PUBLIC (decl
) == 0);
2512 decl
= DECL_CONTEXT (decl
);
2516 /* Subroutine of cp_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
2517 CALL_EXPRS. Return whether they are equivalent. */
2520 called_fns_equal (tree t1
, tree t2
)
2522 /* Core 1321: dependent names are equivalent even if the overload sets
2523 are different. But do compare explicit template arguments. */
2524 tree name1
= dependent_name (t1
);
2525 tree name2
= dependent_name (t2
);
2528 tree targs1
= NULL_TREE
, targs2
= NULL_TREE
;
2533 if (TREE_CODE (t1
) == TEMPLATE_ID_EXPR
)
2534 targs1
= TREE_OPERAND (t1
, 1);
2535 if (TREE_CODE (t2
) == TEMPLATE_ID_EXPR
)
2536 targs2
= TREE_OPERAND (t2
, 1);
2537 return cp_tree_equal (targs1
, targs2
);
2540 return cp_tree_equal (t1
, t2
);
2543 /* Return truthvalue of whether T1 is the same tree structure as T2.
2544 Return 1 if they are the same. Return 0 if they are different. */
2547 cp_tree_equal (tree t1
, tree t2
)
2549 enum tree_code code1
, code2
;
2556 for (code1
= TREE_CODE (t1
);
2557 CONVERT_EXPR_CODE_P (code1
)
2558 || code1
== NON_LVALUE_EXPR
;
2559 code1
= TREE_CODE (t1
))
2560 t1
= TREE_OPERAND (t1
, 0);
2561 for (code2
= TREE_CODE (t2
);
2562 CONVERT_EXPR_CODE_P (code2
)
2563 || code2
== NON_LVALUE_EXPR
;
2564 code2
= TREE_CODE (t2
))
2565 t2
= TREE_OPERAND (t2
, 0);
2567 /* They might have become equal now. */
2577 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
2578 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
2581 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2584 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2585 && !memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2586 TREE_STRING_LENGTH (t1
));
2589 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
),
2590 TREE_FIXED_CST (t2
));
2593 return cp_tree_equal (TREE_REALPART (t1
), TREE_REALPART (t2
))
2594 && cp_tree_equal (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
));
2597 return operand_equal_p (t1
, t2
, OEP_ONLY_CONST
);
2600 /* We need to do this when determining whether or not two
2601 non-type pointer to member function template arguments
2603 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
2604 || CONSTRUCTOR_NELTS (t1
) != CONSTRUCTOR_NELTS (t2
))
2609 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1
), i
, field
, value
)
2611 constructor_elt
*elt2
= CONSTRUCTOR_ELT (t2
, i
);
2612 if (!cp_tree_equal (field
, elt2
->index
)
2613 || !cp_tree_equal (value
, elt2
->value
))
2620 if (!cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
)))
2622 if (!cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
)))
2624 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
2627 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2632 call_expr_arg_iterator iter1
, iter2
;
2633 if (!called_fns_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
)))
2635 for (arg1
= first_call_expr_arg (t1
, &iter1
),
2636 arg2
= first_call_expr_arg (t2
, &iter2
);
2638 arg1
= next_call_expr_arg (&iter1
),
2639 arg2
= next_call_expr_arg (&iter2
))
2640 if (!cp_tree_equal (arg1
, arg2
))
2649 tree o1
= TREE_OPERAND (t1
, 0);
2650 tree o2
= TREE_OPERAND (t2
, 0);
2652 /* Special case: if either target is an unallocated VAR_DECL,
2653 it means that it's going to be unified with whatever the
2654 TARGET_EXPR is really supposed to initialize, so treat it
2655 as being equivalent to anything. */
2656 if (VAR_P (o1
) && DECL_NAME (o1
) == NULL_TREE
2657 && !DECL_RTL_SET_P (o1
))
2659 else if (VAR_P (o2
) && DECL_NAME (o2
) == NULL_TREE
2660 && !DECL_RTL_SET_P (o2
))
2662 else if (!cp_tree_equal (o1
, o2
))
2665 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2668 case WITH_CLEANUP_EXPR
:
2669 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
2671 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
2674 if (TREE_OPERAND (t1
, 1) != TREE_OPERAND (t2
, 1))
2676 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2679 /* For comparing uses of parameters in late-specified return types
2680 with an out-of-class definition of the function, but can also come
2681 up for expressions that involve 'this' in a member function
2684 if (comparing_specializations
)
2685 /* When comparing hash table entries, only an exact match is
2686 good enough; we don't want to replace 'this' with the
2687 version from another function. */
2690 if (same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2692 if (DECL_ARTIFICIAL (t1
) ^ DECL_ARTIFICIAL (t2
))
2694 if (DECL_ARTIFICIAL (t1
)
2695 || (DECL_PARM_LEVEL (t1
) == DECL_PARM_LEVEL (t2
)
2696 && DECL_PARM_INDEX (t1
) == DECL_PARM_INDEX (t2
)))
2706 case IDENTIFIER_NODE
:
2711 return (BASELINK_BINFO (t1
) == BASELINK_BINFO (t2
)
2712 && BASELINK_ACCESS_BINFO (t1
) == BASELINK_ACCESS_BINFO (t2
)
2713 && BASELINK_QUALIFIED_P (t1
) == BASELINK_QUALIFIED_P (t2
)
2714 && cp_tree_equal (BASELINK_FUNCTIONS (t1
),
2715 BASELINK_FUNCTIONS (t2
)));
2717 case TEMPLATE_PARM_INDEX
:
2718 return (TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
2719 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
)
2720 && (TEMPLATE_PARM_PARAMETER_PACK (t1
)
2721 == TEMPLATE_PARM_PARAMETER_PACK (t2
))
2722 && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1
)),
2723 TREE_TYPE (TEMPLATE_PARM_DECL (t2
))));
2725 case TEMPLATE_ID_EXPR
:
2726 return (cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2727 && cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2732 if (TREE_VEC_LENGTH (t1
) != TREE_VEC_LENGTH (t2
))
2734 for (ix
= TREE_VEC_LENGTH (t1
); ix
--;)
2735 if (!cp_tree_equal (TREE_VEC_ELT (t1
, ix
),
2736 TREE_VEC_ELT (t2
, ix
)))
2744 tree o1
= TREE_OPERAND (t1
, 0);
2745 tree o2
= TREE_OPERAND (t2
, 0);
2747 if (code1
== SIZEOF_EXPR
)
2749 if (SIZEOF_EXPR_TYPE_P (t1
))
2750 o1
= TREE_TYPE (o1
);
2751 if (SIZEOF_EXPR_TYPE_P (t2
))
2752 o2
= TREE_TYPE (o2
);
2754 if (TREE_CODE (o1
) != TREE_CODE (o2
))
2757 return same_type_p (o1
, o2
);
2759 return cp_tree_equal (o1
, o2
);
2764 tree t1_op1
, t2_op1
;
2766 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
2769 t1_op1
= TREE_OPERAND (t1
, 1);
2770 t2_op1
= TREE_OPERAND (t2
, 1);
2771 if (TREE_CODE (t1_op1
) != TREE_CODE (t2_op1
))
2774 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t2
, 2));
2778 /* Two pointer-to-members are the same if they point to the same
2779 field or function in the same class. */
2780 if (PTRMEM_CST_MEMBER (t1
) != PTRMEM_CST_MEMBER (t2
))
2783 return same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
));
2786 if (OVL_FUNCTION (t1
) != OVL_FUNCTION (t2
))
2788 return cp_tree_equal (OVL_CHAIN (t1
), OVL_CHAIN (t2
));
2791 if (TRAIT_EXPR_KIND (t1
) != TRAIT_EXPR_KIND (t2
))
2793 return same_type_p (TRAIT_EXPR_TYPE1 (t1
), TRAIT_EXPR_TYPE1 (t2
))
2794 && same_type_p (TRAIT_EXPR_TYPE2 (t1
), TRAIT_EXPR_TYPE2 (t2
));
2797 case STATIC_CAST_EXPR
:
2798 case REINTERPRET_CAST_EXPR
:
2799 case CONST_CAST_EXPR
:
2800 case DYNAMIC_CAST_EXPR
:
2801 case IMPLICIT_CONV_EXPR
:
2803 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2805 /* Now compare operands as usual. */
2808 case DEFERRED_NOEXCEPT
:
2809 return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1
),
2810 DEFERRED_NOEXCEPT_PATTERN (t2
))
2811 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1
),
2812 DEFERRED_NOEXCEPT_ARGS (t2
)));
2819 switch (TREE_CODE_CLASS (code1
))
2823 case tcc_comparison
:
2824 case tcc_expression
:
2831 n
= cp_tree_operand_length (t1
);
2832 if (TREE_CODE_CLASS (code1
) == tcc_vl_exp
2833 && n
!= TREE_OPERAND_LENGTH (t2
))
2836 for (i
= 0; i
< n
; ++i
)
2837 if (!cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
)))
2844 return same_type_p (t1
, t2
);
2848 /* We can get here with --disable-checking. */
2852 /* The type of ARG when used as an lvalue. */
2855 lvalue_type (tree arg
)
2857 tree type
= TREE_TYPE (arg
);
2861 /* The type of ARG for printing error messages; denote lvalues with
2865 error_type (tree arg
)
2867 tree type
= TREE_TYPE (arg
);
2869 if (TREE_CODE (type
) == ARRAY_TYPE
)
2871 else if (TREE_CODE (type
) == ERROR_MARK
)
2873 else if (real_lvalue_p (arg
))
2874 type
= build_reference_type (lvalue_type (arg
));
2875 else if (MAYBE_CLASS_TYPE_P (type
))
2876 type
= lvalue_type (arg
);
2881 /* Does FUNCTION use a variable-length argument list? */
2884 varargs_function_p (const_tree function
)
2886 return stdarg_p (TREE_TYPE (function
));
2889 /* Returns 1 if decl is a member of a class. */
2892 member_p (const_tree decl
)
2894 const_tree
const ctx
= DECL_CONTEXT (decl
);
2895 return (ctx
&& TYPE_P (ctx
));
2898 /* Create a placeholder for member access where we don't actually have an
2899 object that the access is against. */
2902 build_dummy_object (tree type
)
2904 tree decl
= build1 (NOP_EXPR
, build_pointer_type (type
), void_zero_node
);
2905 return cp_build_indirect_ref (decl
, RO_NULL
, tf_warning_or_error
);
2908 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2909 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2910 binfo path from current_class_type to TYPE, or 0. */
2913 maybe_dummy_object (tree type
, tree
* binfop
)
2917 tree current
= current_nonlambda_class_type ();
2920 && (binfo
= lookup_base (current
, type
, ba_any
, NULL
,
2921 tf_warning_or_error
)))
2925 /* Reference from a nested class member function. */
2927 binfo
= TYPE_BINFO (type
);
2933 if (current_class_ref
2934 /* current_class_ref might not correspond to current_class_type if
2935 we're in tsubst_default_argument or a lambda-declarator; in either
2936 case, we want to use current_class_ref if it matches CONTEXT. */
2937 && (same_type_ignoring_top_level_qualifiers_p
2938 (TREE_TYPE (current_class_ref
), context
)))
2939 decl
= current_class_ref
;
2941 decl
= build_dummy_object (context
);
2946 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
2949 is_dummy_object (const_tree ob
)
2951 if (INDIRECT_REF_P (ob
))
2952 ob
= TREE_OPERAND (ob
, 0);
2953 return (TREE_CODE (ob
) == NOP_EXPR
2954 && TREE_OPERAND (ob
, 0) == void_zero_node
);
2957 /* Returns 1 iff type T is something we want to treat as a scalar type for
2958 the purpose of deciding whether it is trivial/POD/standard-layout. */
2961 scalarish_type_p (const_tree t
)
2963 if (t
== error_mark_node
)
2966 return (SCALAR_TYPE_P (t
)
2967 || TREE_CODE (t
) == VECTOR_TYPE
);
2970 /* Returns true iff T requires non-trivial default initialization. */
2973 type_has_nontrivial_default_init (const_tree t
)
2975 t
= strip_array_types (CONST_CAST_TREE (t
));
2977 if (CLASS_TYPE_P (t
))
2978 return TYPE_HAS_COMPLEX_DFLT (t
);
2983 /* Returns true iff copying an object of type T (including via move
2984 constructor) is non-trivial. That is, T has no non-trivial copy
2985 constructors and no non-trivial move constructors. */
2988 type_has_nontrivial_copy_init (const_tree t
)
2990 t
= strip_array_types (CONST_CAST_TREE (t
));
2992 if (CLASS_TYPE_P (t
))
2994 gcc_assert (COMPLETE_TYPE_P (t
));
2995 return ((TYPE_HAS_COPY_CTOR (t
)
2996 && TYPE_HAS_COMPLEX_COPY_CTOR (t
))
2997 || TYPE_HAS_COMPLEX_MOVE_CTOR (t
));
3003 /* Returns 1 iff type T is a trivially copyable type, as defined in
3004 [basic.types] and [class]. */
3007 trivially_copyable_p (const_tree t
)
3009 t
= strip_array_types (CONST_CAST_TREE (t
));
3011 if (CLASS_TYPE_P (t
))
3012 return ((!TYPE_HAS_COPY_CTOR (t
)
3013 || !TYPE_HAS_COMPLEX_COPY_CTOR (t
))
3014 && !TYPE_HAS_COMPLEX_MOVE_CTOR (t
)
3015 && (!TYPE_HAS_COPY_ASSIGN (t
)
3016 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t
))
3017 && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t
)
3018 && TYPE_HAS_TRIVIAL_DESTRUCTOR (t
));
3020 return scalarish_type_p (t
);
3023 /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
3027 trivial_type_p (const_tree t
)
3029 t
= strip_array_types (CONST_CAST_TREE (t
));
3031 if (CLASS_TYPE_P (t
))
3032 return (TYPE_HAS_TRIVIAL_DFLT (t
)
3033 && trivially_copyable_p (t
));
3035 return scalarish_type_p (t
);
3038 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
3041 pod_type_p (const_tree t
)
3043 /* This CONST_CAST is okay because strip_array_types returns its
3044 argument unmodified and we assign it to a const_tree. */
3045 t
= strip_array_types (CONST_CAST_TREE(t
));
3047 if (!CLASS_TYPE_P (t
))
3048 return scalarish_type_p (t
);
3049 else if (cxx_dialect
> cxx98
)
3050 /* [class]/10: A POD struct is a class that is both a trivial class and a
3051 standard-layout class, and has no non-static data members of type
3052 non-POD struct, non-POD union (or array of such types).
3054 We don't need to check individual members because if a member is
3055 non-std-layout or non-trivial, the class will be too. */
3056 return (std_layout_type_p (t
) && trivial_type_p (t
));
3058 /* The C++98 definition of POD is different. */
3059 return !CLASSTYPE_NON_LAYOUT_POD_P (t
);
3062 /* Returns true iff T is POD for the purpose of layout, as defined in the
3066 layout_pod_type_p (const_tree t
)
3068 t
= strip_array_types (CONST_CAST_TREE (t
));
3070 if (CLASS_TYPE_P (t
))
3071 return !CLASSTYPE_NON_LAYOUT_POD_P (t
);
3073 return scalarish_type_p (t
);
3076 /* Returns true iff T is a standard-layout type, as defined in
3080 std_layout_type_p (const_tree t
)
3082 t
= strip_array_types (CONST_CAST_TREE (t
));
3084 if (CLASS_TYPE_P (t
))
3085 return !CLASSTYPE_NON_STD_LAYOUT (t
);
3087 return scalarish_type_p (t
);
3090 /* Nonzero iff type T is a class template implicit specialization. */
3093 class_tmpl_impl_spec_p (const_tree t
)
3095 return CLASS_TYPE_P (t
) && CLASSTYPE_TEMPLATE_INSTANTIATION (t
);
3098 /* Returns 1 iff zero initialization of type T means actually storing
3102 zero_init_p (const_tree t
)
3104 /* This CONST_CAST is okay because strip_array_types returns its
3105 argument unmodified and we assign it to a const_tree. */
3106 t
= strip_array_types (CONST_CAST_TREE(t
));
3108 if (t
== error_mark_node
)
3111 /* NULL pointers to data members are initialized with -1. */
3112 if (TYPE_PTRDATAMEM_P (t
))
3115 /* Classes that contain types that can't be zero-initialized, cannot
3116 be zero-initialized themselves. */
3117 if (CLASS_TYPE_P (t
) && CLASSTYPE_NON_ZERO_INIT_P (t
))
3123 /* Table of valid C++ attributes. */
3124 const struct attribute_spec cxx_attribute_table
[] =
3126 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3127 affects_type_identity } */
3128 { "java_interface", 0, 0, false, false, false,
3129 handle_java_interface_attribute
, false },
3130 { "com_interface", 0, 0, false, false, false,
3131 handle_com_interface_attribute
, false },
3132 { "init_priority", 1, 1, true, false, false,
3133 handle_init_priority_attribute
, false },
3134 { "abi_tag", 1, -1, false, false, false,
3135 handle_abi_tag_attribute
, true },
3136 { NULL
, 0, 0, false, false, false, NULL
, false }
3139 /* Handle a "java_interface" attribute; arguments as in
3140 struct attribute_spec.handler. */
3142 handle_java_interface_attribute (tree
* node
,
3149 || !CLASS_TYPE_P (*node
)
3150 || !TYPE_FOR_JAVA (*node
))
3152 error ("%qE attribute can only be applied to Java class definitions",
3154 *no_add_attrs
= true;
3157 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
3158 *node
= build_variant_type_copy (*node
);
3159 TYPE_JAVA_INTERFACE (*node
) = 1;
3164 /* Handle a "com_interface" attribute; arguments as in
3165 struct attribute_spec.handler. */
3167 handle_com_interface_attribute (tree
* node
,
3175 *no_add_attrs
= true;
3178 || !CLASS_TYPE_P (*node
)
3179 || *node
!= TYPE_MAIN_VARIANT (*node
))
3181 warning (OPT_Wattributes
, "%qE attribute can only be applied "
3182 "to class definitions", name
);
3187 warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default",
3193 /* Handle an "init_priority" attribute; arguments as in
3194 struct attribute_spec.handler. */
3196 handle_init_priority_attribute (tree
* node
,
3202 tree initp_expr
= TREE_VALUE (args
);
3204 tree type
= TREE_TYPE (decl
);
3207 STRIP_NOPS (initp_expr
);
3209 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
3211 error ("requested init_priority is not an integer constant");
3212 *no_add_attrs
= true;
3216 pri
= TREE_INT_CST_LOW (initp_expr
);
3218 type
= strip_array_types (type
);
3220 if (decl
== NULL_TREE
3222 || !TREE_STATIC (decl
)
3223 || DECL_EXTERNAL (decl
)
3224 || (TREE_CODE (type
) != RECORD_TYPE
3225 && TREE_CODE (type
) != UNION_TYPE
)
3226 /* Static objects in functions are initialized the
3227 first time control passes through that
3228 function. This is not precise enough to pin down an
3229 init_priority value, so don't allow it. */
3230 || current_function_decl
)
3232 error ("can only use %qE attribute on file-scope definitions "
3233 "of objects of class type", name
);
3234 *no_add_attrs
= true;
3238 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
3240 error ("requested init_priority is out of range");
3241 *no_add_attrs
= true;
3245 /* Check for init_priorities that are reserved for
3246 language and runtime support implementations.*/
3247 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
3250 (0, "requested init_priority is reserved for internal use");
3253 if (SUPPORTS_INIT_PRIORITY
)
3255 SET_DECL_INIT_PRIORITY (decl
, pri
);
3256 DECL_HAS_INIT_PRIORITY_P (decl
) = 1;
3261 error ("%qE attribute is not supported on this platform", name
);
3262 *no_add_attrs
= true;
3267 /* DECL is being redeclared; the old declaration had the abi tags in OLD,
3268 and the new one has the tags in NEW_. Give an error if there are tags
3269 in NEW_ that weren't in OLD. */
3272 check_abi_tag_redeclaration (const_tree decl
, const_tree old
, const_tree new_
)
3274 if (old
&& TREE_CODE (TREE_VALUE (old
)) == TREE_LIST
)
3275 old
= TREE_VALUE (old
);
3276 if (new_
&& TREE_CODE (TREE_VALUE (new_
)) == TREE_LIST
)
3277 new_
= TREE_VALUE (new_
);
3279 for (const_tree t
= new_
; t
; t
= TREE_CHAIN (t
))
3281 tree str
= TREE_VALUE (t
);
3282 for (const_tree in
= old
; in
; in
= TREE_CHAIN (in
))
3284 tree ostr
= TREE_VALUE (in
);
3285 if (cp_tree_equal (str
, ostr
))
3288 error ("redeclaration of %qD adds abi tag %E", decl
, str
);
3294 inform (DECL_SOURCE_LOCATION (decl
), "previous declaration here");
3300 /* Handle an "abi_tag" attribute; arguments as in
3301 struct attribute_spec.handler. */
3304 handle_abi_tag_attribute (tree
* node
, tree name
, tree args
,
3305 int flags
, bool* no_add_attrs
)
3309 if (!TAGGED_TYPE_P (*node
))
3311 error ("%qE attribute applied to non-class, non-enum type %qT",
3315 else if (!(flags
& (int)ATTR_FLAG_TYPE_IN_PLACE
))
3317 error ("%qE attribute applied to %qT after its definition",
3322 tree attributes
= TYPE_ATTRIBUTES (*node
);
3323 tree decl
= TYPE_NAME (*node
);
3325 /* Make sure all declarations have the same abi tags. */
3326 if (DECL_SOURCE_LOCATION (decl
) != input_location
)
3328 if (!check_abi_tag_redeclaration (decl
,
3329 lookup_attribute ("abi_tag",
3337 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3339 error ("%qE attribute applied to non-function %qD", name
, *node
);
3342 else if (DECL_LANGUAGE (*node
) == lang_c
)
3344 error ("%qE attribute applied to extern \"C\" function %qD",
3353 *no_add_attrs
= true;
3357 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
3358 thing pointed to by the constant. */
3361 make_ptrmem_cst (tree type
, tree member
)
3363 tree ptrmem_cst
= make_node (PTRMEM_CST
);
3364 TREE_TYPE (ptrmem_cst
) = type
;
3365 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
3369 /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
3370 return an existing type if an appropriate type already exists. */
3373 cp_build_type_attribute_variant (tree type
, tree attributes
)
3377 new_type
= build_type_attribute_variant (type
, attributes
);
3378 if (TREE_CODE (new_type
) == FUNCTION_TYPE
3379 || TREE_CODE (new_type
) == METHOD_TYPE
)
3381 new_type
= build_exception_variant (new_type
,
3382 TYPE_RAISES_EXCEPTIONS (type
));
3383 new_type
= build_ref_qualified_type (new_type
,
3384 type_memfn_rqual (type
));
3387 /* Making a new main variant of a class type is broken. */
3388 gcc_assert (!CLASS_TYPE_P (type
) || new_type
== type
);
3393 /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
3394 Called only after doing all language independent checks. Only
3395 to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already
3396 compared in type_hash_eq. */
3399 cxx_type_hash_eq (const_tree typea
, const_tree typeb
)
3401 gcc_assert (TREE_CODE (typea
) == FUNCTION_TYPE
3402 || TREE_CODE (typea
) == METHOD_TYPE
);
3404 return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea
),
3405 TYPE_RAISES_EXCEPTIONS (typeb
), ce_exact
);
3408 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
3409 traversal. Called from walk_tree. */
3412 cp_walk_subtrees (tree
*tp
, int *walk_subtrees_p
, walk_tree_fn func
,
3413 void *data
, struct pointer_set_t
*pset
)
3415 enum tree_code code
= TREE_CODE (*tp
);
3418 #define WALK_SUBTREE(NODE) \
3421 result = cp_walk_tree (&(NODE), func, data, pset); \
3422 if (result) goto out; \
3426 /* Not one of the easy cases. We must explicitly go through the
3432 case TEMPLATE_TEMPLATE_PARM
:
3433 case BOUND_TEMPLATE_TEMPLATE_PARM
:
3434 case UNBOUND_CLASS_TEMPLATE
:
3435 case TEMPLATE_PARM_INDEX
:
3436 case TEMPLATE_TYPE_PARM
:
3439 case UNDERLYING_TYPE
:
3440 /* None of these have subtrees other than those already walked
3442 *walk_subtrees_p
= 0;
3446 WALK_SUBTREE (BASELINK_FUNCTIONS (*tp
));
3447 *walk_subtrees_p
= 0;
3451 WALK_SUBTREE (TREE_TYPE (*tp
));
3452 *walk_subtrees_p
= 0;
3456 WALK_SUBTREE (TREE_PURPOSE (*tp
));
3460 WALK_SUBTREE (OVL_FUNCTION (*tp
));
3461 WALK_SUBTREE (OVL_CHAIN (*tp
));
3462 *walk_subtrees_p
= 0;
3466 WALK_SUBTREE (DECL_NAME (*tp
));
3467 WALK_SUBTREE (USING_DECL_SCOPE (*tp
));
3468 WALK_SUBTREE (USING_DECL_DECLS (*tp
));
3469 *walk_subtrees_p
= 0;
3473 if (TYPE_PTRMEMFUNC_P (*tp
))
3474 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp
));
3477 case TYPE_ARGUMENT_PACK
:
3478 case NONTYPE_ARGUMENT_PACK
:
3480 tree args
= ARGUMENT_PACK_ARGS (*tp
);
3481 int i
, len
= TREE_VEC_LENGTH (args
);
3482 for (i
= 0; i
< len
; i
++)
3483 WALK_SUBTREE (TREE_VEC_ELT (args
, i
));
3487 case TYPE_PACK_EXPANSION
:
3488 WALK_SUBTREE (TREE_TYPE (*tp
));
3489 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp
));
3490 *walk_subtrees_p
= 0;
3493 case EXPR_PACK_EXPANSION
:
3494 WALK_SUBTREE (TREE_OPERAND (*tp
, 0));
3495 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp
));
3496 *walk_subtrees_p
= 0;
3500 case REINTERPRET_CAST_EXPR
:
3501 case STATIC_CAST_EXPR
:
3502 case CONST_CAST_EXPR
:
3503 case DYNAMIC_CAST_EXPR
:
3504 case IMPLICIT_CONV_EXPR
:
3505 if (TREE_TYPE (*tp
))
3506 WALK_SUBTREE (TREE_TYPE (*tp
));
3510 for (i
= 0; i
< TREE_CODE_LENGTH (TREE_CODE (*tp
)); ++i
)
3511 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
3513 *walk_subtrees_p
= 0;
3517 WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp
));
3518 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp
));
3519 *walk_subtrees_p
= 0;
3523 WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp
));
3524 *walk_subtrees_p
= 0;
3532 /* We didn't find what we were looking for. */
3539 /* Like save_expr, but for C++. */
3542 cp_save_expr (tree expr
)
3544 /* There is no reason to create a SAVE_EXPR within a template; if
3545 needed, we can create the SAVE_EXPR when instantiating the
3546 template. Furthermore, the middle-end cannot handle C++-specific
3548 if (processing_template_decl
)
3550 return save_expr (expr
);
3553 /* Initialize tree.c. */
3558 list_hash_table
= htab_create_ggc (31, list_hash
, list_hash_eq
, NULL
);
3561 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
3562 is. Note that sfk_none is zero, so this function can be used as a
3563 predicate to test whether or not DECL is a special function. */
3565 special_function_kind
3566 special_function_p (const_tree decl
)
3568 /* Rather than doing all this stuff with magic names, we should
3569 probably have a field of type `special_function_kind' in
3570 DECL_LANG_SPECIFIC. */
3571 if (DECL_INHERITED_CTOR_BASE (decl
))
3572 return sfk_inheriting_constructor
;
3573 if (DECL_COPY_CONSTRUCTOR_P (decl
))
3574 return sfk_copy_constructor
;
3575 if (DECL_MOVE_CONSTRUCTOR_P (decl
))
3576 return sfk_move_constructor
;
3577 if (DECL_CONSTRUCTOR_P (decl
))
3578 return sfk_constructor
;
3579 if (DECL_OVERLOADED_OPERATOR_P (decl
) == NOP_EXPR
)
3581 if (copy_fn_p (decl
))
3582 return sfk_copy_assignment
;
3583 if (move_fn_p (decl
))
3584 return sfk_move_assignment
;
3586 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
))
3587 return sfk_destructor
;
3588 if (DECL_COMPLETE_DESTRUCTOR_P (decl
))
3589 return sfk_complete_destructor
;
3590 if (DECL_BASE_DESTRUCTOR_P (decl
))
3591 return sfk_base_destructor
;
3592 if (DECL_DELETING_DESTRUCTOR_P (decl
))
3593 return sfk_deleting_destructor
;
3594 if (DECL_CONV_FN_P (decl
))
3595 return sfk_conversion
;
3600 /* Returns nonzero if TYPE is a character type, including wchar_t. */
3603 char_type_p (tree type
)
3605 return (same_type_p (type
, char_type_node
)
3606 || same_type_p (type
, unsigned_char_type_node
)
3607 || same_type_p (type
, signed_char_type_node
)
3608 || same_type_p (type
, char16_type_node
)
3609 || same_type_p (type
, char32_type_node
)
3610 || same_type_p (type
, wchar_type_node
));
3613 /* Returns the kind of linkage associated with the indicated DECL. Th
3614 value returned is as specified by the language standard; it is
3615 independent of implementation details regarding template
3616 instantiation, etc. For example, it is possible that a declaration
3617 to which this function assigns external linkage would not show up
3618 as a global symbol when you run `nm' on the resulting object file. */
3621 decl_linkage (tree decl
)
3623 /* This function doesn't attempt to calculate the linkage from first
3624 principles as given in [basic.link]. Instead, it makes use of
3625 the fact that we have already set TREE_PUBLIC appropriately, and
3626 then handles a few special cases. Ideally, we would calculate
3627 linkage first, and then transform that into a concrete
3630 /* Things that don't have names have no linkage. */
3631 if (!DECL_NAME (decl
))
3634 /* Fields have no linkage. */
3635 if (TREE_CODE (decl
) == FIELD_DECL
)
3638 /* Things that are TREE_PUBLIC have external linkage. */
3639 if (TREE_PUBLIC (decl
))
3642 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3645 /* Linkage of a CONST_DECL depends on the linkage of the enumeration
3647 if (TREE_CODE (decl
) == CONST_DECL
)
3648 return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl
)));
3650 /* Some things that are not TREE_PUBLIC have external linkage, too.
3651 For example, on targets that don't have weak symbols, we make all
3652 template instantiations have internal linkage (in the object
3653 file), but the symbols should still be treated as having external
3654 linkage from the point of view of the language. */
3655 if (VAR_OR_FUNCTION_DECL_P (decl
)
3656 && DECL_COMDAT (decl
))
3659 /* Things in local scope do not have linkage, if they don't have
3661 if (decl_function_context (decl
))
3664 /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
3665 are considered to have external linkage for language purposes. DECLs
3666 really meant to have internal linkage have DECL_THIS_STATIC set. */
3667 if (TREE_CODE (decl
) == TYPE_DECL
)
3669 if (VAR_OR_FUNCTION_DECL_P (decl
))
3671 if (!DECL_THIS_STATIC (decl
))
3674 /* Static data members and static member functions from classes
3675 in anonymous namespace also don't have TREE_PUBLIC set. */
3676 if (DECL_CLASS_CONTEXT (decl
))
3680 /* Everything else has internal linkage. */
3684 /* Returns the storage duration of the object or reference associated with
3685 the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
3688 decl_storage_duration (tree decl
)
3690 if (TREE_CODE (decl
) == PARM_DECL
)
3692 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3694 gcc_assert (VAR_P (decl
));
3695 if (!TREE_STATIC (decl
)
3696 && !DECL_EXTERNAL (decl
))
3698 if (DECL_THREAD_LOCAL_P (decl
))
3703 /* EXP is an expression that we want to pre-evaluate. Returns (in
3704 *INITP) an expression that will perform the pre-evaluation. The
3705 value returned by this function is a side-effect free expression
3706 equivalent to the pre-evaluated expression. Callers must ensure
3707 that *INITP is evaluated before EXP. */
3710 stabilize_expr (tree exp
, tree
* initp
)
3714 if (!TREE_SIDE_EFFECTS (exp
))
3715 init_expr
= NULL_TREE
;
3716 else if (VOID_TYPE_P (TREE_TYPE (exp
)))
3719 exp
= void_zero_node
;
3721 /* There are no expressions with REFERENCE_TYPE, but there can be call
3722 arguments with such a type; just treat it as a pointer. */
3723 else if (TREE_CODE (TREE_TYPE (exp
)) == REFERENCE_TYPE
3724 || SCALAR_TYPE_P (TREE_TYPE (exp
))
3725 || !lvalue_or_rvalue_with_address_p (exp
))
3727 init_expr
= get_target_expr (exp
);
3728 exp
= TARGET_EXPR_SLOT (init_expr
);
3732 bool xval
= !real_lvalue_p (exp
);
3733 exp
= cp_build_addr_expr (exp
, tf_warning_or_error
);
3734 init_expr
= get_target_expr (exp
);
3735 exp
= TARGET_EXPR_SLOT (init_expr
);
3736 exp
= cp_build_indirect_ref (exp
, RO_NULL
, tf_warning_or_error
);
3742 gcc_assert (!TREE_SIDE_EFFECTS (exp
));
3746 /* Add NEW_EXPR, an expression whose value we don't care about, after the
3747 similar expression ORIG. */
3750 add_stmt_to_compound (tree orig
, tree new_expr
)
3752 if (!new_expr
|| !TREE_SIDE_EFFECTS (new_expr
))
3754 if (!orig
|| !TREE_SIDE_EFFECTS (orig
))
3756 return build2 (COMPOUND_EXPR
, void_type_node
, orig
, new_expr
);
3759 /* Like stabilize_expr, but for a call whose arguments we want to
3760 pre-evaluate. CALL is modified in place to use the pre-evaluated
3761 arguments, while, upon return, *INITP contains an expression to
3762 compute the arguments. */
3765 stabilize_call (tree call
, tree
*initp
)
3767 tree inits
= NULL_TREE
;
3769 int nargs
= call_expr_nargs (call
);
3771 if (call
== error_mark_node
|| processing_template_decl
)
3777 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
3779 for (i
= 0; i
< nargs
; i
++)
3782 CALL_EXPR_ARG (call
, i
) =
3783 stabilize_expr (CALL_EXPR_ARG (call
, i
), &init
);
3784 inits
= add_stmt_to_compound (inits
, init
);
3790 /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
3791 to pre-evaluate. CALL is modified in place to use the pre-evaluated
3792 arguments, while, upon return, *INITP contains an expression to
3793 compute the arguments. */
3796 stabilize_aggr_init (tree call
, tree
*initp
)
3798 tree inits
= NULL_TREE
;
3800 int nargs
= aggr_init_expr_nargs (call
);
3802 if (call
== error_mark_node
)
3805 gcc_assert (TREE_CODE (call
) == AGGR_INIT_EXPR
);
3807 for (i
= 0; i
< nargs
; i
++)
3810 AGGR_INIT_EXPR_ARG (call
, i
) =
3811 stabilize_expr (AGGR_INIT_EXPR_ARG (call
, i
), &init
);
3812 inits
= add_stmt_to_compound (inits
, init
);
3818 /* Like stabilize_expr, but for an initialization.
3820 If the initialization is for an object of class type, this function
3821 takes care not to introduce additional temporaries.
3823 Returns TRUE iff the expression was successfully pre-evaluated,
3824 i.e., if INIT is now side-effect free, except for, possibly, a
3825 single call to a constructor. */
3828 stabilize_init (tree init
, tree
*initp
)
3834 if (t
== error_mark_node
|| processing_template_decl
)
3837 if (TREE_CODE (t
) == INIT_EXPR
)
3838 t
= TREE_OPERAND (t
, 1);
3839 if (TREE_CODE (t
) == TARGET_EXPR
)
3840 t
= TARGET_EXPR_INITIAL (t
);
3842 /* If the RHS can be stabilized without breaking copy elision, stabilize
3843 it. We specifically don't stabilize class prvalues here because that
3844 would mean an extra copy, but they might be stabilized below. */
3845 if (TREE_CODE (init
) == INIT_EXPR
3846 && TREE_CODE (t
) != CONSTRUCTOR
3847 && TREE_CODE (t
) != AGGR_INIT_EXPR
3848 && (SCALAR_TYPE_P (TREE_TYPE (t
))
3849 || lvalue_or_rvalue_with_address_p (t
)))
3851 TREE_OPERAND (init
, 1) = stabilize_expr (t
, initp
);
3855 if (TREE_CODE (t
) == COMPOUND_EXPR
3856 && TREE_CODE (init
) == INIT_EXPR
)
3858 tree last
= expr_last (t
);
3859 /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
3860 if (!TREE_SIDE_EFFECTS (last
))
3863 TREE_OPERAND (init
, 1) = last
;
3868 if (TREE_CODE (t
) == CONSTRUCTOR
)
3870 /* Aggregate initialization: stabilize each of the field
3873 constructor_elt
*ce
;
3875 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (t
);
3876 for (i
= 0; vec_safe_iterate (v
, i
, &ce
); ++i
)
3878 tree type
= TREE_TYPE (ce
->value
);
3880 if (TREE_CODE (type
) == REFERENCE_TYPE
3881 || SCALAR_TYPE_P (type
))
3882 ce
->value
= stabilize_expr (ce
->value
, &subinit
);
3883 else if (!stabilize_init (ce
->value
, &subinit
))
3885 *initp
= add_stmt_to_compound (*initp
, subinit
);
3890 if (TREE_CODE (t
) == CALL_EXPR
)
3892 stabilize_call (t
, initp
);
3896 if (TREE_CODE (t
) == AGGR_INIT_EXPR
)
3898 stabilize_aggr_init (t
, initp
);
3902 /* The initialization is being performed via a bitwise copy -- and
3903 the item copied may have side effects. */
3904 return !TREE_SIDE_EFFECTS (init
);
3907 /* Like "fold", but should be used whenever we might be processing the
3908 body of a template. */
3911 fold_if_not_in_template (tree expr
)
3913 /* In the body of a template, there is never any need to call
3914 "fold". We will call fold later when actually instantiating the
3915 template. Integral constant expressions in templates will be
3916 evaluated via fold_non_dependent_expr, as necessary. */
3917 if (processing_template_decl
)
3920 /* Fold C++ front-end specific tree codes. */
3921 if (TREE_CODE (expr
) == UNARY_PLUS_EXPR
)
3922 return fold_convert (TREE_TYPE (expr
), TREE_OPERAND (expr
, 0));
3927 /* Returns true if a cast to TYPE may appear in an integral constant
3931 cast_valid_in_integral_constant_expression_p (tree type
)
3933 return (INTEGRAL_OR_ENUMERATION_TYPE_P (type
)
3934 || cxx_dialect
>= cxx0x
3935 || dependent_type_p (type
)
3936 || type
== error_mark_node
);
3939 /* Return true if we need to fix linkage information of DECL. */
3942 cp_fix_function_decl_p (tree decl
)
3944 /* Skip if DECL is not externally visible. */
3945 if (!TREE_PUBLIC (decl
))
3948 /* We need to fix DECL if it a appears to be exported but with no
3949 function body. Thunks do not have CFGs and we may need to
3950 handle them specially later. */
3951 if (!gimple_has_body_p (decl
)
3952 && !DECL_THUNK_P (decl
)
3953 && !DECL_EXTERNAL (decl
))
3955 struct cgraph_node
*node
= cgraph_get_node (decl
);
3957 /* Don't fix same_body aliases. Although they don't have their own
3958 CFG, they share it with what they alias to. */
3959 if (!node
|| !node
->alias
3960 || !vec_safe_length (node
->symbol
.ref_list
.references
))
3967 /* Clean the C++ specific parts of the tree T. */
3970 cp_free_lang_data (tree t
)
3972 if (TREE_CODE (t
) == METHOD_TYPE
3973 || TREE_CODE (t
) == FUNCTION_TYPE
)
3975 /* Default args are not interesting anymore. */
3976 tree argtypes
= TYPE_ARG_TYPES (t
);
3979 TREE_PURPOSE (argtypes
) = 0;
3980 argtypes
= TREE_CHAIN (argtypes
);
3983 else if (TREE_CODE (t
) == FUNCTION_DECL
3984 && cp_fix_function_decl_p (t
))
3986 /* If T is used in this translation unit at all, the definition
3987 must exist somewhere else since we have decided to not emit it
3988 in this TU. So make it an external reference. */
3989 DECL_EXTERNAL (t
) = 1;
3990 TREE_STATIC (t
) = 0;
3992 if (TREE_CODE (t
) == NAMESPACE_DECL
)
3994 /* The list of users of a namespace isn't useful for the middle-end
3995 or debug generators. */
3996 DECL_NAMESPACE_USERS (t
) = NULL_TREE
;
3997 /* Neither do we need the leftover chaining of namespaces
3998 from the binding level. */
3999 DECL_CHAIN (t
) = NULL_TREE
;
4003 /* Stub for c-common. Please keep in sync with c-decl.c.
4004 FIXME: If address space support is target specific, then this
4005 should be a C target hook. But currently this is not possible,
4006 because this function is called via REGISTER_TARGET_PRAGMAS. */
4008 c_register_addr_space (const char * /*word*/, addr_space_t
/*as*/)
4012 /* Return the number of operands in T that we care about for things like
4016 cp_tree_operand_length (const_tree t
)
4018 enum tree_code code
= TREE_CODE (t
);
4022 case PREINCREMENT_EXPR
:
4023 case PREDECREMENT_EXPR
:
4024 case POSTINCREMENT_EXPR
:
4025 case POSTDECREMENT_EXPR
:
4031 case EXPR_PACK_EXPANSION
:
4035 return TREE_OPERAND_LENGTH (t
);
4039 /* Implement -Wzero_as_null_pointer_constant. Return true if the
4040 conditions for the warning hold, false otherwise. */
4042 maybe_warn_zero_as_null_pointer_constant (tree expr
, location_t loc
)
4044 if (c_inhibit_evaluation_warnings
== 0
4045 && !NULLPTR_TYPE_P (TREE_TYPE (expr
)))
4047 warning_at (loc
, OPT_Wzero_as_null_pointer_constant
,
4048 "zero as null pointer constant");
4054 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4055 /* Complain that some language-specific thing hanging off a tree
4056 node has been accessed improperly. */
4059 lang_check_failed (const char* file
, int line
, const char* function
)
4061 internal_error ("lang_* check: failed in %s, at %s:%d",
4062 function
, trim_filename (file
), line
);
4064 #endif /* ENABLE_TREE_CHECKING */
4066 #include "gt-cp-tree.h"