1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2017 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"
26 #include "gimple-expr.h"
28 #include "stor-layout.h"
29 #include "print-tree.h"
30 #include "tree-iterator.h"
31 #include "tree-inline.h"
37 static tree
bot_manip (tree
*, int *, void *);
38 static tree
bot_replace (tree
*, int *, void *);
39 static hashval_t
list_hash_pieces (tree
, tree
, tree
);
40 static tree
build_target_expr (tree
, tree
, tsubst_flags_t
);
41 static tree
count_trees_r (tree
*, int *, void *);
42 static tree
verify_stmt_tree_r (tree
*, int *, void *);
43 static tree
build_local_temp (tree
);
45 static tree
handle_init_priority_attribute (tree
*, tree
, tree
, int, bool *);
46 static tree
handle_abi_tag_attribute (tree
*, tree
, tree
, int, bool *);
48 /* If REF is an lvalue, returns the kind of lvalue that REF is.
49 Otherwise, returns clk_none. */
52 lvalue_kind (const_tree ref
)
54 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
55 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
57 /* Expressions of reference type are sometimes wrapped in
58 INDIRECT_REFs. INDIRECT_REFs are just internal compiler
59 representation, not part of the language, so we have to look
61 if (REFERENCE_REF_P (ref
))
62 return lvalue_kind (TREE_OPERAND (ref
, 0));
65 && TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
67 /* unnamed rvalue references are rvalues */
68 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref
))
69 && TREE_CODE (ref
) != PARM_DECL
71 && TREE_CODE (ref
) != COMPONENT_REF
72 /* Functions are always lvalues. */
73 && TREE_CODE (TREE_TYPE (TREE_TYPE (ref
))) != FUNCTION_TYPE
)
76 /* lvalue references and named rvalue references are lvalues. */
80 if (ref
== current_class_ptr
)
83 switch (TREE_CODE (ref
))
87 /* preincrements and predecrements are valid lvals, provided
88 what they refer to are valid lvals. */
89 case PREINCREMENT_EXPR
:
90 case PREDECREMENT_EXPR
:
92 case WITH_CLEANUP_EXPR
:
95 return lvalue_kind (TREE_OPERAND (ref
, 0));
99 if (TREE_CODE (ref
) == MEMBER_REF
)
100 op1_lvalue_kind
= clk_ordinary
;
102 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
103 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref
, 1))))
104 op1_lvalue_kind
= clk_none
;
105 return op1_lvalue_kind
;
108 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
109 /* Look at the member designator. */
110 if (!op1_lvalue_kind
)
112 else if (is_overloaded_fn (TREE_OPERAND (ref
, 1)))
113 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
114 situations. If we're seeing a COMPONENT_REF, it's a non-static
115 member, so it isn't an lvalue. */
116 op1_lvalue_kind
= clk_none
;
117 else if (TREE_CODE (TREE_OPERAND (ref
, 1)) != FIELD_DECL
)
118 /* This can be IDENTIFIER_NODE in a template. */;
119 else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
121 /* Clear the ordinary bit. If this object was a class
122 rvalue we want to preserve that information. */
123 op1_lvalue_kind
&= ~clk_ordinary
;
124 /* The lvalue is for a bitfield. */
125 op1_lvalue_kind
|= clk_bitfield
;
127 else if (DECL_PACKED (TREE_OPERAND (ref
, 1)))
128 op1_lvalue_kind
|= clk_packed
;
130 return op1_lvalue_kind
;
133 case COMPOUND_LITERAL_EXPR
:
137 /* CONST_DECL without TREE_STATIC are enumeration values and
138 thus not lvalues. With TREE_STATIC they are used by ObjC++
139 in objc_build_string_object and need to be considered as
141 if (! TREE_STATIC (ref
))
145 if (VAR_P (ref
) && DECL_HAS_VALUE_EXPR_P (ref
))
146 return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref
)));
148 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
149 && DECL_LANG_SPECIFIC (ref
)
150 && DECL_IN_AGGR_P (ref
))
156 case ARRAY_NOTATION_REF
:
159 case PLACEHOLDER_EXPR
:
162 /* A scope ref in a template, left as SCOPE_REF to support later
165 gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref
)));
167 tree op
= TREE_OPERAND (ref
, 1);
168 if (TREE_CODE (op
) == FIELD_DECL
)
169 return (DECL_C_BIT_FIELD (op
) ? clk_bitfield
: clk_ordinary
);
171 return lvalue_kind (op
);
176 /* Disallow <? and >? as lvalues if either argument side-effects. */
177 if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 0))
178 || TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 1)))
180 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
181 op2_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 1));
185 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 1)
186 ? TREE_OPERAND (ref
, 1)
187 : TREE_OPERAND (ref
, 0));
188 op2_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 2));
192 /* We expect to see unlowered MODOP_EXPRs only during
193 template processing. */
194 gcc_assert (processing_template_decl
);
202 return lvalue_kind (TREE_OPERAND (ref
, 1));
208 return (CLASS_TYPE_P (TREE_TYPE (ref
)) ? clk_class
: clk_none
);
211 /* We can see calls outside of TARGET_EXPR in templates. */
212 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
217 /* All functions (except non-static-member functions) are
219 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
220 ? clk_none
: clk_ordinary
);
223 /* We now represent a reference to a single static member function
225 /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
226 its argument unmodified and we assign it to a const_tree. */
227 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref
)));
229 case NON_DEPENDENT_EXPR
:
230 return lvalue_kind (TREE_OPERAND (ref
, 0));
233 if (!TREE_TYPE (ref
))
235 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
240 /* If one operand is not an lvalue at all, then this expression is
242 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
245 /* Otherwise, it's an lvalue, and it has all the odd properties
246 contributed by either operand. */
247 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
248 /* It's not an ordinary lvalue if it involves any other kind. */
249 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
250 op1_lvalue_kind
&= ~clk_ordinary
;
251 /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
252 A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
253 if ((op1_lvalue_kind
& (clk_rvalueref
|clk_class
))
254 && (op1_lvalue_kind
& (clk_bitfield
|clk_packed
)))
255 op1_lvalue_kind
= clk_none
;
256 return op1_lvalue_kind
;
259 /* Returns the kind of lvalue that REF is, in the sense of [basic.lval]. */
262 real_lvalue_p (const_tree ref
)
264 cp_lvalue_kind kind
= lvalue_kind (ref
);
265 if (kind
& (clk_rvalueref
|clk_class
))
271 /* c-common wants us to return bool. */
274 lvalue_p (const_tree t
)
276 return real_lvalue_p (t
);
279 /* This differs from lvalue_p in that xvalues are included. */
282 glvalue_p (const_tree ref
)
284 cp_lvalue_kind kind
= lvalue_kind (ref
);
285 if (kind
& clk_class
)
288 return (kind
!= clk_none
);
291 /* This differs from glvalue_p in that class prvalues are included. */
294 obvalue_p (const_tree ref
)
296 return (lvalue_kind (ref
) != clk_none
);
299 /* Returns true if REF is an xvalue (the result of dereferencing an rvalue
300 reference), false otherwise. */
303 xvalue_p (const_tree ref
)
305 return (lvalue_kind (ref
) == clk_rvalueref
);
308 /* True if REF is a bit-field. */
311 bitfield_p (const_tree ref
)
313 return (lvalue_kind (ref
) & clk_bitfield
);
316 /* C++-specific version of stabilize_reference. */
319 cp_stabilize_reference (tree ref
)
321 switch (TREE_CODE (ref
))
323 /* We need to treat specially anything stabilize_reference doesn't
324 handle specifically. */
335 case ARRAY_RANGE_REF
:
339 cp_lvalue_kind kind
= lvalue_kind (ref
);
340 if ((kind
& ~clk_class
) != clk_none
)
342 tree type
= unlowered_expr_type (ref
);
343 bool rval
= !!(kind
& clk_rvalueref
);
344 type
= cp_build_reference_type (type
, rval
);
345 /* This inhibits warnings in, eg, cxx_mark_addressable
347 warning_sentinel
s (extra_warnings
);
348 ref
= build_static_cast (type
, ref
, tf_error
);
352 return stabilize_reference (ref
);
355 /* Test whether DECL is a builtin that may appear in a
356 constant-expression. */
359 builtin_valid_in_constant_expr_p (const_tree decl
)
361 if (!(TREE_CODE (decl
) == FUNCTION_DECL
362 && DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
))
363 /* Not a built-in. */
365 switch (DECL_FUNCTION_CODE (decl
))
367 /* These always have constant results like the corresponding
370 case BUILT_IN_FUNCTION
:
373 /* The following built-ins are valid in constant expressions
374 when their arguments are. */
375 case BUILT_IN_ADD_OVERFLOW_P
:
376 case BUILT_IN_SUB_OVERFLOW_P
:
377 case BUILT_IN_MUL_OVERFLOW_P
:
379 /* These have constant results even if their operands are
381 case BUILT_IN_CONSTANT_P
:
382 case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE
:
389 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
392 build_target_expr (tree decl
, tree value
, tsubst_flags_t complain
)
395 tree type
= TREE_TYPE (decl
);
397 value
= mark_rvalue_use (value
);
399 gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value
))
400 || TREE_TYPE (decl
) == TREE_TYPE (value
)
401 /* On ARM ctors return 'this'. */
402 || (TYPE_PTR_P (TREE_TYPE (value
))
403 && TREE_CODE (value
) == CALL_EXPR
)
404 || useless_type_conversion_p (TREE_TYPE (decl
),
407 if (complain
& tf_no_cleanup
)
408 /* The caller is building a new-expr and does not need a cleanup. */
412 t
= cxx_maybe_build_cleanup (decl
, complain
);
413 if (t
== error_mark_node
)
414 return error_mark_node
;
416 t
= build4 (TARGET_EXPR
, type
, decl
, value
, t
, NULL_TREE
);
417 if (EXPR_HAS_LOCATION (value
))
418 SET_EXPR_LOCATION (t
, EXPR_LOCATION (value
));
419 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
420 ignore the TARGET_EXPR. If there really turn out to be no
421 side-effects, then the optimizer should be able to get rid of
422 whatever code is generated anyhow. */
423 TREE_SIDE_EFFECTS (t
) = 1;
428 /* Return an undeclared local temporary of type TYPE for use in building a
432 build_local_temp (tree type
)
434 tree slot
= build_decl (input_location
,
435 VAR_DECL
, NULL_TREE
, type
);
436 DECL_ARTIFICIAL (slot
) = 1;
437 DECL_IGNORED_P (slot
) = 1;
438 DECL_CONTEXT (slot
) = current_function_decl
;
439 layout_decl (slot
, 0);
443 /* Set various status flags when building an AGGR_INIT_EXPR object T. */
446 process_aggr_init_operands (tree t
)
450 side_effects
= TREE_SIDE_EFFECTS (t
);
454 n
= TREE_OPERAND_LENGTH (t
);
455 for (i
= 1; i
< n
; i
++)
457 tree op
= TREE_OPERAND (t
, i
);
458 if (op
&& TREE_SIDE_EFFECTS (op
))
465 TREE_SIDE_EFFECTS (t
) = side_effects
;
468 /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
469 FN, and SLOT. NARGS is the number of call arguments which are specified
470 as a tree array ARGS. */
473 build_aggr_init_array (tree return_type
, tree fn
, tree slot
, int nargs
,
479 t
= build_vl_exp (AGGR_INIT_EXPR
, nargs
+ 3);
480 TREE_TYPE (t
) = return_type
;
481 AGGR_INIT_EXPR_FN (t
) = fn
;
482 AGGR_INIT_EXPR_SLOT (t
) = slot
;
483 for (i
= 0; i
< nargs
; i
++)
484 AGGR_INIT_EXPR_ARG (t
, i
) = args
[i
];
485 process_aggr_init_operands (t
);
489 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
490 target. TYPE is the type to be initialized.
492 Build an AGGR_INIT_EXPR to represent the initialization. This function
493 differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
494 to initialize another object, whereas a TARGET_EXPR can either
495 initialize another object or create its own temporary object, and as a
496 result building up a TARGET_EXPR requires that the type's destructor be
500 build_aggr_init_expr (tree type
, tree init
)
507 /* Don't build AGGR_INIT_EXPR in a template. */
508 if (processing_template_decl
)
511 fn
= cp_get_callee (init
);
513 return convert (type
, init
);
515 is_ctor
= (TREE_CODE (fn
) == ADDR_EXPR
516 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
517 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
519 /* We split the CALL_EXPR into its function and its arguments here.
520 Then, in expand_expr, we put them back together. The reason for
521 this is that this expression might be a default argument
522 expression. In that case, we need a new temporary every time the
523 expression is used. That's what break_out_target_exprs does; it
524 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
525 temporary slot. Then, expand_expr builds up a call-expression
526 using the new slot. */
528 /* If we don't need to use a constructor to create an object of this
529 type, don't mess with AGGR_INIT_EXPR. */
530 if (is_ctor
|| TREE_ADDRESSABLE (type
))
532 slot
= build_local_temp (type
);
534 if (TREE_CODE (init
) == CALL_EXPR
)
536 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
537 call_expr_nargs (init
),
538 CALL_EXPR_ARGP (init
));
539 AGGR_INIT_FROM_THUNK_P (rval
)
540 = CALL_FROM_THUNK_P (init
);
544 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
545 aggr_init_expr_nargs (init
),
546 AGGR_INIT_EXPR_ARGP (init
));
547 AGGR_INIT_FROM_THUNK_P (rval
)
548 = AGGR_INIT_FROM_THUNK_P (init
);
550 TREE_SIDE_EFFECTS (rval
) = 1;
551 AGGR_INIT_VIA_CTOR_P (rval
) = is_ctor
;
552 TREE_NOTHROW (rval
) = TREE_NOTHROW (init
);
553 CALL_EXPR_OPERATOR_SYNTAX (rval
) = CALL_EXPR_OPERATOR_SYNTAX (init
);
554 CALL_EXPR_ORDERED_ARGS (rval
) = CALL_EXPR_ORDERED_ARGS (init
);
555 CALL_EXPR_REVERSE_ARGS (rval
) = CALL_EXPR_REVERSE_ARGS (init
);
563 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
564 target. TYPE is the type that this initialization should appear to
567 Build an encapsulation of the initialization to perform
568 and return it so that it can be processed by language-independent
569 and language-specific expression expanders. */
572 build_cplus_new (tree type
, tree init
, tsubst_flags_t complain
)
574 tree rval
= build_aggr_init_expr (type
, init
);
577 if (!complete_type_or_maybe_complain (type
, init
, complain
))
578 return error_mark_node
;
580 /* Make sure that we're not trying to create an instance of an
582 if (abstract_virtuals_error_sfinae (NULL_TREE
, type
, complain
))
583 return error_mark_node
;
585 if (TREE_CODE (rval
) == AGGR_INIT_EXPR
)
586 slot
= AGGR_INIT_EXPR_SLOT (rval
);
587 else if (TREE_CODE (rval
) == CALL_EXPR
588 || TREE_CODE (rval
) == CONSTRUCTOR
)
589 slot
= build_local_temp (type
);
593 rval
= build_target_expr (slot
, rval
, complain
);
595 if (rval
!= error_mark_node
)
596 TARGET_EXPR_IMPLICIT_P (rval
) = 1;
601 /* Subroutine of build_vec_init_expr: Build up a single element
602 intialization as a proxy for the full array initialization to get things
603 marked as used and any appropriate diagnostics.
605 Since we're deferring building the actual constructor calls until
606 gimplification time, we need to build one now and throw it away so
607 that the relevant constructor gets mark_used before cgraph decides
608 what functions are needed. Here we assume that init is either
609 NULL_TREE, void_type_node (indicating value-initialization), or
610 another array to copy. */
613 build_vec_init_elt (tree type
, tree init
, tsubst_flags_t complain
)
615 tree inner_type
= strip_array_types (type
);
616 vec
<tree
, va_gc
> *argvec
;
618 if (integer_zerop (array_type_nelts_total (type
))
619 || !CLASS_TYPE_P (inner_type
))
620 /* No interesting initialization to do. */
621 return integer_zero_node
;
622 else if (init
== void_type_node
)
623 return build_value_init (inner_type
, complain
);
625 gcc_assert (init
== NULL_TREE
626 || (same_type_ignoring_top_level_qualifiers_p
627 (type
, TREE_TYPE (init
))));
629 argvec
= make_tree_vector ();
632 tree init_type
= strip_array_types (TREE_TYPE (init
));
633 tree dummy
= build_dummy_object (init_type
);
634 if (!lvalue_p (init
))
635 dummy
= move (dummy
);
636 argvec
->quick_push (dummy
);
638 init
= build_special_member_call (NULL_TREE
, complete_ctor_identifier
,
639 &argvec
, inner_type
, LOOKUP_NORMAL
,
641 release_tree_vector (argvec
);
643 /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
644 we don't want one here because we aren't creating a temporary. */
645 if (TREE_CODE (init
) == TARGET_EXPR
)
646 init
= TARGET_EXPR_INITIAL (init
);
651 /* Return a TARGET_EXPR which expresses the initialization of an array to
652 be named later, either default-initialization or copy-initialization
653 from another array of the same type. */
656 build_vec_init_expr (tree type
, tree init
, tsubst_flags_t complain
)
659 bool value_init
= false;
660 tree elt_init
= build_vec_init_elt (type
, init
, complain
);
662 if (init
== void_type_node
)
668 slot
= build_local_temp (type
);
669 init
= build2 (VEC_INIT_EXPR
, type
, slot
, init
);
670 TREE_SIDE_EFFECTS (init
) = true;
671 SET_EXPR_LOCATION (init
, input_location
);
673 if (cxx_dialect
>= cxx11
674 && potential_constant_expression (elt_init
))
675 VEC_INIT_EXPR_IS_CONSTEXPR (init
) = true;
676 VEC_INIT_EXPR_VALUE_INIT (init
) = value_init
;
681 /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
682 that requires a constant expression. */
685 diagnose_non_constexpr_vec_init (tree expr
)
687 tree type
= TREE_TYPE (VEC_INIT_EXPR_SLOT (expr
));
689 if (VEC_INIT_EXPR_VALUE_INIT (expr
))
690 init
= void_type_node
;
692 init
= VEC_INIT_EXPR_INIT (expr
);
694 elt_init
= build_vec_init_elt (type
, init
, tf_warning_or_error
);
695 require_potential_constant_expression (elt_init
);
699 build_array_copy (tree init
)
701 return build_vec_init_expr (TREE_TYPE (init
), init
, tf_warning_or_error
);
704 /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
708 build_target_expr_with_type (tree init
, tree type
, tsubst_flags_t complain
)
710 gcc_assert (!VOID_TYPE_P (type
));
712 if (TREE_CODE (init
) == TARGET_EXPR
713 || init
== error_mark_node
)
715 else if (CLASS_TYPE_P (type
) && type_has_nontrivial_copy_init (type
)
716 && !VOID_TYPE_P (TREE_TYPE (init
))
717 && TREE_CODE (init
) != COND_EXPR
718 && TREE_CODE (init
) != CONSTRUCTOR
719 && TREE_CODE (init
) != VA_ARG_EXPR
)
720 /* We need to build up a copy constructor call. A void initializer
721 means we're being called from bot_manip. COND_EXPR is a special
722 case because we already have copies on the arms and we don't want
723 another one here. A CONSTRUCTOR is aggregate initialization, which
724 is handled separately. A VA_ARG_EXPR is magic creation of an
725 aggregate; there's no additional work to be done. */
726 return force_rvalue (init
, complain
);
728 return force_target_expr (type
, init
, complain
);
731 /* Like the above function, but without the checking. This function should
732 only be used by code which is deliberately trying to subvert the type
733 system, such as call_builtin_trap. Or build_over_call, to avoid
734 infinite recursion. */
737 force_target_expr (tree type
, tree init
, tsubst_flags_t complain
)
741 gcc_assert (!VOID_TYPE_P (type
));
743 slot
= build_local_temp (type
);
744 return build_target_expr (slot
, init
, complain
);
747 /* Like build_target_expr_with_type, but use the type of INIT. */
750 get_target_expr_sfinae (tree init
, tsubst_flags_t complain
)
752 if (TREE_CODE (init
) == AGGR_INIT_EXPR
)
753 return build_target_expr (AGGR_INIT_EXPR_SLOT (init
), init
, complain
);
754 else if (TREE_CODE (init
) == VEC_INIT_EXPR
)
755 return build_target_expr (VEC_INIT_EXPR_SLOT (init
), init
, complain
);
758 init
= convert_bitfield_to_declared_type (init
);
759 return build_target_expr_with_type (init
, TREE_TYPE (init
), complain
);
764 get_target_expr (tree init
)
766 return get_target_expr_sfinae (init
, tf_warning_or_error
);
769 /* If EXPR is a bitfield reference, convert it to the declared type of
770 the bitfield, and return the resulting expression. Otherwise,
771 return EXPR itself. */
774 convert_bitfield_to_declared_type (tree expr
)
778 bitfield_type
= is_bitfield_expr_with_lowered_type (expr
);
780 expr
= convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type
),
785 /* EXPR is being used in an rvalue context. Return a version of EXPR
786 that is marked as an rvalue. */
793 if (error_operand_p (expr
))
796 expr
= mark_rvalue_use (expr
);
800 Non-class rvalues always have cv-unqualified types. */
801 type
= TREE_TYPE (expr
);
802 if (!CLASS_TYPE_P (type
) && cv_qualified_p (type
))
803 type
= cv_unqualified (type
);
805 /* We need to do this for rvalue refs as well to get the right answer
806 from decltype; see c++/36628. */
807 if (!processing_template_decl
&& glvalue_p (expr
))
808 expr
= build1 (NON_LVALUE_EXPR
, type
, expr
);
809 else if (type
!= TREE_TYPE (expr
))
810 expr
= build_nop (type
, expr
);
816 struct cplus_array_info
822 struct cplus_array_hasher
: ggc_ptr_hash
<tree_node
>
824 typedef cplus_array_info
*compare_type
;
826 static hashval_t
hash (tree t
);
827 static bool equal (tree
, cplus_array_info
*);
830 /* Hash an ARRAY_TYPE. K is really of type `tree'. */
833 cplus_array_hasher::hash (tree t
)
837 hash
= TYPE_UID (TREE_TYPE (t
));
839 hash
^= TYPE_UID (TYPE_DOMAIN (t
));
843 /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
844 of type `cplus_array_info*'. */
847 cplus_array_hasher::equal (tree t1
, cplus_array_info
*t2
)
849 return (TREE_TYPE (t1
) == t2
->type
&& TYPE_DOMAIN (t1
) == t2
->domain
);
852 /* Hash table containing dependent array types, which are unsuitable for
853 the language-independent type hash table. */
854 static GTY (()) hash_table
<cplus_array_hasher
> *cplus_array_htab
;
856 /* Build an ARRAY_TYPE without laying it out. */
859 build_min_array_type (tree elt_type
, tree index_type
)
861 tree t
= cxx_make_type (ARRAY_TYPE
);
862 TREE_TYPE (t
) = elt_type
;
863 TYPE_DOMAIN (t
) = index_type
;
867 /* Set TYPE_CANONICAL like build_array_type_1, but using
868 build_cplus_array_type. */
871 set_array_type_canon (tree t
, tree elt_type
, tree index_type
)
873 /* Set the canonical type for this new node. */
874 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
875 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
876 SET_TYPE_STRUCTURAL_EQUALITY (t
);
877 else if (TYPE_CANONICAL (elt_type
) != elt_type
878 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
880 = build_cplus_array_type (TYPE_CANONICAL (elt_type
),
882 ? TYPE_CANONICAL (index_type
) : index_type
);
884 TYPE_CANONICAL (t
) = t
;
887 /* Like build_array_type, but handle special C++ semantics: an array of a
888 variant element type is a variant of the array of the main variant of
892 build_cplus_array_type (tree elt_type
, tree index_type
)
896 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
897 return error_mark_node
;
899 bool dependent
= (uses_template_parms (elt_type
)
900 || (index_type
&& uses_template_parms (index_type
)));
902 if (elt_type
!= TYPE_MAIN_VARIANT (elt_type
))
903 /* Start with an array of the TYPE_MAIN_VARIANT. */
904 t
= build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type
),
908 /* Since type_hash_canon calls layout_type, we need to use our own
910 cplus_array_info cai
;
913 if (cplus_array_htab
== NULL
)
914 cplus_array_htab
= hash_table
<cplus_array_hasher
>::create_ggc (61);
916 hash
= TYPE_UID (elt_type
);
918 hash
^= TYPE_UID (index_type
);
920 cai
.domain
= index_type
;
922 tree
*e
= cplus_array_htab
->find_slot_with_hash (&cai
, hash
, INSERT
);
924 /* We have found the type: we're done. */
928 /* Build a new array type. */
929 t
= build_min_array_type (elt_type
, index_type
);
931 /* Store it in the hash table. */
934 /* Set the canonical type for this new node. */
935 set_array_type_canon (t
, elt_type
, index_type
);
940 t
= build_array_type (elt_type
, index_type
);
943 /* Now check whether we already have this array variant. */
944 if (elt_type
!= TYPE_MAIN_VARIANT (elt_type
))
947 for (t
= m
; t
; t
= TYPE_NEXT_VARIANT (t
))
948 if (TREE_TYPE (t
) == elt_type
949 && TYPE_NAME (t
) == NULL_TREE
950 && TYPE_ATTRIBUTES (t
) == NULL_TREE
)
954 t
= build_min_array_type (elt_type
, index_type
);
955 set_array_type_canon (t
, elt_type
, index_type
);
959 /* Make sure sizes are shared with the main variant.
960 layout_type can't be called after setting TYPE_NEXT_VARIANT,
961 as it will overwrite alignment etc. of all variants. */
962 TYPE_SIZE (t
) = TYPE_SIZE (m
);
963 TYPE_SIZE_UNIT (t
) = TYPE_SIZE_UNIT (m
);
966 TYPE_MAIN_VARIANT (t
) = m
;
967 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
968 TYPE_NEXT_VARIANT (m
) = t
;
972 /* Avoid spurious warnings with VLAs (c++/54583). */
973 if (TYPE_SIZE (t
) && EXPR_P (TYPE_SIZE (t
)))
974 TREE_NO_WARNING (TYPE_SIZE (t
)) = 1;
976 /* Push these needs up to the ARRAY_TYPE so that initialization takes
977 place more easily. */
978 bool needs_ctor
= (TYPE_NEEDS_CONSTRUCTING (t
)
979 = TYPE_NEEDS_CONSTRUCTING (elt_type
));
980 bool needs_dtor
= (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
981 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type
));
983 if (!dependent
&& t
== TYPE_MAIN_VARIANT (t
)
984 && !COMPLETE_TYPE_P (t
) && COMPLETE_TYPE_P (elt_type
))
986 /* The element type has been completed since the last time we saw
987 this array type; update the layout and 'tor flags for any variants
990 for (tree v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
992 TYPE_NEEDS_CONSTRUCTING (v
) = needs_ctor
;
993 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v
) = needs_dtor
;
1000 /* Return an ARRAY_TYPE with element type ELT and length N. */
1003 build_array_of_n_type (tree elt
, int n
)
1005 return build_cplus_array_type (elt
, build_index_type (size_int (n
- 1)));
1008 /* True iff T is an N3639 array of runtime bound (VLA). These were
1009 approved for C++14 but then removed. */
1012 array_of_runtime_bound_p (tree t
)
1014 if (!t
|| TREE_CODE (t
) != ARRAY_TYPE
)
1016 tree dom
= TYPE_DOMAIN (t
);
1019 tree max
= TYPE_MAX_VALUE (dom
);
1020 return (!potential_rvalue_constant_expression (max
)
1021 || (!value_dependent_expression_p (max
) && !TREE_CONSTANT (max
)));
1024 /* Return a reference type node referring to TO_TYPE. If RVAL is
1025 true, return an rvalue reference type, otherwise return an lvalue
1026 reference type. If a type node exists, reuse it, otherwise create
1029 cp_build_reference_type (tree to_type
, bool rval
)
1033 if (TREE_CODE (to_type
) == REFERENCE_TYPE
)
1035 rval
= rval
&& TYPE_REF_IS_RVALUE (to_type
);
1036 to_type
= TREE_TYPE (to_type
);
1039 lvalue_ref
= build_reference_type (to_type
);
1043 /* This code to create rvalue reference types is based on and tied
1044 to the code creating lvalue reference types in the middle-end
1045 functions build_reference_type_for_mode and build_reference_type.
1047 It works by putting the rvalue reference type nodes after the
1048 lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
1049 they will effectively be ignored by the middle end. */
1051 for (t
= lvalue_ref
; (t
= TYPE_NEXT_REF_TO (t
)); )
1052 if (TYPE_REF_IS_RVALUE (t
))
1055 t
= build_distinct_type_copy (lvalue_ref
);
1057 TYPE_REF_IS_RVALUE (t
) = true;
1058 TYPE_NEXT_REF_TO (t
) = TYPE_NEXT_REF_TO (lvalue_ref
);
1059 TYPE_NEXT_REF_TO (lvalue_ref
) = t
;
1061 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
1062 SET_TYPE_STRUCTURAL_EQUALITY (t
);
1063 else if (TYPE_CANONICAL (to_type
) != to_type
)
1065 = cp_build_reference_type (TYPE_CANONICAL (to_type
), rval
);
1067 TYPE_CANONICAL (t
) = t
;
1075 /* Returns EXPR cast to rvalue reference type, like std::move. */
1080 tree type
= TREE_TYPE (expr
);
1081 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
1082 type
= cp_build_reference_type (type
, /*rval*/true);
1083 return build_static_cast (type
, expr
, tf_warning_or_error
);
1086 /* Used by the C++ front end to build qualified array types. However,
1087 the C version of this function does not properly maintain canonical
1088 types (which are not used in C). */
1090 c_build_qualified_type (tree type
, int type_quals
, tree
/* orig_qual_type */,
1091 size_t /* orig_qual_indirect */)
1093 return cp_build_qualified_type (type
, type_quals
);
1097 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
1098 arrays correctly. In particular, if TYPE is an array of T's, and
1099 TYPE_QUALS is non-empty, returns an array of qualified T's.
1101 FLAGS determines how to deal with ill-formed qualifications. If
1102 tf_ignore_bad_quals is set, then bad qualifications are dropped
1103 (this is permitted if TYPE was introduced via a typedef or template
1104 type parameter). If bad qualifications are dropped and tf_warning
1105 is set, then a warning is issued for non-const qualifications. If
1106 tf_ignore_bad_quals is not set and tf_error is not set, we
1107 return error_mark_node. Otherwise, we issue an error, and ignore
1110 Qualification of a reference type is valid when the reference came
1111 via a typedef or template type argument. [dcl.ref] No such
1112 dispensation is provided for qualifying a function type. [dcl.fct]
1113 DR 295 queries this and the proposed resolution brings it into line
1114 with qualifying a reference. We implement the DR. We also behave
1115 in a similar manner for restricting non-pointer types. */
1118 cp_build_qualified_type_real (tree type
,
1120 tsubst_flags_t complain
)
1123 int bad_quals
= TYPE_UNQUALIFIED
;
1125 if (type
== error_mark_node
)
1128 if (type_quals
== cp_type_quals (type
))
1131 if (TREE_CODE (type
) == ARRAY_TYPE
)
1133 /* In C++, the qualification really applies to the array element
1134 type. Obtain the appropriately qualified element type. */
1137 = cp_build_qualified_type_real (TREE_TYPE (type
),
1141 if (element_type
== error_mark_node
)
1142 return error_mark_node
;
1144 /* See if we already have an identically qualified type. Tests
1145 should be equivalent to those in check_qualified_type. */
1146 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1147 if (TREE_TYPE (t
) == element_type
1148 && TYPE_NAME (t
) == TYPE_NAME (type
)
1149 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
)
1150 && attribute_list_equal (TYPE_ATTRIBUTES (t
),
1151 TYPE_ATTRIBUTES (type
)))
1156 t
= build_cplus_array_type (element_type
, TYPE_DOMAIN (type
));
1158 /* Keep the typedef name. */
1159 if (TYPE_NAME (t
) != TYPE_NAME (type
))
1161 t
= build_variant_type_copy (t
);
1162 TYPE_NAME (t
) = TYPE_NAME (type
);
1163 SET_TYPE_ALIGN (t
, TYPE_ALIGN (type
));
1164 TYPE_USER_ALIGN (t
) = TYPE_USER_ALIGN (type
);
1168 /* Even if we already had this variant, we update
1169 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1170 they changed since the variant was originally created.
1172 This seems hokey; if there is some way to use a previous
1173 variant *without* coming through here,
1174 TYPE_NEEDS_CONSTRUCTING will never be updated. */
1175 TYPE_NEEDS_CONSTRUCTING (t
)
1176 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
1177 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
1178 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
1181 else if (TREE_CODE (type
) == TYPE_PACK_EXPANSION
)
1183 tree t
= PACK_EXPANSION_PATTERN (type
);
1185 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
1186 return make_pack_expansion (t
);
1189 /* A reference or method type shall not be cv-qualified.
1190 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1191 (in CD1) we always ignore extra cv-quals on functions. */
1192 if (type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
)
1193 && (TREE_CODE (type
) == REFERENCE_TYPE
1194 || TREE_CODE (type
) == FUNCTION_TYPE
1195 || TREE_CODE (type
) == METHOD_TYPE
))
1197 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1198 bad_quals
|= type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
1199 type_quals
&= ~(TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
1202 /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1203 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1204 type_quals
|= type_memfn_quals (type
);
1206 /* A restrict-qualified type must be a pointer (or reference)
1207 to object or incomplete type. */
1208 if ((type_quals
& TYPE_QUAL_RESTRICT
)
1209 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
1210 && TREE_CODE (type
) != TYPENAME_TYPE
1211 && !POINTER_TYPE_P (type
))
1213 bad_quals
|= TYPE_QUAL_RESTRICT
;
1214 type_quals
&= ~TYPE_QUAL_RESTRICT
;
1217 if (bad_quals
== TYPE_UNQUALIFIED
1218 || (complain
& tf_ignore_bad_quals
))
1220 else if (!(complain
& tf_error
))
1221 return error_mark_node
;
1224 tree bad_type
= build_qualified_type (ptr_type_node
, bad_quals
);
1225 error ("%qV qualifiers cannot be applied to %qT",
1229 /* Retrieve (or create) the appropriately qualified variant. */
1230 result
= build_qualified_type (type
, type_quals
);
1232 /* Preserve exception specs and ref-qualifier since build_qualified_type
1233 doesn't know about them. */
1234 if (TREE_CODE (result
) == FUNCTION_TYPE
1235 || TREE_CODE (result
) == METHOD_TYPE
)
1237 result
= build_exception_variant (result
, TYPE_RAISES_EXCEPTIONS (type
));
1238 result
= build_ref_qualified_type (result
, type_memfn_rqual (type
));
1244 /* Return TYPE with const and volatile removed. */
1247 cv_unqualified (tree type
)
1251 if (type
== error_mark_node
)
1254 quals
= cp_type_quals (type
);
1255 quals
&= ~(TYPE_QUAL_CONST
|TYPE_QUAL_VOLATILE
);
1256 return cp_build_qualified_type (type
, quals
);
1259 /* Subroutine of strip_typedefs. We want to apply to RESULT the attributes
1260 from ATTRIBS that affect type identity, and no others. If any are not
1261 applied, set *remove_attributes to true. */
1264 apply_identity_attributes (tree result
, tree attribs
, bool *remove_attributes
)
1266 tree first_ident
= NULL_TREE
;
1267 tree new_attribs
= NULL_TREE
;
1268 tree
*p
= &new_attribs
;
1270 if (OVERLOAD_TYPE_P (result
))
1272 /* On classes and enums all attributes are ingrained. */
1273 gcc_assert (attribs
== TYPE_ATTRIBUTES (result
));
1277 for (tree a
= attribs
; a
; a
= TREE_CHAIN (a
))
1279 const attribute_spec
*as
1280 = lookup_attribute_spec (get_attribute_name (a
));
1281 if (as
&& as
->affects_type_identity
)
1285 else if (first_ident
== error_mark_node
)
1287 *p
= tree_cons (TREE_PURPOSE (a
), TREE_VALUE (a
), NULL_TREE
);
1288 p
= &TREE_CHAIN (*p
);
1291 else if (first_ident
)
1293 for (tree a2
= first_ident
; a2
; a2
= TREE_CHAIN (a2
))
1295 *p
= tree_cons (TREE_PURPOSE (a2
), TREE_VALUE (a2
), NULL_TREE
);
1296 p
= &TREE_CHAIN (*p
);
1298 first_ident
= error_mark_node
;
1301 if (first_ident
!= error_mark_node
)
1302 new_attribs
= first_ident
;
1304 if (first_ident
== attribs
)
1305 /* All attributes affected type identity. */;
1307 *remove_attributes
= true;
1309 return cp_build_type_attribute_variant (result
, new_attribs
);
1312 /* Builds a qualified variant of T that is not a typedef variant.
1313 E.g. consider the following declarations:
1314 typedef const int ConstInt;
1315 typedef ConstInt* PtrConstInt;
1316 If T is PtrConstInt, this function returns a type representing
1318 In other words, if T is a typedef, the function returns the underlying type.
1319 The cv-qualification and attributes of the type returned match the
1321 They will always be compatible types.
1322 The returned type is built so that all of its subtypes
1323 recursively have their typedefs stripped as well.
1325 This is different from just returning TYPE_CANONICAL (T)
1326 Because of several reasons:
1327 * If T is a type that needs structural equality
1328 its TYPE_CANONICAL (T) will be NULL.
1329 * TYPE_CANONICAL (T) desn't carry type attributes
1330 and loses template parameter names.
1332 If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
1333 affect type identity, and set the referent to true if any were
1337 strip_typedefs (tree t
, bool *remove_attributes
)
1339 tree result
= NULL
, type
= NULL
, t0
= NULL
;
1341 if (!t
|| t
== error_mark_node
)
1344 if (TREE_CODE (t
) == TREE_LIST
)
1346 bool changed
= false;
1347 vec
<tree
,va_gc
> *vec
= make_tree_vector ();
1349 for (; t
; t
= TREE_CHAIN (t
))
1351 gcc_assert (!TREE_PURPOSE (t
));
1352 tree elt
= strip_typedefs (TREE_VALUE (t
), remove_attributes
);
1353 if (elt
!= TREE_VALUE (t
))
1355 vec_safe_push (vec
, elt
);
1358 r
= build_tree_list_vec (vec
);
1359 release_tree_vector (vec
);
1363 gcc_assert (TYPE_P (t
));
1365 if (t
== TYPE_CANONICAL (t
))
1368 if (dependent_alias_template_spec_p (t
))
1369 /* DR 1558: However, if the template-id is dependent, subsequent
1370 template argument substitution still applies to the template-id. */
1373 switch (TREE_CODE (t
))
1376 type
= strip_typedefs (TREE_TYPE (t
), remove_attributes
);
1377 result
= build_pointer_type (type
);
1379 case REFERENCE_TYPE
:
1380 type
= strip_typedefs (TREE_TYPE (t
), remove_attributes
);
1381 result
= cp_build_reference_type (type
, TYPE_REF_IS_RVALUE (t
));
1384 t0
= strip_typedefs (TYPE_OFFSET_BASETYPE (t
), remove_attributes
);
1385 type
= strip_typedefs (TREE_TYPE (t
), remove_attributes
);
1386 result
= build_offset_type (t0
, type
);
1389 if (TYPE_PTRMEMFUNC_P (t
))
1391 t0
= strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t
), remove_attributes
);
1392 result
= build_ptrmemfunc_type (t0
);
1396 type
= strip_typedefs (TREE_TYPE (t
), remove_attributes
);
1397 t0
= strip_typedefs (TYPE_DOMAIN (t
), remove_attributes
);
1398 result
= build_cplus_array_type (type
, t0
);
1403 tree arg_types
= NULL
, arg_node
, arg_node2
, arg_type
;
1406 /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
1407 around the compiler (e.g. cp_parser_late_parsing_default_args), we
1408 can't expect that re-hashing a function type will find a previous
1409 equivalent type, so try to reuse the input type if nothing has
1410 changed. If the type is itself a variant, that will change. */
1411 bool is_variant
= typedef_variant_p (t
);
1412 if (remove_attributes
1413 && (TYPE_ATTRIBUTES (t
) || TYPE_USER_ALIGN (t
)))
1416 type
= strip_typedefs (TREE_TYPE (t
), remove_attributes
);
1417 changed
= type
!= TREE_TYPE (t
) || is_variant
;
1419 for (arg_node
= TYPE_ARG_TYPES (t
);
1421 arg_node
= TREE_CHAIN (arg_node
))
1423 if (arg_node
== void_list_node
)
1425 arg_type
= strip_typedefs (TREE_VALUE (arg_node
),
1427 gcc_assert (arg_type
);
1428 if (arg_type
== TREE_VALUE (arg_node
) && !changed
)
1434 for (arg_node2
= TYPE_ARG_TYPES (t
);
1435 arg_node2
!= arg_node
;
1436 arg_node2
= TREE_CHAIN (arg_node2
))
1438 = tree_cons (TREE_PURPOSE (arg_node2
),
1439 TREE_VALUE (arg_node2
), arg_types
);
1443 = tree_cons (TREE_PURPOSE (arg_node
), arg_type
, arg_types
);
1450 arg_types
= nreverse (arg_types
);
1452 /* A list of parameters not ending with an ellipsis
1453 must end with void_list_node. */
1455 arg_types
= chainon (arg_types
, void_list_node
);
1457 if (TREE_CODE (t
) == METHOD_TYPE
)
1459 tree class_type
= TREE_TYPE (TREE_VALUE (arg_types
));
1460 gcc_assert (class_type
);
1462 build_method_type_directly (class_type
, type
,
1463 TREE_CHAIN (arg_types
));
1465 = build_ref_qualified_type (result
, type_memfn_rqual (t
));
1469 result
= build_function_type (type
,
1471 result
= apply_memfn_quals (result
,
1472 type_memfn_quals (t
),
1473 type_memfn_rqual (t
));
1476 if (TYPE_RAISES_EXCEPTIONS (t
))
1477 result
= build_exception_variant (result
,
1478 TYPE_RAISES_EXCEPTIONS (t
));
1479 if (TYPE_HAS_LATE_RETURN_TYPE (t
))
1480 TYPE_HAS_LATE_RETURN_TYPE (result
) = 1;
1485 tree fullname
= TYPENAME_TYPE_FULLNAME (t
);
1486 if (TREE_CODE (fullname
) == TEMPLATE_ID_EXPR
1487 && TREE_OPERAND (fullname
, 1))
1489 tree args
= TREE_OPERAND (fullname
, 1);
1490 tree new_args
= copy_node (args
);
1491 bool changed
= false;
1492 for (int i
= 0; i
< TREE_VEC_LENGTH (args
); ++i
)
1494 tree arg
= TREE_VEC_ELT (args
, i
);
1497 strip_arg
= strip_typedefs (arg
, remove_attributes
);
1499 strip_arg
= strip_typedefs_expr (arg
, remove_attributes
);
1500 TREE_VEC_ELT (new_args
, i
) = strip_arg
;
1501 if (strip_arg
!= arg
)
1506 NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args
)
1507 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args
);
1509 = lookup_template_function (TREE_OPERAND (fullname
, 0),
1513 ggc_free (new_args
);
1515 result
= make_typename_type (strip_typedefs (TYPE_CONTEXT (t
),
1517 fullname
, typename_type
, tf_none
);
1518 /* Handle 'typedef typename A::N N;' */
1519 if (typedef_variant_p (result
))
1520 result
= TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (TYPE_NAME (result
)));
1524 result
= strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t
),
1526 if (result
== DECLTYPE_TYPE_EXPR (t
))
1529 result
= (finish_decltype_type
1531 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t
),
1540 if (typedef_variant_p (t
))
1542 /* Explicitly get the underlying type, as TYPE_MAIN_VARIANT doesn't
1543 strip typedefs with attributes. */
1544 result
= TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (TYPE_NAME (t
)));
1545 result
= strip_typedefs (result
);
1548 result
= TYPE_MAIN_VARIANT (t
);
1550 gcc_assert (!typedef_variant_p (result
));
1551 if (TYPE_USER_ALIGN (t
) != TYPE_USER_ALIGN (result
)
1552 || TYPE_ALIGN (t
) != TYPE_ALIGN (result
))
1554 gcc_assert (TYPE_USER_ALIGN (t
));
1555 if (remove_attributes
)
1556 *remove_attributes
= true;
1559 if (TYPE_ALIGN (t
) == TYPE_ALIGN (result
))
1560 result
= build_variant_type_copy (result
);
1562 result
= build_aligned_type (result
, TYPE_ALIGN (t
));
1563 TYPE_USER_ALIGN (result
) = true;
1566 if (TYPE_ATTRIBUTES (t
))
1568 if (remove_attributes
)
1569 result
= apply_identity_attributes (result
, TYPE_ATTRIBUTES (t
),
1572 result
= cp_build_type_attribute_variant (result
, TYPE_ATTRIBUTES (t
));
1574 return cp_build_qualified_type (result
, cp_type_quals (t
));
1577 /* Like strip_typedefs above, but works on expressions, so that in
1579 template<class T> struct A
1585 sizeof(TT) is replaced by sizeof(T). */
1588 strip_typedefs_expr (tree t
, bool *remove_attributes
)
1592 enum tree_code code
;
1594 if (t
== NULL_TREE
|| t
== error_mark_node
)
1597 if (DECL_P (t
) || CONSTANT_CLASS_P (t
))
1600 /* Some expressions have type operands, so let's handle types here rather
1601 than check TYPE_P in multiple places below. */
1603 return strip_typedefs (t
, remove_attributes
);
1605 code
= TREE_CODE (t
);
1608 case IDENTIFIER_NODE
:
1609 case TEMPLATE_PARM_INDEX
:
1612 case ARGUMENT_PACK_SELECT
:
1617 tree type1
= strip_typedefs (TRAIT_EXPR_TYPE1 (t
), remove_attributes
);
1618 tree type2
= strip_typedefs (TRAIT_EXPR_TYPE2 (t
), remove_attributes
);
1619 if (type1
== TRAIT_EXPR_TYPE1 (t
)
1620 && type2
== TRAIT_EXPR_TYPE2 (t
))
1623 TRAIT_EXPR_TYPE1 (r
) = type1
;
1624 TRAIT_EXPR_TYPE2 (r
) = type2
;
1630 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
1631 bool changed
= false;
1633 for (it
= t
; it
; it
= TREE_CHAIN (it
))
1635 tree val
= strip_typedefs_expr (TREE_VALUE (t
), remove_attributes
);
1636 vec_safe_push (vec
, val
);
1637 if (val
!= TREE_VALUE (t
))
1639 gcc_assert (TREE_PURPOSE (it
) == NULL_TREE
);
1644 FOR_EACH_VEC_ELT_REVERSE (*vec
, i
, it
)
1645 r
= tree_cons (NULL_TREE
, it
, r
);
1649 release_tree_vector (vec
);
1655 bool changed
= false;
1656 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
1657 n
= TREE_VEC_LENGTH (t
);
1658 vec_safe_reserve (vec
, n
);
1659 for (i
= 0; i
< n
; ++i
)
1661 tree op
= strip_typedefs_expr (TREE_VEC_ELT (t
, i
),
1663 vec
->quick_push (op
);
1664 if (op
!= TREE_VEC_ELT (t
, i
))
1670 for (i
= 0; i
< n
; ++i
)
1671 TREE_VEC_ELT (r
, i
) = (*vec
)[i
];
1672 NON_DEFAULT_TEMPLATE_ARGS_COUNT (r
)
1673 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t
);
1677 release_tree_vector (vec
);
1683 bool changed
= false;
1684 vec
<constructor_elt
, va_gc
> *vec
1685 = vec_safe_copy (CONSTRUCTOR_ELTS (t
));
1686 n
= CONSTRUCTOR_NELTS (t
);
1687 type
= strip_typedefs (TREE_TYPE (t
), remove_attributes
);
1688 for (i
= 0; i
< n
; ++i
)
1690 constructor_elt
*e
= &(*vec
)[i
];
1691 tree op
= strip_typedefs_expr (e
->value
, remove_attributes
);
1698 (e
->index
== strip_typedefs_expr (e
->index
, remove_attributes
));
1701 if (!changed
&& type
== TREE_TYPE (t
))
1709 TREE_TYPE (r
) = type
;
1710 CONSTRUCTOR_ELTS (r
) = vec
;
1716 error ("lambda-expression in a constant expression");
1717 return error_mark_node
;
1723 gcc_assert (EXPR_P (t
));
1725 n
= TREE_OPERAND_LENGTH (t
);
1726 ops
= XALLOCAVEC (tree
, n
);
1727 type
= TREE_TYPE (t
);
1732 case IMPLICIT_CONV_EXPR
:
1733 case DYNAMIC_CAST_EXPR
:
1734 case STATIC_CAST_EXPR
:
1735 case CONST_CAST_EXPR
:
1736 case REINTERPRET_CAST_EXPR
:
1739 type
= strip_typedefs (type
, remove_attributes
);
1743 for (i
= 0; i
< n
; ++i
)
1744 ops
[i
] = strip_typedefs_expr (TREE_OPERAND (t
, i
), remove_attributes
);
1748 /* If nothing changed, return t. */
1749 for (i
= 0; i
< n
; ++i
)
1750 if (ops
[i
] != TREE_OPERAND (t
, i
))
1752 if (i
== n
&& type
== TREE_TYPE (t
))
1756 TREE_TYPE (r
) = type
;
1757 for (i
= 0; i
< n
; ++i
)
1758 TREE_OPERAND (r
, i
) = ops
[i
];
1762 /* Makes a copy of BINFO and TYPE, which is to be inherited into a
1763 graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
1764 and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
1765 VIRT indicates whether TYPE is inherited virtually or not.
1766 IGO_PREV points at the previous binfo of the inheritance graph
1767 order chain. The newly copied binfo's TREE_CHAIN forms this
1770 The CLASSTYPE_VBASECLASSES vector of T is constructed in the
1771 correct order. That is in the order the bases themselves should be
1774 The BINFO_INHERITANCE of a virtual base class points to the binfo
1775 of the most derived type. ??? We could probably change this so that
1776 BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
1777 remove a field. They currently can only differ for primary virtual
1781 copy_binfo (tree binfo
, tree type
, tree t
, tree
*igo_prev
, int virt
)
1787 /* See if we've already made this virtual base. */
1788 new_binfo
= binfo_for_vbase (type
, t
);
1793 new_binfo
= make_tree_binfo (binfo
? BINFO_N_BASE_BINFOS (binfo
) : 0);
1794 BINFO_TYPE (new_binfo
) = type
;
1796 /* Chain it into the inheritance graph. */
1797 TREE_CHAIN (*igo_prev
) = new_binfo
;
1798 *igo_prev
= new_binfo
;
1800 if (binfo
&& !BINFO_DEPENDENT_BASE_P (binfo
))
1805 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), type
));
1807 BINFO_OFFSET (new_binfo
) = BINFO_OFFSET (binfo
);
1808 BINFO_VIRTUALS (new_binfo
) = BINFO_VIRTUALS (binfo
);
1810 /* We do not need to copy the accesses, as they are read only. */
1811 BINFO_BASE_ACCESSES (new_binfo
) = BINFO_BASE_ACCESSES (binfo
);
1813 /* Recursively copy base binfos of BINFO. */
1814 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
1816 tree new_base_binfo
;
1817 new_base_binfo
= copy_binfo (base_binfo
, BINFO_TYPE (base_binfo
),
1819 BINFO_VIRTUAL_P (base_binfo
));
1821 if (!BINFO_INHERITANCE_CHAIN (new_base_binfo
))
1822 BINFO_INHERITANCE_CHAIN (new_base_binfo
) = new_binfo
;
1823 BINFO_BASE_APPEND (new_binfo
, new_base_binfo
);
1827 BINFO_DEPENDENT_BASE_P (new_binfo
) = 1;
1831 /* Push it onto the list after any virtual bases it contains
1832 will have been pushed. */
1833 CLASSTYPE_VBASECLASSES (t
)->quick_push (new_binfo
);
1834 BINFO_VIRTUAL_P (new_binfo
) = 1;
1835 BINFO_INHERITANCE_CHAIN (new_binfo
) = TYPE_BINFO (t
);
1841 /* Hashing of lists so that we don't make duplicates.
1842 The entry point is `list_hash_canon'. */
1851 struct list_hasher
: ggc_ptr_hash
<tree_node
>
1853 typedef list_proxy
*compare_type
;
1855 static hashval_t
hash (tree
);
1856 static bool equal (tree
, list_proxy
*);
1859 /* Now here is the hash table. When recording a list, it is added
1860 to the slot whose index is the hash code mod the table size.
1861 Note that the hash table is used for several kinds of lists.
1862 While all these live in the same table, they are completely independent,
1863 and the hash code is computed differently for each of these. */
1865 static GTY (()) hash_table
<list_hasher
> *list_hash_table
;
1867 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
1868 for a node we are thinking about adding). */
1871 list_hasher::equal (tree t
, list_proxy
*proxy
)
1873 return (TREE_VALUE (t
) == proxy
->value
1874 && TREE_PURPOSE (t
) == proxy
->purpose
1875 && TREE_CHAIN (t
) == proxy
->chain
);
1878 /* Compute a hash code for a list (chain of TREE_LIST nodes
1879 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
1880 TREE_COMMON slots), by adding the hash codes of the individual entries. */
1883 list_hash_pieces (tree purpose
, tree value
, tree chain
)
1885 hashval_t hashcode
= 0;
1888 hashcode
+= TREE_HASH (chain
);
1891 hashcode
+= TREE_HASH (value
);
1895 hashcode
+= TREE_HASH (purpose
);
1901 /* Hash an already existing TREE_LIST. */
1904 list_hasher::hash (tree t
)
1906 return list_hash_pieces (TREE_PURPOSE (t
),
1911 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1912 object for an identical list if one already exists. Otherwise, build a
1913 new one, and record it as the canonical object. */
1916 hash_tree_cons (tree purpose
, tree value
, tree chain
)
1920 struct list_proxy proxy
;
1922 /* Hash the list node. */
1923 hashcode
= list_hash_pieces (purpose
, value
, chain
);
1924 /* Create a proxy for the TREE_LIST we would like to create. We
1925 don't actually create it so as to avoid creating garbage. */
1926 proxy
.purpose
= purpose
;
1927 proxy
.value
= value
;
1928 proxy
.chain
= chain
;
1929 /* See if it is already in the table. */
1930 slot
= list_hash_table
->find_slot_with_hash (&proxy
, hashcode
, INSERT
);
1931 /* If not, create a new node. */
1933 *slot
= tree_cons (purpose
, value
, chain
);
1934 return (tree
) *slot
;
1937 /* Constructor for hashed lists. */
1940 hash_tree_chain (tree value
, tree chain
)
1942 return hash_tree_cons (NULL_TREE
, value
, chain
);
1946 debug_binfo (tree elem
)
1951 fprintf (stderr
, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
1953 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1954 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1955 debug_tree (BINFO_TYPE (elem
));
1956 if (BINFO_VTABLE (elem
))
1957 fprintf (stderr
, "vtable decl \"%s\"\n",
1958 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem
))));
1960 fprintf (stderr
, "no vtable decl yet\n");
1961 fprintf (stderr
, "virtuals:\n");
1962 virtuals
= BINFO_VIRTUALS (elem
);
1967 tree fndecl
= TREE_VALUE (virtuals
);
1968 fprintf (stderr
, "%s [%ld =? %ld]\n",
1969 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1970 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1972 virtuals
= TREE_CHAIN (virtuals
);
1976 /* Build a representation for the qualified name SCOPE::NAME. TYPE is
1977 the type of the result expression, if known, or NULL_TREE if the
1978 resulting expression is type-dependent. If TEMPLATE_P is true,
1979 NAME is known to be a template because the user explicitly used the
1980 "template" keyword after the "::".
1982 All SCOPE_REFs should be built by use of this function. */
1985 build_qualified_name (tree type
, tree scope
, tree name
, bool template_p
)
1988 if (type
== error_mark_node
1989 || scope
== error_mark_node
1990 || name
== error_mark_node
)
1991 return error_mark_node
;
1992 t
= build2 (SCOPE_REF
, type
, scope
, name
);
1993 QUALIFIED_NAME_IS_TEMPLATE (t
) = template_p
;
1994 PTRMEM_OK_P (t
) = true;
1996 t
= convert_from_reference (t
);
2000 /* Like check_qualified_type, but also check ref-qualifier and exception
2004 cp_check_qualified_type (const_tree cand
, const_tree base
, int type_quals
,
2005 cp_ref_qualifier rqual
, tree raises
)
2007 return (TYPE_QUALS (cand
) == type_quals
2008 && check_base_type (cand
, base
)
2009 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (cand
),
2011 && type_memfn_rqual (cand
) == rqual
);
2014 /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
2017 build_ref_qualified_type (tree type
, cp_ref_qualifier rqual
)
2021 if (rqual
== type_memfn_rqual (type
))
2024 int type_quals
= TYPE_QUALS (type
);
2025 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
2026 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
2027 if (cp_check_qualified_type (t
, type
, type_quals
, rqual
, raises
))
2030 t
= build_variant_type_copy (type
);
2033 case REF_QUAL_RVALUE
:
2034 FUNCTION_RVALUE_QUALIFIED (t
) = 1;
2035 FUNCTION_REF_QUALIFIED (t
) = 1;
2037 case REF_QUAL_LVALUE
:
2038 FUNCTION_RVALUE_QUALIFIED (t
) = 0;
2039 FUNCTION_REF_QUALIFIED (t
) = 1;
2042 FUNCTION_REF_QUALIFIED (t
) = 0;
2046 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
2047 /* Propagate structural equality. */
2048 SET_TYPE_STRUCTURAL_EQUALITY (t
);
2049 else if (TYPE_CANONICAL (type
) != type
)
2050 /* Build the underlying canonical type, since it is different
2052 TYPE_CANONICAL (t
) = build_ref_qualified_type (TYPE_CANONICAL (type
),
2055 /* T is its own canonical type. */
2056 TYPE_CANONICAL (t
) = t
;
2061 /* Returns nonzero if X is an expression for a (possibly overloaded)
2062 function. If "f" is a function or function template, "f", "c->f",
2063 "c.f", "C::f", and "f<int>" will all be considered possibly
2064 overloaded functions. Returns 2 if the function is actually
2065 overloaded, i.e., if it is impossible to know the type of the
2066 function without performing overload resolution. */
2069 is_overloaded_fn (tree x
)
2071 /* A baselink is also considered an overloaded function. */
2072 if (TREE_CODE (x
) == OFFSET_REF
2073 || TREE_CODE (x
) == COMPONENT_REF
)
2074 x
= TREE_OPERAND (x
, 1);
2076 x
= BASELINK_FUNCTIONS (x
);
2077 if (TREE_CODE (x
) == TEMPLATE_ID_EXPR
)
2078 x
= TREE_OPERAND (x
, 0);
2079 if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x
))
2080 || (TREE_CODE (x
) == OVERLOAD
&& OVL_CHAIN (x
)))
2082 return (TREE_CODE (x
) == FUNCTION_DECL
2083 || TREE_CODE (x
) == OVERLOAD
);
2086 /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
2087 (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
2091 dependent_name (tree x
)
2093 if (identifier_p (x
))
2095 if (TREE_CODE (x
) != COMPONENT_REF
2096 && TREE_CODE (x
) != OFFSET_REF
2097 && TREE_CODE (x
) != BASELINK
2098 && is_overloaded_fn (x
))
2099 return DECL_NAME (get_first_fn (x
));
2103 /* Returns true iff X is an expression for an overloaded function
2104 whose type cannot be known without performing overload
2108 really_overloaded_fn (tree x
)
2110 return is_overloaded_fn (x
) == 2;
2116 gcc_assert (is_overloaded_fn (from
));
2117 /* A baselink is also considered an overloaded function. */
2118 if (TREE_CODE (from
) == OFFSET_REF
2119 || TREE_CODE (from
) == COMPONENT_REF
)
2120 from
= TREE_OPERAND (from
, 1);
2121 if (BASELINK_P (from
))
2122 from
= BASELINK_FUNCTIONS (from
);
2123 if (TREE_CODE (from
) == TEMPLATE_ID_EXPR
)
2124 from
= TREE_OPERAND (from
, 0);
2129 get_first_fn (tree from
)
2131 return OVL_CURRENT (get_fns (from
));
2134 /* Return a new OVL node, concatenating it with the old one. */
2137 ovl_cons (tree decl
, tree chain
)
2139 tree result
= make_node (OVERLOAD
);
2140 TREE_TYPE (result
) = unknown_type_node
;
2141 OVL_FUNCTION (result
) = decl
;
2142 TREE_CHAIN (result
) = chain
;
2147 /* Build a new overloaded function. If this is the first one,
2148 just return it; otherwise, ovl_cons the _DECLs */
2151 build_overload (tree decl
, tree chain
)
2153 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
2155 return ovl_cons (decl
, chain
);
2158 /* Return the scope where the overloaded functions OVL were found. */
2161 ovl_scope (tree ovl
)
2163 if (TREE_CODE (ovl
) == OFFSET_REF
2164 || TREE_CODE (ovl
) == COMPONENT_REF
)
2165 ovl
= TREE_OPERAND (ovl
, 1);
2166 if (TREE_CODE (ovl
) == BASELINK
)
2167 return BINFO_TYPE (BASELINK_BINFO (ovl
));
2168 if (TREE_CODE (ovl
) == TEMPLATE_ID_EXPR
)
2169 ovl
= TREE_OPERAND (ovl
, 0);
2170 /* Skip using-declarations. */
2171 while (TREE_CODE (ovl
) == OVERLOAD
&& OVL_USED (ovl
) && OVL_CHAIN (ovl
))
2172 ovl
= OVL_CHAIN (ovl
);
2173 return CP_DECL_CONTEXT (OVL_CURRENT (ovl
));
2176 #define PRINT_RING_SIZE 4
2179 cxx_printable_name_internal (tree decl
, int v
, bool translate
)
2181 static unsigned int uid_ring
[PRINT_RING_SIZE
];
2182 static char *print_ring
[PRINT_RING_SIZE
];
2183 static bool trans_ring
[PRINT_RING_SIZE
];
2184 static int ring_counter
;
2187 /* Only cache functions. */
2189 || TREE_CODE (decl
) != FUNCTION_DECL
2190 || DECL_LANG_SPECIFIC (decl
) == 0)
2191 return lang_decl_name (decl
, v
, translate
);
2193 /* See if this print name is lying around. */
2194 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
2195 if (uid_ring
[i
] == DECL_UID (decl
) && translate
== trans_ring
[i
])
2196 /* yes, so return it. */
2197 return print_ring
[i
];
2199 if (++ring_counter
== PRINT_RING_SIZE
)
2202 if (current_function_decl
!= NULL_TREE
)
2204 /* There may be both translated and untranslated versions of the
2206 for (i
= 0; i
< 2; i
++)
2208 if (uid_ring
[ring_counter
] == DECL_UID (current_function_decl
))
2210 if (ring_counter
== PRINT_RING_SIZE
)
2213 gcc_assert (uid_ring
[ring_counter
] != DECL_UID (current_function_decl
));
2216 free (print_ring
[ring_counter
]);
2218 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
, translate
));
2219 uid_ring
[ring_counter
] = DECL_UID (decl
);
2220 trans_ring
[ring_counter
] = translate
;
2221 return print_ring
[ring_counter
];
2225 cxx_printable_name (tree decl
, int v
)
2227 return cxx_printable_name_internal (decl
, v
, false);
2231 cxx_printable_name_translate (tree decl
, int v
)
2233 return cxx_printable_name_internal (decl
, v
, true);
2236 /* Return the canonical version of exception-specification RAISES for a C++17
2237 function type, for use in type comparison and building TYPE_CANONICAL. */
2240 canonical_eh_spec (tree raises
)
2242 if (raises
== NULL_TREE
)
2244 else if (DEFERRED_NOEXCEPT_SPEC_P (raises
)
2245 || uses_template_parms (raises
)
2246 || uses_template_parms (TREE_PURPOSE (raises
)))
2247 /* Keep a dependent or deferred exception specification. */
2249 else if (nothrow_spec_p (raises
))
2250 /* throw() -> noexcept. */
2251 return noexcept_true_spec
;
2253 /* For C++17 type matching, anything else -> nothing. */
2257 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
2258 listed in RAISES. */
2261 build_exception_variant (tree type
, tree raises
)
2266 if (comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (type
), ce_exact
))
2269 type_quals
= TYPE_QUALS (type
);
2270 cp_ref_qualifier rqual
= type_memfn_rqual (type
);
2271 for (v
= TYPE_MAIN_VARIANT (type
); v
; v
= TYPE_NEXT_VARIANT (v
))
2272 if (cp_check_qualified_type (v
, type
, type_quals
, rqual
, raises
))
2275 /* Need to build a new variant. */
2276 v
= build_variant_type_copy (type
);
2277 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
2279 if (!flag_noexcept_type
)
2280 /* The exception-specification is not part of the canonical type. */
2283 /* Canonicalize the exception specification. */
2284 tree cr
= canonical_eh_spec (raises
);
2286 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
2287 /* Propagate structural equality. */
2288 SET_TYPE_STRUCTURAL_EQUALITY (v
);
2289 else if (TYPE_CANONICAL (type
) != type
|| cr
!= raises
)
2290 /* Build the underlying canonical type, since it is different
2292 TYPE_CANONICAL (v
) = build_exception_variant (TYPE_CANONICAL (type
), cr
);
2294 /* T is its own canonical type. */
2295 TYPE_CANONICAL (v
) = v
;
2300 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
2301 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
2305 bind_template_template_parm (tree t
, tree newargs
)
2307 tree decl
= TYPE_NAME (t
);
2310 t2
= cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM
);
2311 decl
= build_decl (input_location
,
2312 TYPE_DECL
, DECL_NAME (decl
), NULL_TREE
);
2314 /* These nodes have to be created to reflect new TYPE_DECL and template
2316 TEMPLATE_TYPE_PARM_INDEX (t2
) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t
));
2317 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2
)) = decl
;
2318 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
2319 = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t
), newargs
);
2321 TREE_TYPE (decl
) = t2
;
2322 TYPE_NAME (t2
) = decl
;
2323 TYPE_STUB_DECL (t2
) = decl
;
2325 SET_TYPE_STRUCTURAL_EQUALITY (t2
);
2330 /* Called from count_trees via walk_tree. */
2333 count_trees_r (tree
*tp
, int *walk_subtrees
, void *data
)
2343 /* Debugging function for measuring the rough complexity of a tree
2347 count_trees (tree t
)
2350 cp_walk_tree_without_duplicates (&t
, count_trees_r
, &n_trees
);
2354 /* Called from verify_stmt_tree via walk_tree. */
2357 verify_stmt_tree_r (tree
* tp
, int * /*walk_subtrees*/, void* data
)
2360 hash_table
<nofree_ptr_hash
<tree_node
> > *statements
2361 = static_cast <hash_table
<nofree_ptr_hash
<tree_node
> > *> (data
);
2364 if (!STATEMENT_CODE_P (TREE_CODE (t
)))
2367 /* If this statement is already present in the hash table, then
2368 there is a circularity in the statement tree. */
2369 gcc_assert (!statements
->find (t
));
2371 slot
= statements
->find_slot (t
, INSERT
);
2377 /* Debugging function to check that the statement T has not been
2378 corrupted. For now, this function simply checks that T contains no
2382 verify_stmt_tree (tree t
)
2384 hash_table
<nofree_ptr_hash
<tree_node
> > statements (37);
2385 cp_walk_tree (&t
, verify_stmt_tree_r
, &statements
, NULL
);
2388 /* Check if the type T depends on a type with no linkage and if so, return
2389 it. If RELAXED_P then do not consider a class type declared within
2390 a vague-linkage function to have no linkage. */
2393 no_linkage_check (tree t
, bool relaxed_p
)
2397 /* There's no point in checking linkage on template functions; we
2398 can't know their complete types. */
2399 if (processing_template_decl
)
2402 switch (TREE_CODE (t
))
2405 if (TYPE_PTRMEMFUNC_P (t
))
2407 /* Lambda types that don't have mangling scope have no linkage. We
2408 check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
2409 when we get here from pushtag none of the lambda information is
2410 set up yet, so we want to assume that the lambda has linkage and
2411 fix it up later if not. */
2412 if (CLASSTYPE_LAMBDA_EXPR (t
)
2413 && CLASSTYPE_LAMBDA_EXPR (t
) != error_mark_node
2414 && LAMBDA_TYPE_EXTRA_SCOPE (t
) == NULL_TREE
)
2418 if (!CLASS_TYPE_P (t
))
2422 /* Only treat unnamed types as having no linkage if they're at
2423 namespace scope. This is core issue 966. */
2424 if (TYPE_UNNAMED_P (t
) && TYPE_NAMESPACE_SCOPE_P (t
))
2427 for (r
= CP_TYPE_CONTEXT (t
); ; )
2429 /* If we're a nested type of a !TREE_PUBLIC class, we might not
2430 have linkage, or we might just be in an anonymous namespace.
2431 If we're in a TREE_PUBLIC class, we have linkage. */
2432 if (TYPE_P (r
) && !TREE_PUBLIC (TYPE_NAME (r
)))
2433 return no_linkage_check (TYPE_CONTEXT (t
), relaxed_p
);
2434 else if (TREE_CODE (r
) == FUNCTION_DECL
)
2436 if (!relaxed_p
|| !vague_linkage_p (r
))
2439 r
= CP_DECL_CONTEXT (r
);
2449 case REFERENCE_TYPE
:
2451 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
2455 r
= no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t
),
2459 return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t
), relaxed_p
);
2464 tree parm
= TYPE_ARG_TYPES (t
);
2465 if (TREE_CODE (t
) == METHOD_TYPE
)
2466 /* The 'this' pointer isn't interesting; a method has the same
2467 linkage (or lack thereof) as its enclosing class. */
2468 parm
= TREE_CHAIN (parm
);
2470 parm
&& parm
!= void_list_node
;
2471 parm
= TREE_CHAIN (parm
))
2473 r
= no_linkage_check (TREE_VALUE (parm
), relaxed_p
);
2477 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
2485 extern int depth_reached
;
2488 cxx_print_statistics (void)
2490 print_search_statistics ();
2491 print_class_statistics ();
2492 print_template_statistics ();
2493 if (GATHER_STATISTICS
)
2494 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
2498 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2499 (which is an ARRAY_TYPE). This counts only elements of the top
2503 array_type_nelts_top (tree type
)
2505 return fold_build2_loc (input_location
,
2506 PLUS_EXPR
, sizetype
,
2507 array_type_nelts (type
),
2511 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2512 (which is an ARRAY_TYPE). This one is a recursive count of all
2513 ARRAY_TYPEs that are clumped together. */
2516 array_type_nelts_total (tree type
)
2518 tree sz
= array_type_nelts_top (type
);
2519 type
= TREE_TYPE (type
);
2520 while (TREE_CODE (type
) == ARRAY_TYPE
)
2522 tree n
= array_type_nelts_top (type
);
2523 sz
= fold_build2_loc (input_location
,
2524 MULT_EXPR
, sizetype
, sz
, n
);
2525 type
= TREE_TYPE (type
);
2530 /* Called from break_out_target_exprs via mapcar. */
2533 bot_manip (tree
* tp
, int* walk_subtrees
, void* data
)
2535 splay_tree target_remap
= ((splay_tree
) data
);
2538 if (!TYPE_P (t
) && TREE_CONSTANT (t
) && !TREE_SIDE_EFFECTS (t
))
2540 /* There can't be any TARGET_EXPRs or their slot variables below this
2541 point. But we must make a copy, in case subsequent processing
2542 alters any part of it. For example, during gimplification a cast
2543 of the form (T) &X::f (where "f" is a member function) will lead
2544 to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
2546 *tp
= unshare_expr (t
);
2549 if (TREE_CODE (t
) == TARGET_EXPR
)
2553 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
2555 u
= build_cplus_new (TREE_TYPE (t
), TREE_OPERAND (t
, 1),
2556 tf_warning_or_error
);
2557 if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t
, 1)))
2558 AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u
, 1)) = true;
2561 u
= build_target_expr_with_type (TREE_OPERAND (t
, 1), TREE_TYPE (t
),
2562 tf_warning_or_error
);
2564 TARGET_EXPR_IMPLICIT_P (u
) = TARGET_EXPR_IMPLICIT_P (t
);
2565 TARGET_EXPR_LIST_INIT_P (u
) = TARGET_EXPR_LIST_INIT_P (t
);
2566 TARGET_EXPR_DIRECT_INIT_P (u
) = TARGET_EXPR_DIRECT_INIT_P (t
);
2568 /* Map the old variable to the new one. */
2569 splay_tree_insert (target_remap
,
2570 (splay_tree_key
) TREE_OPERAND (t
, 0),
2571 (splay_tree_value
) TREE_OPERAND (u
, 0));
2573 TREE_OPERAND (u
, 1) = break_out_target_exprs (TREE_OPERAND (u
, 1));
2575 /* Replace the old expression with the new version. */
2577 /* We don't have to go below this point; the recursive call to
2578 break_out_target_exprs will have handled anything below this
2583 if (TREE_CODE (*tp
) == SAVE_EXPR
)
2586 splay_tree_node n
= splay_tree_lookup (target_remap
,
2587 (splay_tree_key
) t
);
2590 *tp
= (tree
)n
->value
;
2595 copy_tree_r (tp
, walk_subtrees
, NULL
);
2596 splay_tree_insert (target_remap
,
2598 (splay_tree_value
)*tp
);
2599 /* Make sure we don't remap an already-remapped SAVE_EXPR. */
2600 splay_tree_insert (target_remap
,
2601 (splay_tree_key
)*tp
,
2602 (splay_tree_value
)*tp
);
2607 /* Make a copy of this node. */
2608 t
= copy_tree_r (tp
, walk_subtrees
, NULL
);
2609 if (TREE_CODE (*tp
) == CALL_EXPR
)
2611 set_flags_from_callee (*tp
);
2613 /* builtin_LINE and builtin_FILE get the location where the default
2614 argument is expanded, not where the call was written. */
2615 tree callee
= get_callee_fndecl (*tp
);
2616 if (callee
&& DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
2617 switch (DECL_FUNCTION_CODE (callee
))
2621 SET_EXPR_LOCATION (*tp
, input_location
);
2629 /* Replace all remapped VAR_DECLs in T with their new equivalents.
2630 DATA is really a splay-tree mapping old variables to new
2634 bot_replace (tree
* t
, int* /*walk_subtrees*/, void* data
)
2636 splay_tree target_remap
= ((splay_tree
) data
);
2640 splay_tree_node n
= splay_tree_lookup (target_remap
,
2641 (splay_tree_key
) *t
);
2643 *t
= (tree
) n
->value
;
2645 else if (TREE_CODE (*t
) == PARM_DECL
2646 && DECL_NAME (*t
) == this_identifier
2647 && !DECL_CONTEXT (*t
))
2649 /* In an NSDMI we need to replace the 'this' parameter we used for
2650 parsing with the real one for this function. */
2651 *t
= current_class_ptr
;
2653 else if (TREE_CODE (*t
) == CONVERT_EXPR
2654 && CONVERT_EXPR_VBASE_PATH (*t
))
2656 /* In an NSDMI build_base_path defers building conversions to virtual
2657 bases, and we handle it here. */
2658 tree basetype
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (*t
)));
2659 vec
<tree
, va_gc
> *vbases
= CLASSTYPE_VBASECLASSES (current_class_type
);
2661 FOR_EACH_VEC_SAFE_ELT (vbases
, i
, binfo
)
2662 if (BINFO_TYPE (binfo
) == basetype
)
2664 *t
= build_base_path (PLUS_EXPR
, TREE_OPERAND (*t
, 0), binfo
, true,
2665 tf_warning_or_error
);
2671 /* When we parse a default argument expression, we may create
2672 temporary variables via TARGET_EXPRs. When we actually use the
2673 default-argument expression, we make a copy of the expression
2674 and replace the temporaries with appropriate local versions. */
2677 break_out_target_exprs (tree t
)
2679 static int target_remap_count
;
2680 static splay_tree target_remap
;
2682 if (!target_remap_count
++)
2683 target_remap
= splay_tree_new (splay_tree_compare_pointers
,
2684 /*splay_tree_delete_key_fn=*/NULL
,
2685 /*splay_tree_delete_value_fn=*/NULL
);
2686 cp_walk_tree (&t
, bot_manip
, target_remap
, NULL
);
2687 cp_walk_tree (&t
, bot_replace
, target_remap
, NULL
);
2689 if (!--target_remap_count
)
2691 splay_tree_delete (target_remap
);
2692 target_remap
= NULL
;
2698 /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
2699 which we expect to have type TYPE. */
2702 build_ctor_subob_ref (tree index
, tree type
, tree obj
)
2704 if (index
== NULL_TREE
)
2705 /* Can't refer to a particular member of a vector. */
2707 else if (TREE_CODE (index
) == INTEGER_CST
)
2708 obj
= cp_build_array_ref (input_location
, obj
, index
, tf_none
);
2710 obj
= build_class_member_access_expr (obj
, index
, NULL_TREE
,
2711 /*reference*/false, tf_none
);
2714 tree objtype
= TREE_TYPE (obj
);
2715 if (TREE_CODE (objtype
) == ARRAY_TYPE
&& !TYPE_DOMAIN (objtype
))
2717 /* When the destination object refers to a flexible array member
2718 verify that it matches the type of the source object except
2719 for its domain and qualifiers. */
2720 gcc_assert (comptypes (TYPE_MAIN_VARIANT (type
),
2721 TYPE_MAIN_VARIANT (objtype
),
2722 COMPARE_REDECLARATION
));
2725 gcc_assert (same_type_ignoring_top_level_qualifiers_p (type
, objtype
));
2731 /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
2732 build up subexpressions as we go deeper. */
2735 replace_placeholders_r (tree
* t
, int* walk_subtrees
, void* data_
)
2737 tree obj
= static_cast<tree
>(data_
);
2739 if (TREE_CONSTANT (*t
))
2741 *walk_subtrees
= false;
2745 switch (TREE_CODE (*t
))
2747 case PLACEHOLDER_EXPR
:
2750 for (; !(same_type_ignoring_top_level_qualifiers_p
2751 (TREE_TYPE (*t
), TREE_TYPE (x
)));
2752 x
= TREE_OPERAND (x
, 0))
2753 gcc_assert (TREE_CODE (x
) == COMPONENT_REF
);
2755 *walk_subtrees
= false;
2761 constructor_elt
*ce
;
2762 vec
<constructor_elt
,va_gc
> *v
= CONSTRUCTOR_ELTS (*t
);
2763 for (unsigned i
= 0; vec_safe_iterate (v
, i
, &ce
); ++i
)
2765 tree
*valp
= &ce
->value
;
2766 tree type
= TREE_TYPE (*valp
);
2769 if (TREE_CODE (*valp
) == CONSTRUCTOR
2770 && AGGREGATE_TYPE_P (type
))
2772 /* If we're looking at the initializer for OBJ, then build
2773 a sub-object reference. If we're looking at an
2774 initializer for another object, just pass OBJ down. */
2775 if (same_type_ignoring_top_level_qualifiers_p
2776 (TREE_TYPE (*t
), TREE_TYPE (obj
)))
2777 subob
= build_ctor_subob_ref (ce
->index
, type
, obj
);
2778 if (TREE_CODE (*valp
) == TARGET_EXPR
)
2779 valp
= &TARGET_EXPR_INITIAL (*valp
);
2782 cp_walk_tree (valp
, replace_placeholders_r
,
2785 *walk_subtrees
= false;
2797 replace_placeholders (tree exp
, tree obj
)
2800 if (TREE_CODE (exp
) == TARGET_EXPR
)
2801 tp
= &TARGET_EXPR_INITIAL (exp
);
2802 cp_walk_tree (tp
, replace_placeholders_r
, obj
, NULL
);
2806 /* Similar to `build_nt', but for template definitions of dependent
2810 build_min_nt_loc (location_t loc
, enum tree_code code
, ...)
2817 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2821 t
= make_node (code
);
2822 SET_EXPR_LOCATION (t
, loc
);
2823 length
= TREE_CODE_LENGTH (code
);
2825 for (i
= 0; i
< length
; i
++)
2827 tree x
= va_arg (p
, tree
);
2828 TREE_OPERAND (t
, i
) = x
;
2836 /* Similar to `build', but for template definitions. */
2839 build_min (enum tree_code code
, tree tt
, ...)
2846 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2850 t
= make_node (code
);
2851 length
= TREE_CODE_LENGTH (code
);
2854 for (i
= 0; i
< length
; i
++)
2856 tree x
= va_arg (p
, tree
);
2857 TREE_OPERAND (t
, i
) = x
;
2858 if (x
&& !TYPE_P (x
) && TREE_SIDE_EFFECTS (x
))
2859 TREE_SIDE_EFFECTS (t
) = 1;
2866 /* Similar to `build', but for template definitions of non-dependent
2867 expressions. NON_DEP is the non-dependent expression that has been
2871 build_min_non_dep (enum tree_code code
, tree non_dep
, ...)
2878 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2880 va_start (p
, non_dep
);
2882 if (REFERENCE_REF_P (non_dep
))
2883 non_dep
= TREE_OPERAND (non_dep
, 0);
2885 t
= make_node (code
);
2886 length
= TREE_CODE_LENGTH (code
);
2887 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
2888 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
2890 for (i
= 0; i
< length
; i
++)
2892 tree x
= va_arg (p
, tree
);
2893 TREE_OPERAND (t
, i
) = x
;
2896 if (code
== COMPOUND_EXPR
&& TREE_CODE (non_dep
) != COMPOUND_EXPR
)
2897 /* This should not be considered a COMPOUND_EXPR, because it
2898 resolves to an overload. */
2899 COMPOUND_EXPR_OVERLOADED (t
) = 1;
2902 return convert_from_reference (t
);
2905 /* Similar to `build_nt_call_vec', but for template definitions of
2906 non-dependent expressions. NON_DEP is the non-dependent expression
2907 that has been built. */
2910 build_min_non_dep_call_vec (tree non_dep
, tree fn
, vec
<tree
, va_gc
> *argvec
)
2912 tree t
= build_nt_call_vec (fn
, argvec
);
2913 if (REFERENCE_REF_P (non_dep
))
2914 non_dep
= TREE_OPERAND (non_dep
, 0);
2915 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
2916 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
2917 return convert_from_reference (t
);
2920 /* Similar to build_min_non_dep, but for expressions that have been resolved to
2921 a call to an operator overload. OP is the operator that has been
2922 overloaded. NON_DEP is the non-dependent expression that's been built,
2923 which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR. OVERLOAD is
2924 the overload that NON_DEP is calling. */
2927 build_min_non_dep_op_overload (enum tree_code op
,
2932 int nargs
, expected_nargs
;
2934 vec
<tree
, va_gc
> *args
;
2936 non_dep
= extract_call_expr (non_dep
);
2938 nargs
= call_expr_nargs (non_dep
);
2940 expected_nargs
= cp_tree_code_length (op
);
2941 if ((op
== POSTINCREMENT_EXPR
2942 || op
== POSTDECREMENT_EXPR
)
2943 /* With -fpermissive non_dep could be operator++(). */
2944 && (!flag_permissive
|| nargs
!= expected_nargs
))
2945 expected_nargs
+= 1;
2946 gcc_assert (nargs
== expected_nargs
);
2948 args
= make_tree_vector ();
2949 va_start (p
, overload
);
2951 if (TREE_CODE (TREE_TYPE (overload
)) == FUNCTION_TYPE
)
2954 for (int i
= 0; i
< nargs
; i
++)
2956 tree arg
= va_arg (p
, tree
);
2957 vec_safe_push (args
, arg
);
2960 else if (TREE_CODE (TREE_TYPE (overload
)) == METHOD_TYPE
)
2962 tree object
= va_arg (p
, tree
);
2963 tree binfo
= TYPE_BINFO (TREE_TYPE (object
));
2964 tree method
= build_baselink (binfo
, binfo
, overload
, NULL_TREE
);
2965 fn
= build_min (COMPONENT_REF
, TREE_TYPE (overload
),
2966 object
, method
, NULL_TREE
);
2967 for (int i
= 1; i
< nargs
; i
++)
2969 tree arg
= va_arg (p
, tree
);
2970 vec_safe_push (args
, arg
);
2977 call
= build_min_non_dep_call_vec (non_dep
, fn
, args
);
2978 release_tree_vector (args
);
2980 tree call_expr
= extract_call_expr (call
);
2981 KOENIG_LOOKUP_P (call_expr
) = KOENIG_LOOKUP_P (non_dep
);
2982 CALL_EXPR_OPERATOR_SYNTAX (call_expr
) = true;
2983 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (non_dep
);
2984 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (non_dep
);
2989 /* Return a new tree vec copied from VEC, with ELT inserted at index IDX. */
2992 vec_copy_and_insert (vec
<tree
, va_gc
> *old_vec
, tree elt
, unsigned idx
)
2994 unsigned len
= vec_safe_length (old_vec
);
2995 gcc_assert (idx
<= len
);
2997 vec
<tree
, va_gc
> *new_vec
= NULL
;
2998 vec_alloc (new_vec
, len
+ 1);
3001 for (i
= 0; i
< len
; ++i
)
3004 new_vec
->quick_push (elt
);
3005 new_vec
->quick_push ((*old_vec
)[i
]);
3008 new_vec
->quick_push (elt
);
3014 get_type_decl (tree t
)
3016 if (TREE_CODE (t
) == TYPE_DECL
)
3019 return TYPE_STUB_DECL (t
);
3020 gcc_assert (t
== error_mark_node
);
3024 /* Returns the namespace that contains DECL, whether directly or
3028 decl_namespace_context (tree decl
)
3032 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3034 else if (TYPE_P (decl
))
3035 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
3037 decl
= CP_DECL_CONTEXT (decl
);
3041 /* Returns true if decl is within an anonymous namespace, however deeply
3042 nested, or false otherwise. */
3045 decl_anon_ns_mem_p (const_tree decl
)
3049 if (decl
== NULL_TREE
|| decl
== error_mark_node
)
3051 if (TREE_CODE (decl
) == NAMESPACE_DECL
3052 && DECL_NAME (decl
) == NULL_TREE
)
3054 /* Classes and namespaces inside anonymous namespaces have
3055 TREE_PUBLIC == 0, so we can shortcut the search. */
3056 else if (TYPE_P (decl
))
3057 return (TREE_PUBLIC (TYPE_MAIN_DECL (decl
)) == 0);
3058 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3059 return (TREE_PUBLIC (decl
) == 0);
3061 decl
= DECL_CONTEXT (decl
);
3065 /* Subroutine of cp_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
3066 CALL_EXPRS. Return whether they are equivalent. */
3069 called_fns_equal (tree t1
, tree t2
)
3071 /* Core 1321: dependent names are equivalent even if the overload sets
3072 are different. But do compare explicit template arguments. */
3073 tree name1
= dependent_name (t1
);
3074 tree name2
= dependent_name (t2
);
3077 tree targs1
= NULL_TREE
, targs2
= NULL_TREE
;
3082 if (TREE_CODE (t1
) == TEMPLATE_ID_EXPR
)
3083 targs1
= TREE_OPERAND (t1
, 1);
3084 if (TREE_CODE (t2
) == TEMPLATE_ID_EXPR
)
3085 targs2
= TREE_OPERAND (t2
, 1);
3086 return cp_tree_equal (targs1
, targs2
);
3089 return cp_tree_equal (t1
, t2
);
3092 /* Return truthvalue of whether T1 is the same tree structure as T2.
3093 Return 1 if they are the same. Return 0 if they are different. */
3096 cp_tree_equal (tree t1
, tree t2
)
3098 enum tree_code code1
, code2
;
3105 code1
= TREE_CODE (t1
);
3106 code2
= TREE_CODE (t2
);
3114 /* There's only a single VOID_CST node, so we should never reach
3119 return tree_int_cst_equal (t1
, t2
);
3122 return real_equal (&TREE_REAL_CST (t1
), &TREE_REAL_CST (t2
));
3125 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3126 && !memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3127 TREE_STRING_LENGTH (t1
));
3130 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
),
3131 TREE_FIXED_CST (t2
));
3134 return cp_tree_equal (TREE_REALPART (t1
), TREE_REALPART (t2
))
3135 && cp_tree_equal (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
));
3138 return operand_equal_p (t1
, t2
, OEP_ONLY_CONST
);
3141 /* We need to do this when determining whether or not two
3142 non-type pointer to member function template arguments
3144 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
3145 || CONSTRUCTOR_NELTS (t1
) != CONSTRUCTOR_NELTS (t2
))
3150 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1
), i
, field
, value
)
3152 constructor_elt
*elt2
= CONSTRUCTOR_ELT (t2
, i
);
3153 if (!cp_tree_equal (field
, elt2
->index
)
3154 || !cp_tree_equal (value
, elt2
->value
))
3161 if (!cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
)))
3163 if (!cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
)))
3165 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
3168 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3173 call_expr_arg_iterator iter1
, iter2
;
3174 if (!called_fns_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
)))
3176 for (arg1
= first_call_expr_arg (t1
, &iter1
),
3177 arg2
= first_call_expr_arg (t2
, &iter2
);
3179 arg1
= next_call_expr_arg (&iter1
),
3180 arg2
= next_call_expr_arg (&iter2
))
3181 if (!cp_tree_equal (arg1
, arg2
))
3190 tree o1
= TREE_OPERAND (t1
, 0);
3191 tree o2
= TREE_OPERAND (t2
, 0);
3193 /* Special case: if either target is an unallocated VAR_DECL,
3194 it means that it's going to be unified with whatever the
3195 TARGET_EXPR is really supposed to initialize, so treat it
3196 as being equivalent to anything. */
3197 if (VAR_P (o1
) && DECL_NAME (o1
) == NULL_TREE
3198 && !DECL_RTL_SET_P (o1
))
3200 else if (VAR_P (o2
) && DECL_NAME (o2
) == NULL_TREE
3201 && !DECL_RTL_SET_P (o2
))
3203 else if (!cp_tree_equal (o1
, o2
))
3206 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
3209 case WITH_CLEANUP_EXPR
:
3210 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
3212 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
3215 if (TREE_OPERAND (t1
, 1) != TREE_OPERAND (t2
, 1))
3217 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3220 /* For comparing uses of parameters in late-specified return types
3221 with an out-of-class definition of the function, but can also come
3222 up for expressions that involve 'this' in a member function
3225 if (comparing_specializations
&& !CONSTRAINT_VAR_P (t1
))
3226 /* When comparing hash table entries, only an exact match is
3227 good enough; we don't want to replace 'this' with the
3228 version from another function. But be more flexible
3229 with local parameters in a requires-expression. */
3232 if (same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3234 if (DECL_ARTIFICIAL (t1
) ^ DECL_ARTIFICIAL (t2
))
3236 if (CONSTRAINT_VAR_P (t1
) ^ CONSTRAINT_VAR_P (t2
))
3238 if (DECL_ARTIFICIAL (t1
)
3239 || (DECL_PARM_LEVEL (t1
) == DECL_PARM_LEVEL (t2
)
3240 && DECL_PARM_INDEX (t1
) == DECL_PARM_INDEX (t2
)))
3250 case IDENTIFIER_NODE
:
3255 return (BASELINK_BINFO (t1
) == BASELINK_BINFO (t2
)
3256 && BASELINK_ACCESS_BINFO (t1
) == BASELINK_ACCESS_BINFO (t2
)
3257 && BASELINK_QUALIFIED_P (t1
) == BASELINK_QUALIFIED_P (t2
)
3258 && cp_tree_equal (BASELINK_FUNCTIONS (t1
),
3259 BASELINK_FUNCTIONS (t2
)));
3261 case TEMPLATE_PARM_INDEX
:
3262 return (TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
3263 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
)
3264 && (TEMPLATE_PARM_PARAMETER_PACK (t1
)
3265 == TEMPLATE_PARM_PARAMETER_PACK (t2
))
3266 && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1
)),
3267 TREE_TYPE (TEMPLATE_PARM_DECL (t2
))));
3269 case TEMPLATE_ID_EXPR
:
3270 return (cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3271 && cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3273 case CONSTRAINT_INFO
:
3274 return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1
),
3275 CI_ASSOCIATED_CONSTRAINTS (t2
));
3278 return (CHECK_CONSTR_CONCEPT (t1
) == CHECK_CONSTR_CONCEPT (t2
)
3279 && comp_template_args (CHECK_CONSTR_ARGS (t1
),
3280 CHECK_CONSTR_ARGS (t2
)));
3285 if (TREE_VEC_LENGTH (t1
) != TREE_VEC_LENGTH (t2
))
3287 for (ix
= TREE_VEC_LENGTH (t1
); ix
--;)
3288 if (!cp_tree_equal (TREE_VEC_ELT (t1
, ix
),
3289 TREE_VEC_ELT (t2
, ix
)))
3297 tree o1
= TREE_OPERAND (t1
, 0);
3298 tree o2
= TREE_OPERAND (t2
, 0);
3300 if (code1
== SIZEOF_EXPR
)
3302 if (SIZEOF_EXPR_TYPE_P (t1
))
3303 o1
= TREE_TYPE (o1
);
3304 if (SIZEOF_EXPR_TYPE_P (t2
))
3305 o2
= TREE_TYPE (o2
);
3307 if (TREE_CODE (o1
) != TREE_CODE (o2
))
3310 return same_type_p (o1
, o2
);
3312 return cp_tree_equal (o1
, o2
);
3317 tree t1_op1
, t2_op1
;
3319 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
3322 t1_op1
= TREE_OPERAND (t1
, 1);
3323 t2_op1
= TREE_OPERAND (t2
, 1);
3324 if (TREE_CODE (t1_op1
) != TREE_CODE (t2_op1
))
3327 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t2
, 2));
3331 /* Two pointer-to-members are the same if they point to the same
3332 field or function in the same class. */
3333 if (PTRMEM_CST_MEMBER (t1
) != PTRMEM_CST_MEMBER (t2
))
3336 return same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
));
3339 if (OVL_FUNCTION (t1
) != OVL_FUNCTION (t2
))
3341 return cp_tree_equal (OVL_CHAIN (t1
), OVL_CHAIN (t2
));
3344 if (TRAIT_EXPR_KIND (t1
) != TRAIT_EXPR_KIND (t2
))
3346 return same_type_p (TRAIT_EXPR_TYPE1 (t1
), TRAIT_EXPR_TYPE1 (t2
))
3347 && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1
), TRAIT_EXPR_TYPE2 (t2
));
3350 case STATIC_CAST_EXPR
:
3351 case REINTERPRET_CAST_EXPR
:
3352 case CONST_CAST_EXPR
:
3353 case DYNAMIC_CAST_EXPR
:
3354 case IMPLICIT_CONV_EXPR
:
3357 case NON_LVALUE_EXPR
:
3358 case VIEW_CONVERT_EXPR
:
3359 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3361 /* Now compare operands as usual. */
3364 case DEFERRED_NOEXCEPT
:
3365 return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1
),
3366 DEFERRED_NOEXCEPT_PATTERN (t2
))
3367 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1
),
3368 DEFERRED_NOEXCEPT_ARGS (t2
)));
3375 switch (TREE_CODE_CLASS (code1
))
3379 case tcc_comparison
:
3380 case tcc_expression
:
3387 n
= cp_tree_operand_length (t1
);
3388 if (TREE_CODE_CLASS (code1
) == tcc_vl_exp
3389 && n
!= TREE_OPERAND_LENGTH (t2
))
3392 for (i
= 0; i
< n
; ++i
)
3393 if (!cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
)))
3400 return same_type_p (t1
, t2
);
3404 /* We can get here with --disable-checking. */
3408 /* The type of ARG when used as an lvalue. */
3411 lvalue_type (tree arg
)
3413 tree type
= TREE_TYPE (arg
);
3417 /* The type of ARG for printing error messages; denote lvalues with
3421 error_type (tree arg
)
3423 tree type
= TREE_TYPE (arg
);
3425 if (TREE_CODE (type
) == ARRAY_TYPE
)
3427 else if (TREE_CODE (type
) == ERROR_MARK
)
3429 else if (lvalue_p (arg
))
3430 type
= build_reference_type (lvalue_type (arg
));
3431 else if (MAYBE_CLASS_TYPE_P (type
))
3432 type
= lvalue_type (arg
);
3437 /* Does FUNCTION use a variable-length argument list? */
3440 varargs_function_p (const_tree function
)
3442 return stdarg_p (TREE_TYPE (function
));
3445 /* Returns 1 if decl is a member of a class. */
3448 member_p (const_tree decl
)
3450 const_tree
const ctx
= DECL_CONTEXT (decl
);
3451 return (ctx
&& TYPE_P (ctx
));
3454 /* Create a placeholder for member access where we don't actually have an
3455 object that the access is against. */
3458 build_dummy_object (tree type
)
3460 tree decl
= build1 (CONVERT_EXPR
, build_pointer_type (type
), void_node
);
3461 return cp_build_indirect_ref (decl
, RO_NULL
, tf_warning_or_error
);
3464 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
3465 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
3466 binfo path from current_class_type to TYPE, or 0. */
3469 maybe_dummy_object (tree type
, tree
* binfop
)
3473 tree current
= current_nonlambda_class_type ();
3476 && (binfo
= lookup_base (current
, type
, ba_any
, NULL
,
3477 tf_warning_or_error
)))
3481 /* Reference from a nested class member function. */
3483 binfo
= TYPE_BINFO (type
);
3489 if (current_class_ref
3490 /* current_class_ref might not correspond to current_class_type if
3491 we're in tsubst_default_argument or a lambda-declarator; in either
3492 case, we want to use current_class_ref if it matches CONTEXT. */
3493 && (same_type_ignoring_top_level_qualifiers_p
3494 (TREE_TYPE (current_class_ref
), context
)))
3495 decl
= current_class_ref
;
3497 decl
= build_dummy_object (context
);
3502 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
3505 is_dummy_object (const_tree ob
)
3507 if (INDIRECT_REF_P (ob
))
3508 ob
= TREE_OPERAND (ob
, 0);
3509 return (TREE_CODE (ob
) == CONVERT_EXPR
3510 && TREE_OPERAND (ob
, 0) == void_node
);
3513 /* Returns 1 iff type T is something we want to treat as a scalar type for
3514 the purpose of deciding whether it is trivial/POD/standard-layout. */
3517 scalarish_type_p (const_tree t
)
3519 if (t
== error_mark_node
)
3522 return (SCALAR_TYPE_P (t
) || VECTOR_TYPE_P (t
));
3525 /* Returns true iff T requires non-trivial default initialization. */
3528 type_has_nontrivial_default_init (const_tree t
)
3530 t
= strip_array_types (CONST_CAST_TREE (t
));
3532 if (CLASS_TYPE_P (t
))
3533 return TYPE_HAS_COMPLEX_DFLT (t
);
3538 /* Returns true iff copying an object of type T (including via move
3539 constructor) is non-trivial. That is, T has no non-trivial copy
3540 constructors and no non-trivial move constructors. */
3543 type_has_nontrivial_copy_init (const_tree t
)
3545 t
= strip_array_types (CONST_CAST_TREE (t
));
3547 if (CLASS_TYPE_P (t
))
3549 gcc_assert (COMPLETE_TYPE_P (t
));
3550 return ((TYPE_HAS_COPY_CTOR (t
)
3551 && TYPE_HAS_COMPLEX_COPY_CTOR (t
))
3552 || TYPE_HAS_COMPLEX_MOVE_CTOR (t
));
3558 /* Returns 1 iff type T is a trivially copyable type, as defined in
3559 [basic.types] and [class]. */
3562 trivially_copyable_p (const_tree t
)
3564 t
= strip_array_types (CONST_CAST_TREE (t
));
3566 if (CLASS_TYPE_P (t
))
3567 return ((!TYPE_HAS_COPY_CTOR (t
)
3568 || !TYPE_HAS_COMPLEX_COPY_CTOR (t
))
3569 && !TYPE_HAS_COMPLEX_MOVE_CTOR (t
)
3570 && (!TYPE_HAS_COPY_ASSIGN (t
)
3571 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t
))
3572 && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t
)
3573 && TYPE_HAS_TRIVIAL_DESTRUCTOR (t
));
3575 return !CP_TYPE_VOLATILE_P (t
) && scalarish_type_p (t
);
3578 /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
3582 trivial_type_p (const_tree t
)
3584 t
= strip_array_types (CONST_CAST_TREE (t
));
3586 if (CLASS_TYPE_P (t
))
3587 return (TYPE_HAS_TRIVIAL_DFLT (t
)
3588 && trivially_copyable_p (t
));
3590 return scalarish_type_p (t
);
3593 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
3596 pod_type_p (const_tree t
)
3598 /* This CONST_CAST is okay because strip_array_types returns its
3599 argument unmodified and we assign it to a const_tree. */
3600 t
= strip_array_types (CONST_CAST_TREE(t
));
3602 if (!CLASS_TYPE_P (t
))
3603 return scalarish_type_p (t
);
3604 else if (cxx_dialect
> cxx98
)
3605 /* [class]/10: A POD struct is a class that is both a trivial class and a
3606 standard-layout class, and has no non-static data members of type
3607 non-POD struct, non-POD union (or array of such types).
3609 We don't need to check individual members because if a member is
3610 non-std-layout or non-trivial, the class will be too. */
3611 return (std_layout_type_p (t
) && trivial_type_p (t
));
3613 /* The C++98 definition of POD is different. */
3614 return !CLASSTYPE_NON_LAYOUT_POD_P (t
);
3617 /* Returns true iff T is POD for the purpose of layout, as defined in the
3621 layout_pod_type_p (const_tree t
)
3623 t
= strip_array_types (CONST_CAST_TREE (t
));
3625 if (CLASS_TYPE_P (t
))
3626 return !CLASSTYPE_NON_LAYOUT_POD_P (t
);
3628 return scalarish_type_p (t
);
3631 /* Returns true iff T is a standard-layout type, as defined in
3635 std_layout_type_p (const_tree t
)
3637 t
= strip_array_types (CONST_CAST_TREE (t
));
3639 if (CLASS_TYPE_P (t
))
3640 return !CLASSTYPE_NON_STD_LAYOUT (t
);
3642 return scalarish_type_p (t
);
3645 static bool record_has_unique_obj_representations (const_tree
, const_tree
);
3647 /* Returns true iff T satisfies std::has_unique_object_representations<T>,
3648 as defined in [meta.unary.prop]. */
3651 type_has_unique_obj_representations (const_tree t
)
3655 t
= strip_array_types (CONST_CAST_TREE (t
));
3657 if (!trivially_copyable_p (t
))
3660 if (CLASS_TYPE_P (t
) && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t
))
3661 return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t
);
3663 switch (TREE_CODE (t
))
3667 case REFERENCE_TYPE
:
3668 /* If some backend has any paddings in these types, we should add
3669 a target hook for this and handle it there. */
3673 /* For bool values other than 0 and 1 should only appear with
3674 undefined behavior. */
3678 return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t
));
3681 /* XFmode certainly contains padding on x86, which the CPU doesn't store
3682 when storing long double values, so for that we have to return false.
3683 Other kinds of floating point values are questionable due to +.0/-.0
3684 and NaNs, let's play safe for now. */
3687 case FIXED_POINT_TYPE
:
3695 return type_has_unique_obj_representations (TREE_TYPE (t
));
3698 ret
= record_has_unique_obj_representations (t
, TYPE_SIZE (t
));
3699 if (CLASS_TYPE_P (t
))
3701 CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t
) = 1;
3702 CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t
) = ret
;
3710 for (tree field
= TYPE_FIELDS (t
); field
; field
= DECL_CHAIN (field
))
3711 if (TREE_CODE (field
) == FIELD_DECL
)
3714 if (!type_has_unique_obj_representations (TREE_TYPE (field
))
3715 || simple_cst_equal (DECL_SIZE (field
), TYPE_SIZE (t
)) != 1)
3721 if (!any_fields
&& !integer_zerop (TYPE_SIZE (t
)))
3723 if (CLASS_TYPE_P (t
))
3725 CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t
) = 1;
3726 CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t
) = ret
;
3741 /* Helper function for type_has_unique_obj_representations. */
3744 record_has_unique_obj_representations (const_tree t
, const_tree sz
)
3746 for (tree field
= TYPE_FIELDS (t
); field
; field
= DECL_CHAIN (field
))
3747 if (TREE_CODE (field
) != FIELD_DECL
)
3749 /* For bases, can't use type_has_unique_obj_representations here, as in
3750 struct S { int i : 24; S (); };
3751 struct T : public S { int j : 8; T (); };
3752 S doesn't have unique obj representations, but T does. */
3753 else if (DECL_FIELD_IS_BASE (field
))
3755 if (!record_has_unique_obj_representations (TREE_TYPE (field
),
3759 else if (DECL_C_BIT_FIELD (field
))
3761 tree btype
= DECL_BIT_FIELD_TYPE (field
);
3762 if (!type_has_unique_obj_representations (btype
))
3765 else if (!type_has_unique_obj_representations (TREE_TYPE (field
)))
3769 for (tree field
= TYPE_FIELDS (t
); field
; field
= DECL_CHAIN (field
))
3770 if (TREE_CODE (field
) == FIELD_DECL
)
3772 offset_int fld
= wi::to_offset (DECL_FIELD_OFFSET (field
));
3773 offset_int bitpos
= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
3774 fld
= fld
* BITS_PER_UNIT
+ bitpos
;
3777 if (DECL_SIZE (field
))
3779 offset_int size
= wi::to_offset (DECL_SIZE (field
));
3783 if (cur
!= wi::to_offset (sz
))
3789 /* Nonzero iff type T is a class template implicit specialization. */
3792 class_tmpl_impl_spec_p (const_tree t
)
3794 return CLASS_TYPE_P (t
) && CLASSTYPE_TEMPLATE_INSTANTIATION (t
);
3797 /* Returns 1 iff zero initialization of type T means actually storing
3801 zero_init_p (const_tree t
)
3803 /* This CONST_CAST is okay because strip_array_types returns its
3804 argument unmodified and we assign it to a const_tree. */
3805 t
= strip_array_types (CONST_CAST_TREE(t
));
3807 if (t
== error_mark_node
)
3810 /* NULL pointers to data members are initialized with -1. */
3811 if (TYPE_PTRDATAMEM_P (t
))
3814 /* Classes that contain types that can't be zero-initialized, cannot
3815 be zero-initialized themselves. */
3816 if (CLASS_TYPE_P (t
) && CLASSTYPE_NON_ZERO_INIT_P (t
))
3822 /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
3823 warn_unused_result attribute. */
3826 handle_nodiscard_attribute (tree
*node
, tree name
, tree
/*args*/,
3827 int /*flags*/, bool *no_add_attrs
)
3829 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3831 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
3832 warning (OPT_Wattributes
, "%qE attribute applied to %qD with void "
3833 "return type", name
, *node
);
3835 else if (OVERLOAD_TYPE_P (*node
))
3839 warning (OPT_Wattributes
, "%qE attribute can only be applied to "
3840 "functions or to class or enumeration types", name
);
3841 *no_add_attrs
= true;
3846 /* Table of valid C++ attributes. */
3847 const struct attribute_spec cxx_attribute_table
[] =
3849 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3850 affects_type_identity } */
3851 { "init_priority", 1, 1, true, false, false,
3852 handle_init_priority_attribute
, false },
3853 { "abi_tag", 1, -1, false, false, false,
3854 handle_abi_tag_attribute
, true },
3855 { NULL
, 0, 0, false, false, false, NULL
, false }
3858 /* Table of C++ standard attributes. */
3859 const struct attribute_spec std_attribute_table
[] =
3861 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3862 affects_type_identity } */
3863 { "maybe_unused", 0, 0, false, false, false,
3864 handle_unused_attribute
, false },
3865 { "nodiscard", 0, 0, false, false, false,
3866 handle_nodiscard_attribute
, false },
3867 { NULL
, 0, 0, false, false, false, NULL
, false }
3870 /* Handle an "init_priority" attribute; arguments as in
3871 struct attribute_spec.handler. */
3873 handle_init_priority_attribute (tree
* node
,
3879 tree initp_expr
= TREE_VALUE (args
);
3881 tree type
= TREE_TYPE (decl
);
3884 STRIP_NOPS (initp_expr
);
3885 initp_expr
= default_conversion (initp_expr
);
3887 initp_expr
= maybe_constant_value (initp_expr
);
3889 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
3891 error ("requested init_priority is not an integer constant");
3892 cxx_constant_value (initp_expr
);
3893 *no_add_attrs
= true;
3897 pri
= TREE_INT_CST_LOW (initp_expr
);
3899 type
= strip_array_types (type
);
3901 if (decl
== NULL_TREE
3903 || !TREE_STATIC (decl
)
3904 || DECL_EXTERNAL (decl
)
3905 || (TREE_CODE (type
) != RECORD_TYPE
3906 && TREE_CODE (type
) != UNION_TYPE
)
3907 /* Static objects in functions are initialized the
3908 first time control passes through that
3909 function. This is not precise enough to pin down an
3910 init_priority value, so don't allow it. */
3911 || current_function_decl
)
3913 error ("can only use %qE attribute on file-scope definitions "
3914 "of objects of class type", name
);
3915 *no_add_attrs
= true;
3919 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
3921 error ("requested init_priority is out of range");
3922 *no_add_attrs
= true;
3926 /* Check for init_priorities that are reserved for
3927 language and runtime support implementations.*/
3928 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
3931 (0, "requested init_priority is reserved for internal use");
3934 if (SUPPORTS_INIT_PRIORITY
)
3936 SET_DECL_INIT_PRIORITY (decl
, pri
);
3937 DECL_HAS_INIT_PRIORITY_P (decl
) = 1;
3942 error ("%qE attribute is not supported on this platform", name
);
3943 *no_add_attrs
= true;
3948 /* DECL is being redeclared; the old declaration had the abi tags in OLD,
3949 and the new one has the tags in NEW_. Give an error if there are tags
3950 in NEW_ that weren't in OLD. */
3953 check_abi_tag_redeclaration (const_tree decl
, const_tree old
, const_tree new_
)
3955 if (old
&& TREE_CODE (TREE_VALUE (old
)) == TREE_LIST
)
3956 old
= TREE_VALUE (old
);
3957 if (new_
&& TREE_CODE (TREE_VALUE (new_
)) == TREE_LIST
)
3958 new_
= TREE_VALUE (new_
);
3960 for (const_tree t
= new_
; t
; t
= TREE_CHAIN (t
))
3962 tree str
= TREE_VALUE (t
);
3963 for (const_tree in
= old
; in
; in
= TREE_CHAIN (in
))
3965 tree ostr
= TREE_VALUE (in
);
3966 if (cp_tree_equal (str
, ostr
))
3969 error ("redeclaration of %qD adds abi tag %E", decl
, str
);
3975 inform (DECL_SOURCE_LOCATION (decl
), "previous declaration here");
3981 /* The abi_tag attribute with the name NAME was given ARGS. If they are
3982 ill-formed, give an error and return false; otherwise, return true. */
3985 check_abi_tag_args (tree args
, tree name
)
3989 error ("the %qE attribute requires arguments", name
);
3992 for (tree arg
= args
; arg
; arg
= TREE_CHAIN (arg
))
3994 tree elt
= TREE_VALUE (arg
);
3995 if (TREE_CODE (elt
) != STRING_CST
3996 || (!same_type_ignoring_top_level_qualifiers_p
3997 (strip_array_types (TREE_TYPE (elt
)),
4000 error ("arguments to the %qE attribute must be narrow string "
4004 const char *begin
= TREE_STRING_POINTER (elt
);
4005 const char *end
= begin
+ TREE_STRING_LENGTH (elt
);
4006 for (const char *p
= begin
; p
!= end
; ++p
)
4011 if (!ISALPHA (c
) && c
!= '_')
4013 error ("arguments to the %qE attribute must contain valid "
4014 "identifiers", name
);
4015 inform (input_location
, "%<%c%> is not a valid first "
4016 "character for an identifier", c
);
4020 else if (p
== end
- 1)
4021 gcc_assert (c
== 0);
4024 if (!ISALNUM (c
) && c
!= '_')
4026 error ("arguments to the %qE attribute must contain valid "
4027 "identifiers", name
);
4028 inform (input_location
, "%<%c%> is not a valid character "
4029 "in an identifier", c
);
4038 /* Handle an "abi_tag" attribute; arguments as in
4039 struct attribute_spec.handler. */
4042 handle_abi_tag_attribute (tree
* node
, tree name
, tree args
,
4043 int flags
, bool* no_add_attrs
)
4045 if (!check_abi_tag_args (args
, name
))
4050 if (!OVERLOAD_TYPE_P (*node
))
4052 error ("%qE attribute applied to non-class, non-enum type %qT",
4056 else if (!(flags
& (int)ATTR_FLAG_TYPE_IN_PLACE
))
4058 error ("%qE attribute applied to %qT after its definition",
4062 else if (CLASS_TYPE_P (*node
)
4063 && CLASSTYPE_TEMPLATE_INSTANTIATION (*node
))
4065 warning (OPT_Wattributes
, "ignoring %qE attribute applied to "
4066 "template instantiation %qT", name
, *node
);
4069 else if (CLASS_TYPE_P (*node
)
4070 && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node
))
4072 warning (OPT_Wattributes
, "ignoring %qE attribute applied to "
4073 "template specialization %qT", name
, *node
);
4077 tree attributes
= TYPE_ATTRIBUTES (*node
);
4078 tree decl
= TYPE_NAME (*node
);
4080 /* Make sure all declarations have the same abi tags. */
4081 if (DECL_SOURCE_LOCATION (decl
) != input_location
)
4083 if (!check_abi_tag_redeclaration (decl
,
4084 lookup_attribute ("abi_tag",
4092 if (!VAR_OR_FUNCTION_DECL_P (*node
))
4094 error ("%qE attribute applied to non-function, non-variable %qD",
4098 else if (DECL_LANGUAGE (*node
) == lang_c
)
4100 error ("%qE attribute applied to extern \"C\" declaration %qD",
4109 *no_add_attrs
= true;
4113 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
4114 thing pointed to by the constant. */
4117 make_ptrmem_cst (tree type
, tree member
)
4119 tree ptrmem_cst
= make_node (PTRMEM_CST
);
4120 TREE_TYPE (ptrmem_cst
) = type
;
4121 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
4125 /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
4126 return an existing type if an appropriate type already exists. */
4129 cp_build_type_attribute_variant (tree type
, tree attributes
)
4133 new_type
= build_type_attribute_variant (type
, attributes
);
4134 if (TREE_CODE (new_type
) == FUNCTION_TYPE
4135 || TREE_CODE (new_type
) == METHOD_TYPE
)
4137 new_type
= build_exception_variant (new_type
,
4138 TYPE_RAISES_EXCEPTIONS (type
));
4139 new_type
= build_ref_qualified_type (new_type
,
4140 type_memfn_rqual (type
));
4143 /* Making a new main variant of a class type is broken. */
4144 gcc_assert (!CLASS_TYPE_P (type
) || new_type
== type
);
4149 /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
4150 Called only after doing all language independent checks. */
4153 cxx_type_hash_eq (const_tree typea
, const_tree typeb
)
4155 gcc_assert (TREE_CODE (typea
) == FUNCTION_TYPE
4156 || TREE_CODE (typea
) == METHOD_TYPE
);
4158 if (type_memfn_rqual (typea
) != type_memfn_rqual (typeb
))
4160 return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea
),
4161 TYPE_RAISES_EXCEPTIONS (typeb
), ce_exact
);
4164 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
4165 traversal. Called from walk_tree. */
4168 cp_walk_subtrees (tree
*tp
, int *walk_subtrees_p
, walk_tree_fn func
,
4169 void *data
, hash_set
<tree
> *pset
)
4171 enum tree_code code
= TREE_CODE (*tp
);
4174 #define WALK_SUBTREE(NODE) \
4177 result = cp_walk_tree (&(NODE), func, data, pset); \
4178 if (result) goto out; \
4182 /* Not one of the easy cases. We must explicitly go through the
4188 case TEMPLATE_TEMPLATE_PARM
:
4189 case BOUND_TEMPLATE_TEMPLATE_PARM
:
4190 case UNBOUND_CLASS_TEMPLATE
:
4191 case TEMPLATE_PARM_INDEX
:
4192 case TEMPLATE_TYPE_PARM
:
4195 case UNDERLYING_TYPE
:
4196 /* None of these have subtrees other than those already walked
4198 *walk_subtrees_p
= 0;
4202 WALK_SUBTREE (BASELINK_FUNCTIONS (*tp
));
4203 *walk_subtrees_p
= 0;
4207 WALK_SUBTREE (TREE_TYPE (*tp
));
4208 *walk_subtrees_p
= 0;
4212 WALK_SUBTREE (TREE_PURPOSE (*tp
));
4216 WALK_SUBTREE (OVL_FUNCTION (*tp
));
4217 WALK_SUBTREE (OVL_CHAIN (*tp
));
4218 *walk_subtrees_p
= 0;
4222 WALK_SUBTREE (DECL_NAME (*tp
));
4223 WALK_SUBTREE (USING_DECL_SCOPE (*tp
));
4224 WALK_SUBTREE (USING_DECL_DECLS (*tp
));
4225 *walk_subtrees_p
= 0;
4229 if (TYPE_PTRMEMFUNC_P (*tp
))
4230 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (*tp
));
4233 case TYPE_ARGUMENT_PACK
:
4234 case NONTYPE_ARGUMENT_PACK
:
4236 tree args
= ARGUMENT_PACK_ARGS (*tp
);
4237 int i
, len
= TREE_VEC_LENGTH (args
);
4238 for (i
= 0; i
< len
; i
++)
4239 WALK_SUBTREE (TREE_VEC_ELT (args
, i
));
4243 case TYPE_PACK_EXPANSION
:
4244 WALK_SUBTREE (TREE_TYPE (*tp
));
4245 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp
));
4246 *walk_subtrees_p
= 0;
4249 case EXPR_PACK_EXPANSION
:
4250 WALK_SUBTREE (TREE_OPERAND (*tp
, 0));
4251 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp
));
4252 *walk_subtrees_p
= 0;
4256 case REINTERPRET_CAST_EXPR
:
4257 case STATIC_CAST_EXPR
:
4258 case CONST_CAST_EXPR
:
4259 case DYNAMIC_CAST_EXPR
:
4260 case IMPLICIT_CONV_EXPR
:
4261 if (TREE_TYPE (*tp
))
4262 WALK_SUBTREE (TREE_TYPE (*tp
));
4266 for (i
= 0; i
< TREE_CODE_LENGTH (TREE_CODE (*tp
)); ++i
)
4267 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
4269 *walk_subtrees_p
= 0;
4273 WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp
));
4274 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp
));
4275 *walk_subtrees_p
= 0;
4279 WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp
));
4280 *walk_subtrees_p
= 0;
4284 // Only recurse through the nested expression. Do not
4285 // walk the parameter list. Doing so causes false
4286 // positives in the pack expansion checker since the
4287 // requires parameters are introduced as pack expansions.
4288 WALK_SUBTREE (TREE_OPERAND (*tp
, 1));
4289 *walk_subtrees_p
= 0;
4293 /* User variables should be mentioned in BIND_EXPR_VARS
4294 and their initializers and sizes walked when walking
4295 the containing BIND_EXPR. Compiler temporaries are
4297 if (VAR_P (TREE_OPERAND (*tp
, 0))
4298 && DECL_ARTIFICIAL (TREE_OPERAND (*tp
, 0))
4299 && !TREE_STATIC (TREE_OPERAND (*tp
, 0)))
4301 tree decl
= TREE_OPERAND (*tp
, 0);
4302 WALK_SUBTREE (DECL_INITIAL (decl
));
4303 WALK_SUBTREE (DECL_SIZE (decl
));
4304 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
4312 /* We didn't find what we were looking for. */
4319 /* Like save_expr, but for C++. */
4322 cp_save_expr (tree expr
)
4324 /* There is no reason to create a SAVE_EXPR within a template; if
4325 needed, we can create the SAVE_EXPR when instantiating the
4326 template. Furthermore, the middle-end cannot handle C++-specific
4328 if (processing_template_decl
)
4330 return save_expr (expr
);
4333 /* Initialize tree.c. */
4338 list_hash_table
= hash_table
<list_hasher
>::create_ggc (61);
4339 register_scoped_attributes (std_attribute_table
, NULL
);
4342 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
4343 is. Note that sfk_none is zero, so this function can be used as a
4344 predicate to test whether or not DECL is a special function. */
4346 special_function_kind
4347 special_function_p (const_tree decl
)
4349 /* Rather than doing all this stuff with magic names, we should
4350 probably have a field of type `special_function_kind' in
4351 DECL_LANG_SPECIFIC. */
4352 if (DECL_INHERITED_CTOR (decl
))
4353 return sfk_inheriting_constructor
;
4354 if (DECL_COPY_CONSTRUCTOR_P (decl
))
4355 return sfk_copy_constructor
;
4356 if (DECL_MOVE_CONSTRUCTOR_P (decl
))
4357 return sfk_move_constructor
;
4358 if (DECL_CONSTRUCTOR_P (decl
))
4359 return sfk_constructor
;
4360 if (DECL_OVERLOADED_OPERATOR_P (decl
) == NOP_EXPR
)
4362 if (copy_fn_p (decl
))
4363 return sfk_copy_assignment
;
4364 if (move_fn_p (decl
))
4365 return sfk_move_assignment
;
4367 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
))
4368 return sfk_destructor
;
4369 if (DECL_COMPLETE_DESTRUCTOR_P (decl
))
4370 return sfk_complete_destructor
;
4371 if (DECL_BASE_DESTRUCTOR_P (decl
))
4372 return sfk_base_destructor
;
4373 if (DECL_DELETING_DESTRUCTOR_P (decl
))
4374 return sfk_deleting_destructor
;
4375 if (DECL_CONV_FN_P (decl
))
4376 return sfk_conversion
;
4381 /* Returns nonzero if TYPE is a character type, including wchar_t. */
4384 char_type_p (tree type
)
4386 return (same_type_p (type
, char_type_node
)
4387 || same_type_p (type
, unsigned_char_type_node
)
4388 || same_type_p (type
, signed_char_type_node
)
4389 || same_type_p (type
, char16_type_node
)
4390 || same_type_p (type
, char32_type_node
)
4391 || same_type_p (type
, wchar_type_node
));
4394 /* Returns the kind of linkage associated with the indicated DECL. Th
4395 value returned is as specified by the language standard; it is
4396 independent of implementation details regarding template
4397 instantiation, etc. For example, it is possible that a declaration
4398 to which this function assigns external linkage would not show up
4399 as a global symbol when you run `nm' on the resulting object file. */
4402 decl_linkage (tree decl
)
4404 /* This function doesn't attempt to calculate the linkage from first
4405 principles as given in [basic.link]. Instead, it makes use of
4406 the fact that we have already set TREE_PUBLIC appropriately, and
4407 then handles a few special cases. Ideally, we would calculate
4408 linkage first, and then transform that into a concrete
4411 /* Things that don't have names have no linkage. */
4412 if (!DECL_NAME (decl
))
4415 /* Fields have no linkage. */
4416 if (TREE_CODE (decl
) == FIELD_DECL
)
4419 /* Things that are TREE_PUBLIC have external linkage. */
4420 if (TREE_PUBLIC (decl
))
4423 /* maybe_thunk_body clears TREE_PUBLIC on the maybe-in-charge 'tor variants,
4424 check one of the "clones" for the real linkage. */
4425 if ((DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
)
4426 || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl
))
4427 && DECL_CHAIN (decl
)
4428 && DECL_CLONED_FUNCTION (DECL_CHAIN (decl
)))
4429 return decl_linkage (DECL_CHAIN (decl
));
4431 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
4434 /* Linkage of a CONST_DECL depends on the linkage of the enumeration
4436 if (TREE_CODE (decl
) == CONST_DECL
)
4437 return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl
)));
4439 /* Things in local scope do not have linkage, if they don't have
4441 if (decl_function_context (decl
))
4444 /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
4445 are considered to have external linkage for language purposes, as do
4446 template instantiations on targets without weak symbols. DECLs really
4447 meant to have internal linkage have DECL_THIS_STATIC set. */
4448 if (TREE_CODE (decl
) == TYPE_DECL
)
4450 if (VAR_OR_FUNCTION_DECL_P (decl
))
4452 if (!DECL_THIS_STATIC (decl
))
4455 /* Static data members and static member functions from classes
4456 in anonymous namespace also don't have TREE_PUBLIC set. */
4457 if (DECL_CLASS_CONTEXT (decl
))
4461 /* Everything else has internal linkage. */
4465 /* Returns the storage duration of the object or reference associated with
4466 the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
4469 decl_storage_duration (tree decl
)
4471 if (TREE_CODE (decl
) == PARM_DECL
)
4473 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4475 gcc_assert (VAR_P (decl
));
4476 if (!TREE_STATIC (decl
)
4477 && !DECL_EXTERNAL (decl
))
4479 if (CP_DECL_THREAD_LOCAL_P (decl
))
4484 /* EXP is an expression that we want to pre-evaluate. Returns (in
4485 *INITP) an expression that will perform the pre-evaluation. The
4486 value returned by this function is a side-effect free expression
4487 equivalent to the pre-evaluated expression. Callers must ensure
4488 that *INITP is evaluated before EXP. */
4491 stabilize_expr (tree exp
, tree
* initp
)
4495 if (!TREE_SIDE_EFFECTS (exp
))
4496 init_expr
= NULL_TREE
;
4497 else if (VOID_TYPE_P (TREE_TYPE (exp
)))
4502 /* There are no expressions with REFERENCE_TYPE, but there can be call
4503 arguments with such a type; just treat it as a pointer. */
4504 else if (TREE_CODE (TREE_TYPE (exp
)) == REFERENCE_TYPE
4505 || SCALAR_TYPE_P (TREE_TYPE (exp
))
4506 || !glvalue_p (exp
))
4508 init_expr
= get_target_expr (exp
);
4509 exp
= TARGET_EXPR_SLOT (init_expr
);
4510 if (CLASS_TYPE_P (TREE_TYPE (exp
)))
4517 bool xval
= !lvalue_p (exp
);
4518 exp
= cp_build_addr_expr (exp
, tf_warning_or_error
);
4519 init_expr
= get_target_expr (exp
);
4520 exp
= TARGET_EXPR_SLOT (init_expr
);
4521 exp
= cp_build_indirect_ref (exp
, RO_NULL
, tf_warning_or_error
);
4527 gcc_assert (!TREE_SIDE_EFFECTS (exp
));
4531 /* Add NEW_EXPR, an expression whose value we don't care about, after the
4532 similar expression ORIG. */
4535 add_stmt_to_compound (tree orig
, tree new_expr
)
4537 if (!new_expr
|| !TREE_SIDE_EFFECTS (new_expr
))
4539 if (!orig
|| !TREE_SIDE_EFFECTS (orig
))
4541 return build2 (COMPOUND_EXPR
, void_type_node
, orig
, new_expr
);
4544 /* Like stabilize_expr, but for a call whose arguments we want to
4545 pre-evaluate. CALL is modified in place to use the pre-evaluated
4546 arguments, while, upon return, *INITP contains an expression to
4547 compute the arguments. */
4550 stabilize_call (tree call
, tree
*initp
)
4552 tree inits
= NULL_TREE
;
4554 int nargs
= call_expr_nargs (call
);
4556 if (call
== error_mark_node
|| processing_template_decl
)
4562 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
4564 for (i
= 0; i
< nargs
; i
++)
4567 CALL_EXPR_ARG (call
, i
) =
4568 stabilize_expr (CALL_EXPR_ARG (call
, i
), &init
);
4569 inits
= add_stmt_to_compound (inits
, init
);
4575 /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
4576 to pre-evaluate. CALL is modified in place to use the pre-evaluated
4577 arguments, while, upon return, *INITP contains an expression to
4578 compute the arguments. */
4581 stabilize_aggr_init (tree call
, tree
*initp
)
4583 tree inits
= NULL_TREE
;
4585 int nargs
= aggr_init_expr_nargs (call
);
4587 if (call
== error_mark_node
)
4590 gcc_assert (TREE_CODE (call
) == AGGR_INIT_EXPR
);
4592 for (i
= 0; i
< nargs
; i
++)
4595 AGGR_INIT_EXPR_ARG (call
, i
) =
4596 stabilize_expr (AGGR_INIT_EXPR_ARG (call
, i
), &init
);
4597 inits
= add_stmt_to_compound (inits
, init
);
4603 /* Like stabilize_expr, but for an initialization.
4605 If the initialization is for an object of class type, this function
4606 takes care not to introduce additional temporaries.
4608 Returns TRUE iff the expression was successfully pre-evaluated,
4609 i.e., if INIT is now side-effect free, except for, possibly, a
4610 single call to a constructor. */
4613 stabilize_init (tree init
, tree
*initp
)
4619 if (t
== error_mark_node
|| processing_template_decl
)
4622 if (TREE_CODE (t
) == INIT_EXPR
)
4623 t
= TREE_OPERAND (t
, 1);
4624 if (TREE_CODE (t
) == TARGET_EXPR
)
4625 t
= TARGET_EXPR_INITIAL (t
);
4627 /* If the RHS can be stabilized without breaking copy elision, stabilize
4628 it. We specifically don't stabilize class prvalues here because that
4629 would mean an extra copy, but they might be stabilized below. */
4630 if (TREE_CODE (init
) == INIT_EXPR
4631 && TREE_CODE (t
) != CONSTRUCTOR
4632 && TREE_CODE (t
) != AGGR_INIT_EXPR
4633 && (SCALAR_TYPE_P (TREE_TYPE (t
))
4636 TREE_OPERAND (init
, 1) = stabilize_expr (t
, initp
);
4640 if (TREE_CODE (t
) == COMPOUND_EXPR
4641 && TREE_CODE (init
) == INIT_EXPR
)
4643 tree last
= expr_last (t
);
4644 /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
4645 if (!TREE_SIDE_EFFECTS (last
))
4648 TREE_OPERAND (init
, 1) = last
;
4653 if (TREE_CODE (t
) == CONSTRUCTOR
)
4655 /* Aggregate initialization: stabilize each of the field
4658 constructor_elt
*ce
;
4660 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (t
);
4661 for (i
= 0; vec_safe_iterate (v
, i
, &ce
); ++i
)
4663 tree type
= TREE_TYPE (ce
->value
);
4665 if (TREE_CODE (type
) == REFERENCE_TYPE
4666 || SCALAR_TYPE_P (type
))
4667 ce
->value
= stabilize_expr (ce
->value
, &subinit
);
4668 else if (!stabilize_init (ce
->value
, &subinit
))
4670 *initp
= add_stmt_to_compound (*initp
, subinit
);
4675 if (TREE_CODE (t
) == CALL_EXPR
)
4677 stabilize_call (t
, initp
);
4681 if (TREE_CODE (t
) == AGGR_INIT_EXPR
)
4683 stabilize_aggr_init (t
, initp
);
4687 /* The initialization is being performed via a bitwise copy -- and
4688 the item copied may have side effects. */
4689 return !TREE_SIDE_EFFECTS (init
);
4692 /* Returns true if a cast to TYPE may appear in an integral constant
4696 cast_valid_in_integral_constant_expression_p (tree type
)
4698 return (INTEGRAL_OR_ENUMERATION_TYPE_P (type
)
4699 || cxx_dialect
>= cxx11
4700 || dependent_type_p (type
)
4701 || type
== error_mark_node
);
4704 /* Return true if we need to fix linkage information of DECL. */
4707 cp_fix_function_decl_p (tree decl
)
4709 /* Skip if DECL is not externally visible. */
4710 if (!TREE_PUBLIC (decl
))
4713 /* We need to fix DECL if it a appears to be exported but with no
4714 function body. Thunks do not have CFGs and we may need to
4715 handle them specially later. */
4716 if (!gimple_has_body_p (decl
)
4717 && !DECL_THUNK_P (decl
)
4718 && !DECL_EXTERNAL (decl
))
4720 struct cgraph_node
*node
= cgraph_node::get (decl
);
4722 /* Don't fix same_body aliases. Although they don't have their own
4723 CFG, they share it with what they alias to. */
4724 if (!node
|| !node
->alias
4725 || !vec_safe_length (node
->ref_list
.references
))
4732 /* Clean the C++ specific parts of the tree T. */
4735 cp_free_lang_data (tree t
)
4737 if (TREE_CODE (t
) == METHOD_TYPE
4738 || TREE_CODE (t
) == FUNCTION_TYPE
)
4740 /* Default args are not interesting anymore. */
4741 tree argtypes
= TYPE_ARG_TYPES (t
);
4744 TREE_PURPOSE (argtypes
) = 0;
4745 argtypes
= TREE_CHAIN (argtypes
);
4748 else if (TREE_CODE (t
) == FUNCTION_DECL
4749 && cp_fix_function_decl_p (t
))
4751 /* If T is used in this translation unit at all, the definition
4752 must exist somewhere else since we have decided to not emit it
4753 in this TU. So make it an external reference. */
4754 DECL_EXTERNAL (t
) = 1;
4755 TREE_STATIC (t
) = 0;
4757 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4759 /* The list of users of a namespace isn't useful for the middle-end
4760 or debug generators. */
4761 DECL_NAMESPACE_USERS (t
) = NULL_TREE
;
4762 /* Neither do we need the leftover chaining of namespaces
4763 from the binding level. */
4764 DECL_CHAIN (t
) = NULL_TREE
;
4768 /* Stub for c-common. Please keep in sync with c-decl.c.
4769 FIXME: If address space support is target specific, then this
4770 should be a C target hook. But currently this is not possible,
4771 because this function is called via REGISTER_TARGET_PRAGMAS. */
4773 c_register_addr_space (const char * /*word*/, addr_space_t
/*as*/)
4777 /* Return the number of operands in T that we care about for things like
4781 cp_tree_operand_length (const_tree t
)
4783 enum tree_code code
= TREE_CODE (t
);
4785 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
4786 return VL_EXP_OPERAND_LENGTH (t
);
4788 return cp_tree_code_length (code
);
4791 /* Like cp_tree_operand_length, but takes a tree_code CODE. */
4794 cp_tree_code_length (enum tree_code code
)
4796 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4800 case PREINCREMENT_EXPR
:
4801 case PREDECREMENT_EXPR
:
4802 case POSTINCREMENT_EXPR
:
4803 case POSTDECREMENT_EXPR
:
4809 case EXPR_PACK_EXPANSION
:
4813 return TREE_CODE_LENGTH (code
);
4817 /* Implement -Wzero_as_null_pointer_constant. Return true if the
4818 conditions for the warning hold, false otherwise. */
4820 maybe_warn_zero_as_null_pointer_constant (tree expr
, location_t loc
)
4822 if (c_inhibit_evaluation_warnings
== 0
4823 && !NULLPTR_TYPE_P (TREE_TYPE (expr
)))
4825 warning_at (loc
, OPT_Wzero_as_null_pointer_constant
,
4826 "zero as null pointer constant");
4832 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4833 /* Complain that some language-specific thing hanging off a tree
4834 node has been accessed improperly. */
4837 lang_check_failed (const char* file
, int line
, const char* function
)
4839 internal_error ("lang_* check: failed in %s, at %s:%d",
4840 function
, trim_filename (file
), line
);
4842 #endif /* ENABLE_TREE_CHECKING */
4844 #include "gt-cp-tree.h"