re PR c++/71528 (multiple extern reference declarations produce uninitialized access)
[gcc.git] / gcc / cp / tree.c
1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2016 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GCC.
6
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)
10 any later version.
11
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.
16
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/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "cp-tree.h"
26 #include "gimple-expr.h"
27 #include "cgraph.h"
28 #include "stor-layout.h"
29 #include "print-tree.h"
30 #include "tree-iterator.h"
31 #include "tree-inline.h"
32 #include "debug.h"
33 #include "convert.h"
34 #include "gimplify.h"
35 #include "attribs.h"
36
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);
44
45 static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *);
46 static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
47 static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *);
48
49 /* If REF is an lvalue, returns the kind of lvalue that REF is.
50 Otherwise, returns clk_none. */
51
52 cp_lvalue_kind
53 lvalue_kind (const_tree ref)
54 {
55 cp_lvalue_kind op1_lvalue_kind = clk_none;
56 cp_lvalue_kind op2_lvalue_kind = clk_none;
57
58 /* Expressions of reference type are sometimes wrapped in
59 INDIRECT_REFs. INDIRECT_REFs are just internal compiler
60 representation, not part of the language, so we have to look
61 through them. */
62 if (REFERENCE_REF_P (ref))
63 return lvalue_kind (TREE_OPERAND (ref, 0));
64
65 if (TREE_TYPE (ref)
66 && TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
67 {
68 /* unnamed rvalue references are rvalues */
69 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
70 && TREE_CODE (ref) != PARM_DECL
71 && !VAR_P (ref)
72 && TREE_CODE (ref) != COMPONENT_REF
73 /* Functions are always lvalues. */
74 && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
75 return clk_rvalueref;
76
77 /* lvalue references and named rvalue references are lvalues. */
78 return clk_ordinary;
79 }
80
81 if (ref == current_class_ptr)
82 return clk_none;
83
84 switch (TREE_CODE (ref))
85 {
86 case SAVE_EXPR:
87 return clk_none;
88 /* preincrements and predecrements are valid lvals, provided
89 what they refer to are valid lvals. */
90 case PREINCREMENT_EXPR:
91 case PREDECREMENT_EXPR:
92 case TRY_CATCH_EXPR:
93 case WITH_CLEANUP_EXPR:
94 case REALPART_EXPR:
95 case IMAGPART_EXPR:
96 return lvalue_kind (TREE_OPERAND (ref, 0));
97
98 case MEMBER_REF:
99 case DOTSTAR_EXPR:
100 if (TREE_CODE (ref) == MEMBER_REF)
101 op1_lvalue_kind = clk_ordinary;
102 else
103 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
104 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
105 op1_lvalue_kind = clk_none;
106 return op1_lvalue_kind;
107
108 case COMPONENT_REF:
109 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
110 /* Look at the member designator. */
111 if (!op1_lvalue_kind)
112 ;
113 else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
114 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
115 situations. If we're seeing a COMPONENT_REF, it's a non-static
116 member, so it isn't an lvalue. */
117 op1_lvalue_kind = clk_none;
118 else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
119 /* This can be IDENTIFIER_NODE in a template. */;
120 else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
121 {
122 /* Clear the ordinary bit. If this object was a class
123 rvalue we want to preserve that information. */
124 op1_lvalue_kind &= ~clk_ordinary;
125 /* The lvalue is for a bitfield. */
126 op1_lvalue_kind |= clk_bitfield;
127 }
128 else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
129 op1_lvalue_kind |= clk_packed;
130
131 return op1_lvalue_kind;
132
133 case STRING_CST:
134 case COMPOUND_LITERAL_EXPR:
135 return clk_ordinary;
136
137 case CONST_DECL:
138 /* CONST_DECL without TREE_STATIC are enumeration values and
139 thus not lvalues. With TREE_STATIC they are used by ObjC++
140 in objc_build_string_object and need to be considered as
141 lvalues. */
142 if (! TREE_STATIC (ref))
143 return clk_none;
144 case VAR_DECL:
145 if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
146 && DECL_LANG_SPECIFIC (ref)
147 && DECL_IN_AGGR_P (ref))
148 return clk_none;
149 case INDIRECT_REF:
150 case ARROW_EXPR:
151 case ARRAY_REF:
152 case ARRAY_NOTATION_REF:
153 case PARM_DECL:
154 case RESULT_DECL:
155 case PLACEHOLDER_EXPR:
156 return clk_ordinary;
157
158 /* A scope ref in a template, left as SCOPE_REF to support later
159 access checking. */
160 case SCOPE_REF:
161 gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
162 {
163 tree op = TREE_OPERAND (ref, 1);
164 if (TREE_CODE (op) == FIELD_DECL)
165 return (DECL_C_BIT_FIELD (op) ? clk_bitfield : clk_ordinary);
166 else
167 return lvalue_kind (op);
168 }
169
170 case MAX_EXPR:
171 case MIN_EXPR:
172 /* Disallow <? and >? as lvalues if either argument side-effects. */
173 if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
174 || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
175 return clk_none;
176 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
177 op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
178 break;
179
180 case COND_EXPR:
181 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1)
182 ? TREE_OPERAND (ref, 1)
183 : TREE_OPERAND (ref, 0));
184 op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2));
185 break;
186
187 case MODOP_EXPR:
188 /* We expect to see unlowered MODOP_EXPRs only during
189 template processing. */
190 gcc_assert (processing_template_decl);
191 return clk_ordinary;
192
193 case MODIFY_EXPR:
194 case TYPEID_EXPR:
195 return clk_ordinary;
196
197 case COMPOUND_EXPR:
198 return lvalue_kind (TREE_OPERAND (ref, 1));
199
200 case TARGET_EXPR:
201 return clk_class;
202
203 case VA_ARG_EXPR:
204 return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
205
206 case CALL_EXPR:
207 /* We can see calls outside of TARGET_EXPR in templates. */
208 if (CLASS_TYPE_P (TREE_TYPE (ref)))
209 return clk_class;
210 return clk_none;
211
212 case FUNCTION_DECL:
213 /* All functions (except non-static-member functions) are
214 lvalues. */
215 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
216 ? clk_none : clk_ordinary);
217
218 case BASELINK:
219 /* We now represent a reference to a single static member function
220 with a BASELINK. */
221 /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
222 its argument unmodified and we assign it to a const_tree. */
223 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
224
225 case NON_DEPENDENT_EXPR:
226 return lvalue_kind (TREE_OPERAND (ref, 0));
227
228 default:
229 if (!TREE_TYPE (ref))
230 return clk_none;
231 if (CLASS_TYPE_P (TREE_TYPE (ref)))
232 return clk_class;
233 break;
234 }
235
236 /* If one operand is not an lvalue at all, then this expression is
237 not an lvalue. */
238 if (!op1_lvalue_kind || !op2_lvalue_kind)
239 return clk_none;
240
241 /* Otherwise, it's an lvalue, and it has all the odd properties
242 contributed by either operand. */
243 op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
244 /* It's not an ordinary lvalue if it involves any other kind. */
245 if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
246 op1_lvalue_kind &= ~clk_ordinary;
247 /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
248 A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
249 if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
250 && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
251 op1_lvalue_kind = clk_none;
252 return op1_lvalue_kind;
253 }
254
255 /* Returns the kind of lvalue that REF is, in the sense of
256 [basic.lval]. This function should really be named lvalue_p; it
257 computes the C++ definition of lvalue. */
258
259 cp_lvalue_kind
260 real_lvalue_p (const_tree ref)
261 {
262 cp_lvalue_kind kind = lvalue_kind (ref);
263 if (kind & (clk_rvalueref|clk_class))
264 return clk_none;
265 else
266 return kind;
267 }
268
269 /* This differs from real_lvalue_p in that class rvalues are considered
270 lvalues. */
271
272 bool
273 lvalue_p (const_tree ref)
274 {
275 return (lvalue_kind (ref) != clk_none);
276 }
277
278 /* This differs from real_lvalue_p in that rvalues formed by dereferencing
279 rvalue references are considered rvalues. */
280
281 bool
282 lvalue_or_rvalue_with_address_p (const_tree ref)
283 {
284 cp_lvalue_kind kind = lvalue_kind (ref);
285 if (kind & clk_class)
286 return false;
287 else
288 return (kind != clk_none);
289 }
290
291 /* Returns true if REF is an xvalue, false otherwise. */
292
293 bool
294 xvalue_p (const_tree ref)
295 {
296 return (lvalue_kind (ref) == clk_rvalueref);
297 }
298
299 /* C++-specific version of stabilize_reference. */
300
301 tree
302 cp_stabilize_reference (tree ref)
303 {
304 switch (TREE_CODE (ref))
305 {
306 /* We need to treat specially anything stabilize_reference doesn't
307 handle specifically. */
308 case VAR_DECL:
309 case PARM_DECL:
310 case RESULT_DECL:
311 CASE_CONVERT:
312 case FLOAT_EXPR:
313 case FIX_TRUNC_EXPR:
314 case INDIRECT_REF:
315 case COMPONENT_REF:
316 case BIT_FIELD_REF:
317 case ARRAY_REF:
318 case ARRAY_RANGE_REF:
319 case ERROR_MARK:
320 break;
321 default:
322 cp_lvalue_kind kind = lvalue_kind (ref);
323 if ((kind & ~clk_class) != clk_none)
324 {
325 tree type = unlowered_expr_type (ref);
326 bool rval = !!(kind & clk_rvalueref);
327 type = cp_build_reference_type (type, rval);
328 /* This inhibits warnings in, eg, cxx_mark_addressable
329 (c++/60955). */
330 warning_sentinel s (extra_warnings);
331 ref = build_static_cast (type, ref, tf_error);
332 }
333 }
334
335 return stabilize_reference (ref);
336 }
337
338 /* Test whether DECL is a builtin that may appear in a
339 constant-expression. */
340
341 bool
342 builtin_valid_in_constant_expr_p (const_tree decl)
343 {
344 if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl)))
345 /* Not a built-in. */
346 return false;
347 switch (DECL_FUNCTION_CODE (decl))
348 {
349 /* These always have constant results like the corresponding
350 macros/symbol. */
351 case BUILT_IN_FILE:
352 case BUILT_IN_FUNCTION:
353 case BUILT_IN_LINE:
354
355 /* The following built-ins are valid in constant expressions
356 when their arguments are. */
357 case BUILT_IN_ADD_OVERFLOW_P:
358 case BUILT_IN_SUB_OVERFLOW_P:
359 case BUILT_IN_MUL_OVERFLOW_P:
360
361 /* These have constant results even if their operands are
362 non-constant. */
363 case BUILT_IN_CONSTANT_P:
364 case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
365 return true;
366 default:
367 return false;
368 }
369 }
370
371 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
372
373 static tree
374 build_target_expr (tree decl, tree value, tsubst_flags_t complain)
375 {
376 tree t;
377 tree type = TREE_TYPE (decl);
378
379 gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value))
380 || TREE_TYPE (decl) == TREE_TYPE (value)
381 /* On ARM ctors return 'this'. */
382 || (TYPE_PTR_P (TREE_TYPE (value))
383 && TREE_CODE (value) == CALL_EXPR)
384 || useless_type_conversion_p (TREE_TYPE (decl),
385 TREE_TYPE (value)));
386
387 t = cxx_maybe_build_cleanup (decl, complain);
388 if (t == error_mark_node)
389 return error_mark_node;
390 t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
391 if (EXPR_HAS_LOCATION (value))
392 SET_EXPR_LOCATION (t, EXPR_LOCATION (value));
393 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
394 ignore the TARGET_EXPR. If there really turn out to be no
395 side-effects, then the optimizer should be able to get rid of
396 whatever code is generated anyhow. */
397 TREE_SIDE_EFFECTS (t) = 1;
398
399 return t;
400 }
401
402 /* Return an undeclared local temporary of type TYPE for use in building a
403 TARGET_EXPR. */
404
405 static tree
406 build_local_temp (tree type)
407 {
408 tree slot = build_decl (input_location,
409 VAR_DECL, NULL_TREE, type);
410 DECL_ARTIFICIAL (slot) = 1;
411 DECL_IGNORED_P (slot) = 1;
412 DECL_CONTEXT (slot) = current_function_decl;
413 layout_decl (slot, 0);
414 return slot;
415 }
416
417 /* Set various status flags when building an AGGR_INIT_EXPR object T. */
418
419 static void
420 process_aggr_init_operands (tree t)
421 {
422 bool side_effects;
423
424 side_effects = TREE_SIDE_EFFECTS (t);
425 if (!side_effects)
426 {
427 int i, n;
428 n = TREE_OPERAND_LENGTH (t);
429 for (i = 1; i < n; i++)
430 {
431 tree op = TREE_OPERAND (t, i);
432 if (op && TREE_SIDE_EFFECTS (op))
433 {
434 side_effects = 1;
435 break;
436 }
437 }
438 }
439 TREE_SIDE_EFFECTS (t) = side_effects;
440 }
441
442 /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
443 FN, and SLOT. NARGS is the number of call arguments which are specified
444 as a tree array ARGS. */
445
446 static tree
447 build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
448 tree *args)
449 {
450 tree t;
451 int i;
452
453 t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
454 TREE_TYPE (t) = return_type;
455 AGGR_INIT_EXPR_FN (t) = fn;
456 AGGR_INIT_EXPR_SLOT (t) = slot;
457 for (i = 0; i < nargs; i++)
458 AGGR_INIT_EXPR_ARG (t, i) = args[i];
459 process_aggr_init_operands (t);
460 return t;
461 }
462
463 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
464 target. TYPE is the type to be initialized.
465
466 Build an AGGR_INIT_EXPR to represent the initialization. This function
467 differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
468 to initialize another object, whereas a TARGET_EXPR can either
469 initialize another object or create its own temporary object, and as a
470 result building up a TARGET_EXPR requires that the type's destructor be
471 callable. */
472
473 tree
474 build_aggr_init_expr (tree type, tree init)
475 {
476 tree fn;
477 tree slot;
478 tree rval;
479 int is_ctor;
480
481 /* Don't build AGGR_INIT_EXPR in a template. */
482 if (processing_template_decl)
483 return init;
484
485 fn = cp_get_callee (init);
486 if (fn == NULL_TREE)
487 return convert (type, init);
488
489 is_ctor = (TREE_CODE (fn) == ADDR_EXPR
490 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
491 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
492
493 /* We split the CALL_EXPR into its function and its arguments here.
494 Then, in expand_expr, we put them back together. The reason for
495 this is that this expression might be a default argument
496 expression. In that case, we need a new temporary every time the
497 expression is used. That's what break_out_target_exprs does; it
498 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
499 temporary slot. Then, expand_expr builds up a call-expression
500 using the new slot. */
501
502 /* If we don't need to use a constructor to create an object of this
503 type, don't mess with AGGR_INIT_EXPR. */
504 if (is_ctor || TREE_ADDRESSABLE (type))
505 {
506 slot = build_local_temp (type);
507
508 if (TREE_CODE (init) == CALL_EXPR)
509 {
510 rval = build_aggr_init_array (void_type_node, fn, slot,
511 call_expr_nargs (init),
512 CALL_EXPR_ARGP (init));
513 AGGR_INIT_FROM_THUNK_P (rval)
514 = CALL_FROM_THUNK_P (init);
515 }
516 else
517 {
518 rval = build_aggr_init_array (void_type_node, fn, slot,
519 aggr_init_expr_nargs (init),
520 AGGR_INIT_EXPR_ARGP (init));
521 AGGR_INIT_FROM_THUNK_P (rval)
522 = AGGR_INIT_FROM_THUNK_P (init);
523 }
524 TREE_SIDE_EFFECTS (rval) = 1;
525 AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
526 TREE_NOTHROW (rval) = TREE_NOTHROW (init);
527 CALL_EXPR_LIST_INIT_P (rval) = CALL_EXPR_LIST_INIT_P (init);
528 }
529 else
530 rval = init;
531
532 return rval;
533 }
534
535 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
536 target. TYPE is the type that this initialization should appear to
537 have.
538
539 Build an encapsulation of the initialization to perform
540 and return it so that it can be processed by language-independent
541 and language-specific expression expanders. */
542
543 tree
544 build_cplus_new (tree type, tree init, tsubst_flags_t complain)
545 {
546 tree rval = build_aggr_init_expr (type, init);
547 tree slot;
548
549 if (!complete_type_or_maybe_complain (type, init, complain))
550 return error_mark_node;
551
552 /* Make sure that we're not trying to create an instance of an
553 abstract class. */
554 if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain))
555 return error_mark_node;
556
557 if (TREE_CODE (rval) == AGGR_INIT_EXPR)
558 slot = AGGR_INIT_EXPR_SLOT (rval);
559 else if (TREE_CODE (rval) == CALL_EXPR
560 || TREE_CODE (rval) == CONSTRUCTOR)
561 slot = build_local_temp (type);
562 else
563 return rval;
564
565 rval = build_target_expr (slot, rval, complain);
566
567 if (rval != error_mark_node)
568 TARGET_EXPR_IMPLICIT_P (rval) = 1;
569
570 return rval;
571 }
572
573 /* Subroutine of build_vec_init_expr: Build up a single element
574 intialization as a proxy for the full array initialization to get things
575 marked as used and any appropriate diagnostics.
576
577 Since we're deferring building the actual constructor calls until
578 gimplification time, we need to build one now and throw it away so
579 that the relevant constructor gets mark_used before cgraph decides
580 what functions are needed. Here we assume that init is either
581 NULL_TREE, void_type_node (indicating value-initialization), or
582 another array to copy. */
583
584 static tree
585 build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
586 {
587 tree inner_type = strip_array_types (type);
588 vec<tree, va_gc> *argvec;
589
590 if (integer_zerop (array_type_nelts_total (type))
591 || !CLASS_TYPE_P (inner_type))
592 /* No interesting initialization to do. */
593 return integer_zero_node;
594 else if (init == void_type_node)
595 return build_value_init (inner_type, complain);
596
597 gcc_assert (init == NULL_TREE
598 || (same_type_ignoring_top_level_qualifiers_p
599 (type, TREE_TYPE (init))));
600
601 argvec = make_tree_vector ();
602 if (init)
603 {
604 tree init_type = strip_array_types (TREE_TYPE (init));
605 tree dummy = build_dummy_object (init_type);
606 if (!real_lvalue_p (init))
607 dummy = move (dummy);
608 argvec->quick_push (dummy);
609 }
610 init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
611 &argvec, inner_type, LOOKUP_NORMAL,
612 complain);
613 release_tree_vector (argvec);
614
615 /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
616 we don't want one here because we aren't creating a temporary. */
617 if (TREE_CODE (init) == TARGET_EXPR)
618 init = TARGET_EXPR_INITIAL (init);
619
620 return init;
621 }
622
623 /* Return a TARGET_EXPR which expresses the initialization of an array to
624 be named later, either default-initialization or copy-initialization
625 from another array of the same type. */
626
627 tree
628 build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
629 {
630 tree slot;
631 bool value_init = false;
632 tree elt_init = build_vec_init_elt (type, init, complain);
633
634 if (init == void_type_node)
635 {
636 value_init = true;
637 init = NULL_TREE;
638 }
639
640 slot = build_local_temp (type);
641 init = build2 (VEC_INIT_EXPR, type, slot, init);
642 TREE_SIDE_EFFECTS (init) = true;
643 SET_EXPR_LOCATION (init, input_location);
644
645 if (cxx_dialect >= cxx11
646 && potential_constant_expression (elt_init))
647 VEC_INIT_EXPR_IS_CONSTEXPR (init) = true;
648 VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
649
650 return init;
651 }
652
653 /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
654 that requires a constant expression. */
655
656 void
657 diagnose_non_constexpr_vec_init (tree expr)
658 {
659 tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
660 tree init, elt_init;
661 if (VEC_INIT_EXPR_VALUE_INIT (expr))
662 init = void_type_node;
663 else
664 init = VEC_INIT_EXPR_INIT (expr);
665
666 elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
667 require_potential_constant_expression (elt_init);
668 }
669
670 tree
671 build_array_copy (tree init)
672 {
673 return build_vec_init_expr (TREE_TYPE (init), init, tf_warning_or_error);
674 }
675
676 /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
677 indicated TYPE. */
678
679 tree
680 build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
681 {
682 gcc_assert (!VOID_TYPE_P (type));
683
684 if (TREE_CODE (init) == TARGET_EXPR
685 || init == error_mark_node)
686 return init;
687 else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
688 && !VOID_TYPE_P (TREE_TYPE (init))
689 && TREE_CODE (init) != COND_EXPR
690 && TREE_CODE (init) != CONSTRUCTOR
691 && TREE_CODE (init) != VA_ARG_EXPR)
692 /* We need to build up a copy constructor call. A void initializer
693 means we're being called from bot_manip. COND_EXPR is a special
694 case because we already have copies on the arms and we don't want
695 another one here. A CONSTRUCTOR is aggregate initialization, which
696 is handled separately. A VA_ARG_EXPR is magic creation of an
697 aggregate; there's no additional work to be done. */
698 return force_rvalue (init, complain);
699
700 return force_target_expr (type, init, complain);
701 }
702
703 /* Like the above function, but without the checking. This function should
704 only be used by code which is deliberately trying to subvert the type
705 system, such as call_builtin_trap. Or build_over_call, to avoid
706 infinite recursion. */
707
708 tree
709 force_target_expr (tree type, tree init, tsubst_flags_t complain)
710 {
711 tree slot;
712
713 gcc_assert (!VOID_TYPE_P (type));
714
715 slot = build_local_temp (type);
716 return build_target_expr (slot, init, complain);
717 }
718
719 /* Like build_target_expr_with_type, but use the type of INIT. */
720
721 tree
722 get_target_expr_sfinae (tree init, tsubst_flags_t complain)
723 {
724 if (TREE_CODE (init) == AGGR_INIT_EXPR)
725 return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
726 else if (TREE_CODE (init) == VEC_INIT_EXPR)
727 return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
728 else
729 return build_target_expr_with_type (init, TREE_TYPE (init), complain);
730 }
731
732 tree
733 get_target_expr (tree init)
734 {
735 return get_target_expr_sfinae (init, tf_warning_or_error);
736 }
737
738 /* If EXPR is a bitfield reference, convert it to the declared type of
739 the bitfield, and return the resulting expression. Otherwise,
740 return EXPR itself. */
741
742 tree
743 convert_bitfield_to_declared_type (tree expr)
744 {
745 tree bitfield_type;
746
747 bitfield_type = is_bitfield_expr_with_lowered_type (expr);
748 if (bitfield_type)
749 expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
750 expr);
751 return expr;
752 }
753
754 /* EXPR is being used in an rvalue context. Return a version of EXPR
755 that is marked as an rvalue. */
756
757 tree
758 rvalue (tree expr)
759 {
760 tree type;
761
762 if (error_operand_p (expr))
763 return expr;
764
765 expr = mark_rvalue_use (expr);
766
767 /* [basic.lval]
768
769 Non-class rvalues always have cv-unqualified types. */
770 type = TREE_TYPE (expr);
771 if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
772 type = cv_unqualified (type);
773
774 /* We need to do this for rvalue refs as well to get the right answer
775 from decltype; see c++/36628. */
776 if (!processing_template_decl && lvalue_or_rvalue_with_address_p (expr))
777 expr = build1 (NON_LVALUE_EXPR, type, expr);
778 else if (type != TREE_TYPE (expr))
779 expr = build_nop (type, expr);
780
781 return expr;
782 }
783
784 \f
785 struct cplus_array_info
786 {
787 tree type;
788 tree domain;
789 };
790
791 struct cplus_array_hasher : ggc_ptr_hash<tree_node>
792 {
793 typedef cplus_array_info *compare_type;
794
795 static hashval_t hash (tree t);
796 static bool equal (tree, cplus_array_info *);
797 };
798
799 /* Hash an ARRAY_TYPE. K is really of type `tree'. */
800
801 hashval_t
802 cplus_array_hasher::hash (tree t)
803 {
804 hashval_t hash;
805
806 hash = TYPE_UID (TREE_TYPE (t));
807 if (TYPE_DOMAIN (t))
808 hash ^= TYPE_UID (TYPE_DOMAIN (t));
809 return hash;
810 }
811
812 /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
813 of type `cplus_array_info*'. */
814
815 bool
816 cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
817 {
818 return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
819 }
820
821 /* Hash table containing dependent array types, which are unsuitable for
822 the language-independent type hash table. */
823 static GTY (()) hash_table<cplus_array_hasher> *cplus_array_htab;
824
825 /* Build an ARRAY_TYPE without laying it out. */
826
827 static tree
828 build_min_array_type (tree elt_type, tree index_type)
829 {
830 tree t = cxx_make_type (ARRAY_TYPE);
831 TREE_TYPE (t) = elt_type;
832 TYPE_DOMAIN (t) = index_type;
833 return t;
834 }
835
836 /* Set TYPE_CANONICAL like build_array_type_1, but using
837 build_cplus_array_type. */
838
839 static void
840 set_array_type_canon (tree t, tree elt_type, tree index_type)
841 {
842 /* Set the canonical type for this new node. */
843 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
844 || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
845 SET_TYPE_STRUCTURAL_EQUALITY (t);
846 else if (TYPE_CANONICAL (elt_type) != elt_type
847 || (index_type && TYPE_CANONICAL (index_type) != index_type))
848 TYPE_CANONICAL (t)
849 = build_cplus_array_type (TYPE_CANONICAL (elt_type),
850 index_type
851 ? TYPE_CANONICAL (index_type) : index_type);
852 else
853 TYPE_CANONICAL (t) = t;
854 }
855
856 /* Like build_array_type, but handle special C++ semantics: an array of a
857 variant element type is a variant of the array of the main variant of
858 the element type. */
859
860 tree
861 build_cplus_array_type (tree elt_type, tree index_type)
862 {
863 tree t;
864
865 if (elt_type == error_mark_node || index_type == error_mark_node)
866 return error_mark_node;
867
868 bool dependent = (uses_template_parms (elt_type)
869 || (index_type && uses_template_parms (index_type)));
870
871 if (elt_type != TYPE_MAIN_VARIANT (elt_type))
872 /* Start with an array of the TYPE_MAIN_VARIANT. */
873 t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
874 index_type);
875 else if (dependent)
876 {
877 /* Since type_hash_canon calls layout_type, we need to use our own
878 hash table. */
879 cplus_array_info cai;
880 hashval_t hash;
881
882 if (cplus_array_htab == NULL)
883 cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
884
885 hash = TYPE_UID (elt_type);
886 if (index_type)
887 hash ^= TYPE_UID (index_type);
888 cai.type = elt_type;
889 cai.domain = index_type;
890
891 tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
892 if (*e)
893 /* We have found the type: we're done. */
894 return (tree) *e;
895 else
896 {
897 /* Build a new array type. */
898 t = build_min_array_type (elt_type, index_type);
899
900 /* Store it in the hash table. */
901 *e = t;
902
903 /* Set the canonical type for this new node. */
904 set_array_type_canon (t, elt_type, index_type);
905 }
906 }
907 else
908 {
909 t = build_array_type (elt_type, index_type);
910 }
911
912 /* Now check whether we already have this array variant. */
913 if (elt_type != TYPE_MAIN_VARIANT (elt_type))
914 {
915 tree m = t;
916 for (t = m; t; t = TYPE_NEXT_VARIANT (t))
917 if (TREE_TYPE (t) == elt_type
918 && TYPE_NAME (t) == NULL_TREE
919 && TYPE_ATTRIBUTES (t) == NULL_TREE)
920 break;
921 if (!t)
922 {
923 t = build_min_array_type (elt_type, index_type);
924 set_array_type_canon (t, elt_type, index_type);
925 if (!dependent)
926 {
927 layout_type (t);
928 /* Make sure sizes are shared with the main variant.
929 layout_type can't be called after setting TYPE_NEXT_VARIANT,
930 as it will overwrite alignment etc. of all variants. */
931 TYPE_SIZE (t) = TYPE_SIZE (m);
932 TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
933 }
934
935 TYPE_MAIN_VARIANT (t) = m;
936 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
937 TYPE_NEXT_VARIANT (m) = t;
938 }
939 }
940
941 /* Avoid spurious warnings with VLAs (c++/54583). */
942 if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
943 TREE_NO_WARNING (TYPE_SIZE (t)) = 1;
944
945 /* Push these needs up to the ARRAY_TYPE so that initialization takes
946 place more easily. */
947 bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
948 = TYPE_NEEDS_CONSTRUCTING (elt_type));
949 bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
950 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
951
952 if (!dependent && t == TYPE_MAIN_VARIANT (t)
953 && !COMPLETE_TYPE_P (t) && COMPLETE_TYPE_P (elt_type))
954 {
955 /* The element type has been completed since the last time we saw
956 this array type; update the layout and 'tor flags for any variants
957 that need it. */
958 layout_type (t);
959 for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
960 {
961 TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
962 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
963 }
964 }
965
966 return t;
967 }
968
969 /* Return an ARRAY_TYPE with element type ELT and length N. */
970
971 tree
972 build_array_of_n_type (tree elt, int n)
973 {
974 return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
975 }
976
977 /* True iff T is an N3639 array of runtime bound (VLA). These were
978 approved for C++14 but then removed. */
979
980 bool
981 array_of_runtime_bound_p (tree t)
982 {
983 if (!t || TREE_CODE (t) != ARRAY_TYPE)
984 return false;
985 tree dom = TYPE_DOMAIN (t);
986 if (!dom)
987 return false;
988 tree max = TYPE_MAX_VALUE (dom);
989 return (!potential_rvalue_constant_expression (max)
990 || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
991 }
992
993 /* Return a reference type node referring to TO_TYPE. If RVAL is
994 true, return an rvalue reference type, otherwise return an lvalue
995 reference type. If a type node exists, reuse it, otherwise create
996 a new one. */
997 tree
998 cp_build_reference_type (tree to_type, bool rval)
999 {
1000 tree lvalue_ref, t;
1001 lvalue_ref = build_reference_type (to_type);
1002 if (!rval)
1003 return lvalue_ref;
1004
1005 /* This code to create rvalue reference types is based on and tied
1006 to the code creating lvalue reference types in the middle-end
1007 functions build_reference_type_for_mode and build_reference_type.
1008
1009 It works by putting the rvalue reference type nodes after the
1010 lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
1011 they will effectively be ignored by the middle end. */
1012
1013 for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
1014 if (TYPE_REF_IS_RVALUE (t))
1015 return t;
1016
1017 t = build_distinct_type_copy (lvalue_ref);
1018
1019 TYPE_REF_IS_RVALUE (t) = true;
1020 TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
1021 TYPE_NEXT_REF_TO (lvalue_ref) = t;
1022
1023 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
1024 SET_TYPE_STRUCTURAL_EQUALITY (t);
1025 else if (TYPE_CANONICAL (to_type) != to_type)
1026 TYPE_CANONICAL (t)
1027 = cp_build_reference_type (TYPE_CANONICAL (to_type), rval);
1028 else
1029 TYPE_CANONICAL (t) = t;
1030
1031 layout_type (t);
1032
1033 return t;
1034
1035 }
1036
1037 /* Returns EXPR cast to rvalue reference type, like std::move. */
1038
1039 tree
1040 move (tree expr)
1041 {
1042 tree type = TREE_TYPE (expr);
1043 gcc_assert (TREE_CODE (type) != REFERENCE_TYPE);
1044 type = cp_build_reference_type (type, /*rval*/true);
1045 return build_static_cast (type, expr, tf_warning_or_error);
1046 }
1047
1048 /* Used by the C++ front end to build qualified array types. However,
1049 the C version of this function does not properly maintain canonical
1050 types (which are not used in C). */
1051 tree
1052 c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
1053 size_t /* orig_qual_indirect */)
1054 {
1055 return cp_build_qualified_type (type, type_quals);
1056 }
1057
1058 \f
1059 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
1060 arrays correctly. In particular, if TYPE is an array of T's, and
1061 TYPE_QUALS is non-empty, returns an array of qualified T's.
1062
1063 FLAGS determines how to deal with ill-formed qualifications. If
1064 tf_ignore_bad_quals is set, then bad qualifications are dropped
1065 (this is permitted if TYPE was introduced via a typedef or template
1066 type parameter). If bad qualifications are dropped and tf_warning
1067 is set, then a warning is issued for non-const qualifications. If
1068 tf_ignore_bad_quals is not set and tf_error is not set, we
1069 return error_mark_node. Otherwise, we issue an error, and ignore
1070 the qualifications.
1071
1072 Qualification of a reference type is valid when the reference came
1073 via a typedef or template type argument. [dcl.ref] No such
1074 dispensation is provided for qualifying a function type. [dcl.fct]
1075 DR 295 queries this and the proposed resolution brings it into line
1076 with qualifying a reference. We implement the DR. We also behave
1077 in a similar manner for restricting non-pointer types. */
1078
1079 tree
1080 cp_build_qualified_type_real (tree type,
1081 int type_quals,
1082 tsubst_flags_t complain)
1083 {
1084 tree result;
1085 int bad_quals = TYPE_UNQUALIFIED;
1086
1087 if (type == error_mark_node)
1088 return type;
1089
1090 if (type_quals == cp_type_quals (type))
1091 return type;
1092
1093 if (TREE_CODE (type) == ARRAY_TYPE)
1094 {
1095 /* In C++, the qualification really applies to the array element
1096 type. Obtain the appropriately qualified element type. */
1097 tree t;
1098 tree element_type
1099 = cp_build_qualified_type_real (TREE_TYPE (type),
1100 type_quals,
1101 complain);
1102
1103 if (element_type == error_mark_node)
1104 return error_mark_node;
1105
1106 /* See if we already have an identically qualified type. Tests
1107 should be equivalent to those in check_qualified_type. */
1108 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1109 if (TREE_TYPE (t) == element_type
1110 && TYPE_NAME (t) == TYPE_NAME (type)
1111 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
1112 && attribute_list_equal (TYPE_ATTRIBUTES (t),
1113 TYPE_ATTRIBUTES (type)))
1114 break;
1115
1116 if (!t)
1117 {
1118 t = build_cplus_array_type (element_type, TYPE_DOMAIN (type));
1119
1120 /* Keep the typedef name. */
1121 if (TYPE_NAME (t) != TYPE_NAME (type))
1122 {
1123 t = build_variant_type_copy (t);
1124 TYPE_NAME (t) = TYPE_NAME (type);
1125 SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
1126 TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
1127 }
1128 }
1129
1130 /* Even if we already had this variant, we update
1131 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1132 they changed since the variant was originally created.
1133
1134 This seems hokey; if there is some way to use a previous
1135 variant *without* coming through here,
1136 TYPE_NEEDS_CONSTRUCTING will never be updated. */
1137 TYPE_NEEDS_CONSTRUCTING (t)
1138 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1139 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1140 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1141 return t;
1142 }
1143 else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
1144 {
1145 tree t = PACK_EXPANSION_PATTERN (type);
1146
1147 t = cp_build_qualified_type_real (t, type_quals, complain);
1148 return make_pack_expansion (t);
1149 }
1150
1151 /* A reference or method type shall not be cv-qualified.
1152 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1153 (in CD1) we always ignore extra cv-quals on functions. */
1154 if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1155 && (TREE_CODE (type) == REFERENCE_TYPE
1156 || TREE_CODE (type) == FUNCTION_TYPE
1157 || TREE_CODE (type) == METHOD_TYPE))
1158 {
1159 if (TREE_CODE (type) == REFERENCE_TYPE)
1160 bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1161 type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1162 }
1163
1164 /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1165 if (TREE_CODE (type) == FUNCTION_TYPE)
1166 type_quals |= type_memfn_quals (type);
1167
1168 /* A restrict-qualified type must be a pointer (or reference)
1169 to object or incomplete type. */
1170 if ((type_quals & TYPE_QUAL_RESTRICT)
1171 && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1172 && TREE_CODE (type) != TYPENAME_TYPE
1173 && !POINTER_TYPE_P (type))
1174 {
1175 bad_quals |= TYPE_QUAL_RESTRICT;
1176 type_quals &= ~TYPE_QUAL_RESTRICT;
1177 }
1178
1179 if (bad_quals == TYPE_UNQUALIFIED
1180 || (complain & tf_ignore_bad_quals))
1181 /*OK*/;
1182 else if (!(complain & tf_error))
1183 return error_mark_node;
1184 else
1185 {
1186 tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
1187 error ("%qV qualifiers cannot be applied to %qT",
1188 bad_type, type);
1189 }
1190
1191 /* Retrieve (or create) the appropriately qualified variant. */
1192 result = build_qualified_type (type, type_quals);
1193
1194 /* Preserve exception specs and ref-qualifier since build_qualified_type
1195 doesn't know about them. */
1196 if (TREE_CODE (result) == FUNCTION_TYPE
1197 || TREE_CODE (result) == METHOD_TYPE)
1198 {
1199 result = build_exception_variant (result, TYPE_RAISES_EXCEPTIONS (type));
1200 result = build_ref_qualified_type (result, type_memfn_rqual (type));
1201 }
1202
1203 return result;
1204 }
1205
1206 /* Return TYPE with const and volatile removed. */
1207
1208 tree
1209 cv_unqualified (tree type)
1210 {
1211 int quals;
1212
1213 if (type == error_mark_node)
1214 return type;
1215
1216 quals = cp_type_quals (type);
1217 quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1218 return cp_build_qualified_type (type, quals);
1219 }
1220
1221 /* Subroutine of strip_typedefs. We want to apply to RESULT the attributes
1222 from ATTRIBS that affect type identity, and no others. If any are not
1223 applied, set *remove_attributes to true. */
1224
1225 static tree
1226 apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
1227 {
1228 tree first_ident = NULL_TREE;
1229 tree new_attribs = NULL_TREE;
1230 tree *p = &new_attribs;
1231
1232 if (OVERLOAD_TYPE_P (result))
1233 {
1234 /* On classes and enums all attributes are ingrained. */
1235 gcc_assert (attribs == TYPE_ATTRIBUTES (result));
1236 return result;
1237 }
1238
1239 for (tree a = attribs; a; a = TREE_CHAIN (a))
1240 {
1241 const attribute_spec *as
1242 = lookup_attribute_spec (get_attribute_name (a));
1243 if (as && as->affects_type_identity)
1244 {
1245 if (!first_ident)
1246 first_ident = a;
1247 else if (first_ident == error_mark_node)
1248 {
1249 *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
1250 p = &TREE_CHAIN (*p);
1251 }
1252 }
1253 else if (first_ident)
1254 {
1255 for (tree a2 = first_ident; a2; a2 = TREE_CHAIN (a2))
1256 {
1257 *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
1258 p = &TREE_CHAIN (*p);
1259 }
1260 first_ident = error_mark_node;
1261 }
1262 }
1263 if (first_ident != error_mark_node)
1264 new_attribs = first_ident;
1265
1266 if (first_ident == attribs)
1267 /* All attributes affected type identity. */;
1268 else
1269 *remove_attributes = true;
1270
1271 return cp_build_type_attribute_variant (result, new_attribs);
1272 }
1273
1274 /* Builds a qualified variant of T that is not a typedef variant.
1275 E.g. consider the following declarations:
1276 typedef const int ConstInt;
1277 typedef ConstInt* PtrConstInt;
1278 If T is PtrConstInt, this function returns a type representing
1279 const int*.
1280 In other words, if T is a typedef, the function returns the underlying type.
1281 The cv-qualification and attributes of the type returned match the
1282 input type.
1283 They will always be compatible types.
1284 The returned type is built so that all of its subtypes
1285 recursively have their typedefs stripped as well.
1286
1287 This is different from just returning TYPE_CANONICAL (T)
1288 Because of several reasons:
1289 * If T is a type that needs structural equality
1290 its TYPE_CANONICAL (T) will be NULL.
1291 * TYPE_CANONICAL (T) desn't carry type attributes
1292 and loses template parameter names.
1293
1294 If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
1295 affect type identity, and set the referent to true if any were
1296 stripped. */
1297
1298 tree
1299 strip_typedefs (tree t, bool *remove_attributes)
1300 {
1301 tree result = NULL, type = NULL, t0 = NULL;
1302
1303 if (!t || t == error_mark_node)
1304 return t;
1305
1306 if (TREE_CODE (t) == TREE_LIST)
1307 {
1308 bool changed = false;
1309 vec<tree,va_gc> *vec = make_tree_vector ();
1310 tree r = t;
1311 for (; t; t = TREE_CHAIN (t))
1312 {
1313 gcc_assert (!TREE_PURPOSE (t));
1314 tree elt = strip_typedefs (TREE_VALUE (t), remove_attributes);
1315 if (elt != TREE_VALUE (t))
1316 changed = true;
1317 vec_safe_push (vec, elt);
1318 }
1319 if (changed)
1320 r = build_tree_list_vec (vec);
1321 release_tree_vector (vec);
1322 return r;
1323 }
1324
1325 gcc_assert (TYPE_P (t));
1326
1327 if (t == TYPE_CANONICAL (t))
1328 return t;
1329
1330 if (dependent_alias_template_spec_p (t))
1331 /* DR 1558: However, if the template-id is dependent, subsequent
1332 template argument substitution still applies to the template-id. */
1333 return t;
1334
1335 switch (TREE_CODE (t))
1336 {
1337 case POINTER_TYPE:
1338 type = strip_typedefs (TREE_TYPE (t), remove_attributes);
1339 result = build_pointer_type (type);
1340 break;
1341 case REFERENCE_TYPE:
1342 type = strip_typedefs (TREE_TYPE (t), remove_attributes);
1343 result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t));
1344 break;
1345 case OFFSET_TYPE:
1346 t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes);
1347 type = strip_typedefs (TREE_TYPE (t), remove_attributes);
1348 result = build_offset_type (t0, type);
1349 break;
1350 case RECORD_TYPE:
1351 if (TYPE_PTRMEMFUNC_P (t))
1352 {
1353 t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t), remove_attributes);
1354 result = build_ptrmemfunc_type (t0);
1355 }
1356 break;
1357 case ARRAY_TYPE:
1358 type = strip_typedefs (TREE_TYPE (t), remove_attributes);
1359 t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes);
1360 result = build_cplus_array_type (type, t0);
1361 break;
1362 case FUNCTION_TYPE:
1363 case METHOD_TYPE:
1364 {
1365 tree arg_types = NULL, arg_node, arg_node2, arg_type;
1366 bool changed;
1367
1368 /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
1369 around the compiler (e.g. cp_parser_late_parsing_default_args), we
1370 can't expect that re-hashing a function type will find a previous
1371 equivalent type, so try to reuse the input type if nothing has
1372 changed. If the type is itself a variant, that will change. */
1373 bool is_variant = typedef_variant_p (t);
1374 if (remove_attributes
1375 && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
1376 is_variant = true;
1377
1378 type = strip_typedefs (TREE_TYPE (t), remove_attributes);
1379 changed = type != TREE_TYPE (t) || is_variant;
1380
1381 for (arg_node = TYPE_ARG_TYPES (t);
1382 arg_node;
1383 arg_node = TREE_CHAIN (arg_node))
1384 {
1385 if (arg_node == void_list_node)
1386 break;
1387 arg_type = strip_typedefs (TREE_VALUE (arg_node),
1388 remove_attributes);
1389 gcc_assert (arg_type);
1390 if (arg_type == TREE_VALUE (arg_node) && !changed)
1391 continue;
1392
1393 if (!changed)
1394 {
1395 changed = true;
1396 for (arg_node2 = TYPE_ARG_TYPES (t);
1397 arg_node2 != arg_node;
1398 arg_node2 = TREE_CHAIN (arg_node2))
1399 arg_types
1400 = tree_cons (TREE_PURPOSE (arg_node2),
1401 TREE_VALUE (arg_node2), arg_types);
1402 }
1403
1404 arg_types
1405 = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1406 }
1407
1408 if (!changed)
1409 return t;
1410
1411 if (arg_types)
1412 arg_types = nreverse (arg_types);
1413
1414 /* A list of parameters not ending with an ellipsis
1415 must end with void_list_node. */
1416 if (arg_node)
1417 arg_types = chainon (arg_types, void_list_node);
1418
1419 if (TREE_CODE (t) == METHOD_TYPE)
1420 {
1421 tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1422 gcc_assert (class_type);
1423 result =
1424 build_method_type_directly (class_type, type,
1425 TREE_CHAIN (arg_types));
1426 result
1427 = build_ref_qualified_type (result, type_memfn_rqual (t));
1428 }
1429 else
1430 {
1431 result = build_function_type (type,
1432 arg_types);
1433 result = apply_memfn_quals (result,
1434 type_memfn_quals (t),
1435 type_memfn_rqual (t));
1436 }
1437
1438 if (TYPE_RAISES_EXCEPTIONS (t))
1439 result = build_exception_variant (result,
1440 TYPE_RAISES_EXCEPTIONS (t));
1441 if (TYPE_HAS_LATE_RETURN_TYPE (t))
1442 TYPE_HAS_LATE_RETURN_TYPE (result) = 1;
1443 }
1444 break;
1445 case TYPENAME_TYPE:
1446 {
1447 tree fullname = TYPENAME_TYPE_FULLNAME (t);
1448 if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
1449 && TREE_OPERAND (fullname, 1))
1450 {
1451 tree args = TREE_OPERAND (fullname, 1);
1452 tree new_args = copy_node (args);
1453 bool changed = false;
1454 for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
1455 {
1456 tree arg = TREE_VEC_ELT (args, i);
1457 tree strip_arg;
1458 if (TYPE_P (arg))
1459 strip_arg = strip_typedefs (arg, remove_attributes);
1460 else
1461 strip_arg = strip_typedefs_expr (arg, remove_attributes);
1462 TREE_VEC_ELT (new_args, i) = strip_arg;
1463 if (strip_arg != arg)
1464 changed = true;
1465 }
1466 if (changed)
1467 {
1468 NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
1469 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
1470 fullname
1471 = lookup_template_function (TREE_OPERAND (fullname, 0),
1472 new_args);
1473 }
1474 else
1475 ggc_free (new_args);
1476 }
1477 result = make_typename_type (strip_typedefs (TYPE_CONTEXT (t),
1478 remove_attributes),
1479 fullname, typename_type, tf_none);
1480 /* Handle 'typedef typename A::N N;' */
1481 if (typedef_variant_p (result))
1482 result = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (TYPE_NAME (result)));
1483 }
1484 break;
1485 case DECLTYPE_TYPE:
1486 result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
1487 remove_attributes);
1488 if (result == DECLTYPE_TYPE_EXPR (t))
1489 result = NULL_TREE;
1490 else
1491 result = (finish_decltype_type
1492 (result,
1493 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
1494 tf_none));
1495 break;
1496 default:
1497 break;
1498 }
1499
1500 if (!result)
1501 {
1502 if (typedef_variant_p (t))
1503 {
1504 /* Explicitly get the underlying type, as TYPE_MAIN_VARIANT doesn't
1505 strip typedefs with attributes. */
1506 result = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (TYPE_NAME (t)));
1507 result = strip_typedefs (result);
1508 }
1509 else
1510 result = TYPE_MAIN_VARIANT (t);
1511 }
1512 gcc_assert (!typedef_variant_p (result));
1513 if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
1514 || TYPE_ALIGN (t) != TYPE_ALIGN (result))
1515 {
1516 gcc_assert (TYPE_USER_ALIGN (t));
1517 if (remove_attributes)
1518 *remove_attributes = true;
1519 else
1520 {
1521 if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
1522 result = build_variant_type_copy (result);
1523 else
1524 result = build_aligned_type (result, TYPE_ALIGN (t));
1525 TYPE_USER_ALIGN (result) = true;
1526 }
1527 }
1528 if (TYPE_ATTRIBUTES (t))
1529 {
1530 if (remove_attributes)
1531 result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
1532 remove_attributes);
1533 else
1534 result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t));
1535 }
1536 return cp_build_qualified_type (result, cp_type_quals (t));
1537 }
1538
1539 /* Like strip_typedefs above, but works on expressions, so that in
1540
1541 template<class T> struct A
1542 {
1543 typedef T TT;
1544 B<sizeof(TT)> b;
1545 };
1546
1547 sizeof(TT) is replaced by sizeof(T). */
1548
1549 tree
1550 strip_typedefs_expr (tree t, bool *remove_attributes)
1551 {
1552 unsigned i,n;
1553 tree r, type, *ops;
1554 enum tree_code code;
1555
1556 if (t == NULL_TREE || t == error_mark_node)
1557 return t;
1558
1559 if (DECL_P (t) || CONSTANT_CLASS_P (t))
1560 return t;
1561
1562 /* Some expressions have type operands, so let's handle types here rather
1563 than check TYPE_P in multiple places below. */
1564 if (TYPE_P (t))
1565 return strip_typedefs (t, remove_attributes);
1566
1567 code = TREE_CODE (t);
1568 switch (code)
1569 {
1570 case IDENTIFIER_NODE:
1571 case TEMPLATE_PARM_INDEX:
1572 case OVERLOAD:
1573 case BASELINK:
1574 case ARGUMENT_PACK_SELECT:
1575 return t;
1576
1577 case TRAIT_EXPR:
1578 {
1579 tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t), remove_attributes);
1580 tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t), remove_attributes);
1581 if (type1 == TRAIT_EXPR_TYPE1 (t)
1582 && type2 == TRAIT_EXPR_TYPE2 (t))
1583 return t;
1584 r = copy_node (t);
1585 TRAIT_EXPR_TYPE1 (r) = type1;
1586 TRAIT_EXPR_TYPE2 (r) = type2;
1587 return r;
1588 }
1589
1590 case TREE_LIST:
1591 {
1592 vec<tree, va_gc> *vec = make_tree_vector ();
1593 bool changed = false;
1594 tree it;
1595 for (it = t; it; it = TREE_CHAIN (it))
1596 {
1597 tree val = strip_typedefs_expr (TREE_VALUE (t), remove_attributes);
1598 vec_safe_push (vec, val);
1599 if (val != TREE_VALUE (t))
1600 changed = true;
1601 gcc_assert (TREE_PURPOSE (it) == NULL_TREE);
1602 }
1603 if (changed)
1604 {
1605 r = NULL_TREE;
1606 FOR_EACH_VEC_ELT_REVERSE (*vec, i, it)
1607 r = tree_cons (NULL_TREE, it, r);
1608 }
1609 else
1610 r = t;
1611 release_tree_vector (vec);
1612 return r;
1613 }
1614
1615 case TREE_VEC:
1616 {
1617 bool changed = false;
1618 vec<tree, va_gc> *vec = make_tree_vector ();
1619 n = TREE_VEC_LENGTH (t);
1620 vec_safe_reserve (vec, n);
1621 for (i = 0; i < n; ++i)
1622 {
1623 tree op = strip_typedefs_expr (TREE_VEC_ELT (t, i),
1624 remove_attributes);
1625 vec->quick_push (op);
1626 if (op != TREE_VEC_ELT (t, i))
1627 changed = true;
1628 }
1629 if (changed)
1630 {
1631 r = copy_node (t);
1632 for (i = 0; i < n; ++i)
1633 TREE_VEC_ELT (r, i) = (*vec)[i];
1634 NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
1635 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
1636 }
1637 else
1638 r = t;
1639 release_tree_vector (vec);
1640 return r;
1641 }
1642
1643 case CONSTRUCTOR:
1644 {
1645 bool changed = false;
1646 vec<constructor_elt, va_gc> *vec
1647 = vec_safe_copy (CONSTRUCTOR_ELTS (t));
1648 n = CONSTRUCTOR_NELTS (t);
1649 type = strip_typedefs (TREE_TYPE (t), remove_attributes);
1650 for (i = 0; i < n; ++i)
1651 {
1652 constructor_elt *e = &(*vec)[i];
1653 tree op = strip_typedefs_expr (e->value, remove_attributes);
1654 if (op != e->value)
1655 {
1656 changed = true;
1657 e->value = op;
1658 }
1659 gcc_checking_assert
1660 (e->index == strip_typedefs_expr (e->index, remove_attributes));
1661 }
1662
1663 if (!changed && type == TREE_TYPE (t))
1664 {
1665 vec_free (vec);
1666 return t;
1667 }
1668 else
1669 {
1670 r = copy_node (t);
1671 TREE_TYPE (r) = type;
1672 CONSTRUCTOR_ELTS (r) = vec;
1673 return r;
1674 }
1675 }
1676
1677 case LAMBDA_EXPR:
1678 error ("lambda-expression in a constant expression");
1679 return error_mark_node;
1680
1681 default:
1682 break;
1683 }
1684
1685 gcc_assert (EXPR_P (t));
1686
1687 n = TREE_OPERAND_LENGTH (t);
1688 ops = XALLOCAVEC (tree, n);
1689 type = TREE_TYPE (t);
1690
1691 switch (code)
1692 {
1693 CASE_CONVERT:
1694 case IMPLICIT_CONV_EXPR:
1695 case DYNAMIC_CAST_EXPR:
1696 case STATIC_CAST_EXPR:
1697 case CONST_CAST_EXPR:
1698 case REINTERPRET_CAST_EXPR:
1699 case CAST_EXPR:
1700 case NEW_EXPR:
1701 type = strip_typedefs (type, remove_attributes);
1702 /* fallthrough */
1703
1704 default:
1705 for (i = 0; i < n; ++i)
1706 ops[i] = strip_typedefs_expr (TREE_OPERAND (t, i), remove_attributes);
1707 break;
1708 }
1709
1710 /* If nothing changed, return t. */
1711 for (i = 0; i < n; ++i)
1712 if (ops[i] != TREE_OPERAND (t, i))
1713 break;
1714 if (i == n && type == TREE_TYPE (t))
1715 return t;
1716
1717 r = copy_node (t);
1718 TREE_TYPE (r) = type;
1719 for (i = 0; i < n; ++i)
1720 TREE_OPERAND (r, i) = ops[i];
1721 return r;
1722 }
1723
1724 /* Makes a copy of BINFO and TYPE, which is to be inherited into a
1725 graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
1726 and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
1727 VIRT indicates whether TYPE is inherited virtually or not.
1728 IGO_PREV points at the previous binfo of the inheritance graph
1729 order chain. The newly copied binfo's TREE_CHAIN forms this
1730 ordering.
1731
1732 The CLASSTYPE_VBASECLASSES vector of T is constructed in the
1733 correct order. That is in the order the bases themselves should be
1734 constructed in.
1735
1736 The BINFO_INHERITANCE of a virtual base class points to the binfo
1737 of the most derived type. ??? We could probably change this so that
1738 BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
1739 remove a field. They currently can only differ for primary virtual
1740 virtual bases. */
1741
1742 tree
1743 copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
1744 {
1745 tree new_binfo;
1746
1747 if (virt)
1748 {
1749 /* See if we've already made this virtual base. */
1750 new_binfo = binfo_for_vbase (type, t);
1751 if (new_binfo)
1752 return new_binfo;
1753 }
1754
1755 new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
1756 BINFO_TYPE (new_binfo) = type;
1757
1758 /* Chain it into the inheritance graph. */
1759 TREE_CHAIN (*igo_prev) = new_binfo;
1760 *igo_prev = new_binfo;
1761
1762 if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
1763 {
1764 int ix;
1765 tree base_binfo;
1766
1767 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
1768
1769 BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
1770 BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
1771
1772 /* We do not need to copy the accesses, as they are read only. */
1773 BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
1774
1775 /* Recursively copy base binfos of BINFO. */
1776 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
1777 {
1778 tree new_base_binfo;
1779 new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
1780 t, igo_prev,
1781 BINFO_VIRTUAL_P (base_binfo));
1782
1783 if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
1784 BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
1785 BINFO_BASE_APPEND (new_binfo, new_base_binfo);
1786 }
1787 }
1788 else
1789 BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
1790
1791 if (virt)
1792 {
1793 /* Push it onto the list after any virtual bases it contains
1794 will have been pushed. */
1795 CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
1796 BINFO_VIRTUAL_P (new_binfo) = 1;
1797 BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
1798 }
1799
1800 return new_binfo;
1801 }
1802 \f
1803 /* Hashing of lists so that we don't make duplicates.
1804 The entry point is `list_hash_canon'. */
1805
1806 struct list_proxy
1807 {
1808 tree purpose;
1809 tree value;
1810 tree chain;
1811 };
1812
1813 struct list_hasher : ggc_ptr_hash<tree_node>
1814 {
1815 typedef list_proxy *compare_type;
1816
1817 static hashval_t hash (tree);
1818 static bool equal (tree, list_proxy *);
1819 };
1820
1821 /* Now here is the hash table. When recording a list, it is added
1822 to the slot whose index is the hash code mod the table size.
1823 Note that the hash table is used for several kinds of lists.
1824 While all these live in the same table, they are completely independent,
1825 and the hash code is computed differently for each of these. */
1826
1827 static GTY (()) hash_table<list_hasher> *list_hash_table;
1828
1829 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
1830 for a node we are thinking about adding). */
1831
1832 bool
1833 list_hasher::equal (tree t, list_proxy *proxy)
1834 {
1835 return (TREE_VALUE (t) == proxy->value
1836 && TREE_PURPOSE (t) == proxy->purpose
1837 && TREE_CHAIN (t) == proxy->chain);
1838 }
1839
1840 /* Compute a hash code for a list (chain of TREE_LIST nodes
1841 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
1842 TREE_COMMON slots), by adding the hash codes of the individual entries. */
1843
1844 static hashval_t
1845 list_hash_pieces (tree purpose, tree value, tree chain)
1846 {
1847 hashval_t hashcode = 0;
1848
1849 if (chain)
1850 hashcode += TREE_HASH (chain);
1851
1852 if (value)
1853 hashcode += TREE_HASH (value);
1854 else
1855 hashcode += 1007;
1856 if (purpose)
1857 hashcode += TREE_HASH (purpose);
1858 else
1859 hashcode += 1009;
1860 return hashcode;
1861 }
1862
1863 /* Hash an already existing TREE_LIST. */
1864
1865 hashval_t
1866 list_hasher::hash (tree t)
1867 {
1868 return list_hash_pieces (TREE_PURPOSE (t),
1869 TREE_VALUE (t),
1870 TREE_CHAIN (t));
1871 }
1872
1873 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1874 object for an identical list if one already exists. Otherwise, build a
1875 new one, and record it as the canonical object. */
1876
1877 tree
1878 hash_tree_cons (tree purpose, tree value, tree chain)
1879 {
1880 int hashcode = 0;
1881 tree *slot;
1882 struct list_proxy proxy;
1883
1884 /* Hash the list node. */
1885 hashcode = list_hash_pieces (purpose, value, chain);
1886 /* Create a proxy for the TREE_LIST we would like to create. We
1887 don't actually create it so as to avoid creating garbage. */
1888 proxy.purpose = purpose;
1889 proxy.value = value;
1890 proxy.chain = chain;
1891 /* See if it is already in the table. */
1892 slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
1893 /* If not, create a new node. */
1894 if (!*slot)
1895 *slot = tree_cons (purpose, value, chain);
1896 return (tree) *slot;
1897 }
1898
1899 /* Constructor for hashed lists. */
1900
1901 tree
1902 hash_tree_chain (tree value, tree chain)
1903 {
1904 return hash_tree_cons (NULL_TREE, value, chain);
1905 }
1906 \f
1907 void
1908 debug_binfo (tree elem)
1909 {
1910 HOST_WIDE_INT n;
1911 tree virtuals;
1912
1913 fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
1914 "\nvtable type:\n",
1915 TYPE_NAME_STRING (BINFO_TYPE (elem)),
1916 TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
1917 debug_tree (BINFO_TYPE (elem));
1918 if (BINFO_VTABLE (elem))
1919 fprintf (stderr, "vtable decl \"%s\"\n",
1920 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
1921 else
1922 fprintf (stderr, "no vtable decl yet\n");
1923 fprintf (stderr, "virtuals:\n");
1924 virtuals = BINFO_VIRTUALS (elem);
1925 n = 0;
1926
1927 while (virtuals)
1928 {
1929 tree fndecl = TREE_VALUE (virtuals);
1930 fprintf (stderr, "%s [%ld =? %ld]\n",
1931 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
1932 (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
1933 ++n;
1934 virtuals = TREE_CHAIN (virtuals);
1935 }
1936 }
1937
1938 /* Build a representation for the qualified name SCOPE::NAME. TYPE is
1939 the type of the result expression, if known, or NULL_TREE if the
1940 resulting expression is type-dependent. If TEMPLATE_P is true,
1941 NAME is known to be a template because the user explicitly used the
1942 "template" keyword after the "::".
1943
1944 All SCOPE_REFs should be built by use of this function. */
1945
1946 tree
1947 build_qualified_name (tree type, tree scope, tree name, bool template_p)
1948 {
1949 tree t;
1950 if (type == error_mark_node
1951 || scope == error_mark_node
1952 || name == error_mark_node)
1953 return error_mark_node;
1954 t = build2 (SCOPE_REF, type, scope, name);
1955 QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
1956 PTRMEM_OK_P (t) = true;
1957 if (type)
1958 t = convert_from_reference (t);
1959 return t;
1960 }
1961
1962 /* Like check_qualified_type, but also check ref-qualifier and exception
1963 specification. */
1964
1965 static bool
1966 cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
1967 cp_ref_qualifier rqual, tree raises)
1968 {
1969 return (check_qualified_type (cand, base, type_quals)
1970 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
1971 ce_exact)
1972 && type_memfn_rqual (cand) == rqual);
1973 }
1974
1975 /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
1976
1977 tree
1978 build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
1979 {
1980 tree t;
1981
1982 if (rqual == type_memfn_rqual (type))
1983 return type;
1984
1985 int type_quals = TYPE_QUALS (type);
1986 tree raises = TYPE_RAISES_EXCEPTIONS (type);
1987 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1988 if (cp_check_qualified_type (t, type, type_quals, rqual, raises))
1989 return t;
1990
1991 t = build_variant_type_copy (type);
1992 switch (rqual)
1993 {
1994 case REF_QUAL_RVALUE:
1995 FUNCTION_RVALUE_QUALIFIED (t) = 1;
1996 FUNCTION_REF_QUALIFIED (t) = 1;
1997 break;
1998 case REF_QUAL_LVALUE:
1999 FUNCTION_RVALUE_QUALIFIED (t) = 0;
2000 FUNCTION_REF_QUALIFIED (t) = 1;
2001 break;
2002 default:
2003 FUNCTION_REF_QUALIFIED (t) = 0;
2004 break;
2005 }
2006
2007 if (TYPE_STRUCTURAL_EQUALITY_P (type))
2008 /* Propagate structural equality. */
2009 SET_TYPE_STRUCTURAL_EQUALITY (t);
2010 else if (TYPE_CANONICAL (type) != type)
2011 /* Build the underlying canonical type, since it is different
2012 from TYPE. */
2013 TYPE_CANONICAL (t) = build_ref_qualified_type (TYPE_CANONICAL (type),
2014 rqual);
2015 else
2016 /* T is its own canonical type. */
2017 TYPE_CANONICAL (t) = t;
2018
2019 return t;
2020 }
2021
2022 /* Returns nonzero if X is an expression for a (possibly overloaded)
2023 function. If "f" is a function or function template, "f", "c->f",
2024 "c.f", "C::f", and "f<int>" will all be considered possibly
2025 overloaded functions. Returns 2 if the function is actually
2026 overloaded, i.e., if it is impossible to know the type of the
2027 function without performing overload resolution. */
2028
2029 int
2030 is_overloaded_fn (tree x)
2031 {
2032 /* A baselink is also considered an overloaded function. */
2033 if (TREE_CODE (x) == OFFSET_REF
2034 || TREE_CODE (x) == COMPONENT_REF)
2035 x = TREE_OPERAND (x, 1);
2036 if (BASELINK_P (x))
2037 x = BASELINK_FUNCTIONS (x);
2038 if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2039 x = TREE_OPERAND (x, 0);
2040 if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
2041 || (TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x)))
2042 return 2;
2043 return (TREE_CODE (x) == FUNCTION_DECL
2044 || TREE_CODE (x) == OVERLOAD);
2045 }
2046
2047 /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
2048 (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
2049 NULL_TREE. */
2050
2051 tree
2052 dependent_name (tree x)
2053 {
2054 if (identifier_p (x))
2055 return x;
2056 if (TREE_CODE (x) != COMPONENT_REF
2057 && TREE_CODE (x) != OFFSET_REF
2058 && TREE_CODE (x) != BASELINK
2059 && is_overloaded_fn (x))
2060 return DECL_NAME (get_first_fn (x));
2061 return NULL_TREE;
2062 }
2063
2064 /* Returns true iff X is an expression for an overloaded function
2065 whose type cannot be known without performing overload
2066 resolution. */
2067
2068 bool
2069 really_overloaded_fn (tree x)
2070 {
2071 return is_overloaded_fn (x) == 2;
2072 }
2073
2074 tree
2075 get_fns (tree from)
2076 {
2077 gcc_assert (is_overloaded_fn (from));
2078 /* A baselink is also considered an overloaded function. */
2079 if (TREE_CODE (from) == OFFSET_REF
2080 || TREE_CODE (from) == COMPONENT_REF)
2081 from = TREE_OPERAND (from, 1);
2082 if (BASELINK_P (from))
2083 from = BASELINK_FUNCTIONS (from);
2084 if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
2085 from = TREE_OPERAND (from, 0);
2086 return from;
2087 }
2088
2089 tree
2090 get_first_fn (tree from)
2091 {
2092 return OVL_CURRENT (get_fns (from));
2093 }
2094
2095 /* Return a new OVL node, concatenating it with the old one. */
2096
2097 tree
2098 ovl_cons (tree decl, tree chain)
2099 {
2100 tree result = make_node (OVERLOAD);
2101 TREE_TYPE (result) = unknown_type_node;
2102 OVL_FUNCTION (result) = decl;
2103 TREE_CHAIN (result) = chain;
2104
2105 return result;
2106 }
2107
2108 /* Build a new overloaded function. If this is the first one,
2109 just return it; otherwise, ovl_cons the _DECLs */
2110
2111 tree
2112 build_overload (tree decl, tree chain)
2113 {
2114 if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
2115 return decl;
2116 return ovl_cons (decl, chain);
2117 }
2118
2119 /* Return the scope where the overloaded functions OVL were found. */
2120
2121 tree
2122 ovl_scope (tree ovl)
2123 {
2124 if (TREE_CODE (ovl) == OFFSET_REF
2125 || TREE_CODE (ovl) == COMPONENT_REF)
2126 ovl = TREE_OPERAND (ovl, 1);
2127 if (TREE_CODE (ovl) == BASELINK)
2128 return BINFO_TYPE (BASELINK_BINFO (ovl));
2129 if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
2130 ovl = TREE_OPERAND (ovl, 0);
2131 /* Skip using-declarations. */
2132 while (TREE_CODE (ovl) == OVERLOAD && OVL_USED (ovl) && OVL_CHAIN (ovl))
2133 ovl = OVL_CHAIN (ovl);
2134 return CP_DECL_CONTEXT (OVL_CURRENT (ovl));
2135 }
2136 \f
2137 #define PRINT_RING_SIZE 4
2138
2139 static const char *
2140 cxx_printable_name_internal (tree decl, int v, bool translate)
2141 {
2142 static unsigned int uid_ring[PRINT_RING_SIZE];
2143 static char *print_ring[PRINT_RING_SIZE];
2144 static bool trans_ring[PRINT_RING_SIZE];
2145 static int ring_counter;
2146 int i;
2147
2148 /* Only cache functions. */
2149 if (v < 2
2150 || TREE_CODE (decl) != FUNCTION_DECL
2151 || DECL_LANG_SPECIFIC (decl) == 0)
2152 return lang_decl_name (decl, v, translate);
2153
2154 /* See if this print name is lying around. */
2155 for (i = 0; i < PRINT_RING_SIZE; i++)
2156 if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2157 /* yes, so return it. */
2158 return print_ring[i];
2159
2160 if (++ring_counter == PRINT_RING_SIZE)
2161 ring_counter = 0;
2162
2163 if (current_function_decl != NULL_TREE)
2164 {
2165 /* There may be both translated and untranslated versions of the
2166 name cached. */
2167 for (i = 0; i < 2; i++)
2168 {
2169 if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
2170 ring_counter += 1;
2171 if (ring_counter == PRINT_RING_SIZE)
2172 ring_counter = 0;
2173 }
2174 gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
2175 }
2176
2177 free (print_ring[ring_counter]);
2178
2179 print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
2180 uid_ring[ring_counter] = DECL_UID (decl);
2181 trans_ring[ring_counter] = translate;
2182 return print_ring[ring_counter];
2183 }
2184
2185 const char *
2186 cxx_printable_name (tree decl, int v)
2187 {
2188 return cxx_printable_name_internal (decl, v, false);
2189 }
2190
2191 const char *
2192 cxx_printable_name_translate (tree decl, int v)
2193 {
2194 return cxx_printable_name_internal (decl, v, true);
2195 }
2196 \f
2197 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
2198 listed in RAISES. */
2199
2200 tree
2201 build_exception_variant (tree type, tree raises)
2202 {
2203 tree v;
2204 int type_quals;
2205
2206 if (comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (type), ce_exact))
2207 return type;
2208
2209 type_quals = TYPE_QUALS (type);
2210 cp_ref_qualifier rqual = type_memfn_rqual (type);
2211 for (v = TYPE_MAIN_VARIANT (type); v; v = TYPE_NEXT_VARIANT (v))
2212 if (cp_check_qualified_type (v, type, type_quals, rqual, raises))
2213 return v;
2214
2215 /* Need to build a new variant. */
2216 v = build_variant_type_copy (type);
2217 TYPE_RAISES_EXCEPTIONS (v) = raises;
2218 return v;
2219 }
2220
2221 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
2222 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
2223 arguments. */
2224
2225 tree
2226 bind_template_template_parm (tree t, tree newargs)
2227 {
2228 tree decl = TYPE_NAME (t);
2229 tree t2;
2230
2231 t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
2232 decl = build_decl (input_location,
2233 TYPE_DECL, DECL_NAME (decl), NULL_TREE);
2234
2235 /* These nodes have to be created to reflect new TYPE_DECL and template
2236 arguments. */
2237 TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
2238 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
2239 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
2240 = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
2241
2242 TREE_TYPE (decl) = t2;
2243 TYPE_NAME (t2) = decl;
2244 TYPE_STUB_DECL (t2) = decl;
2245 TYPE_SIZE (t2) = 0;
2246 SET_TYPE_STRUCTURAL_EQUALITY (t2);
2247
2248 return t2;
2249 }
2250
2251 /* Called from count_trees via walk_tree. */
2252
2253 static tree
2254 count_trees_r (tree *tp, int *walk_subtrees, void *data)
2255 {
2256 ++*((int *) data);
2257
2258 if (TYPE_P (*tp))
2259 *walk_subtrees = 0;
2260
2261 return NULL_TREE;
2262 }
2263
2264 /* Debugging function for measuring the rough complexity of a tree
2265 representation. */
2266
2267 int
2268 count_trees (tree t)
2269 {
2270 int n_trees = 0;
2271 cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
2272 return n_trees;
2273 }
2274
2275 /* Called from verify_stmt_tree via walk_tree. */
2276
2277 static tree
2278 verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
2279 {
2280 tree t = *tp;
2281 hash_table<nofree_ptr_hash <tree_node> > *statements
2282 = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
2283 tree_node **slot;
2284
2285 if (!STATEMENT_CODE_P (TREE_CODE (t)))
2286 return NULL_TREE;
2287
2288 /* If this statement is already present in the hash table, then
2289 there is a circularity in the statement tree. */
2290 gcc_assert (!statements->find (t));
2291
2292 slot = statements->find_slot (t, INSERT);
2293 *slot = t;
2294
2295 return NULL_TREE;
2296 }
2297
2298 /* Debugging function to check that the statement T has not been
2299 corrupted. For now, this function simply checks that T contains no
2300 circularities. */
2301
2302 void
2303 verify_stmt_tree (tree t)
2304 {
2305 hash_table<nofree_ptr_hash <tree_node> > statements (37);
2306 cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
2307 }
2308
2309 /* Check if the type T depends on a type with no linkage and if so, return
2310 it. If RELAXED_P then do not consider a class type declared within
2311 a vague-linkage function to have no linkage. */
2312
2313 tree
2314 no_linkage_check (tree t, bool relaxed_p)
2315 {
2316 tree r;
2317
2318 /* There's no point in checking linkage on template functions; we
2319 can't know their complete types. */
2320 if (processing_template_decl)
2321 return NULL_TREE;
2322
2323 switch (TREE_CODE (t))
2324 {
2325 case RECORD_TYPE:
2326 if (TYPE_PTRMEMFUNC_P (t))
2327 goto ptrmem;
2328 /* Lambda types that don't have mangling scope have no linkage. We
2329 check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
2330 when we get here from pushtag none of the lambda information is
2331 set up yet, so we want to assume that the lambda has linkage and
2332 fix it up later if not. */
2333 if (CLASSTYPE_LAMBDA_EXPR (t)
2334 && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node
2335 && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE)
2336 return t;
2337 /* Fall through. */
2338 case UNION_TYPE:
2339 if (!CLASS_TYPE_P (t))
2340 return NULL_TREE;
2341 /* Fall through. */
2342 case ENUMERAL_TYPE:
2343 /* Only treat anonymous types as having no linkage if they're at
2344 namespace scope. This is core issue 966. */
2345 if (TYPE_ANONYMOUS_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
2346 return t;
2347
2348 for (r = CP_TYPE_CONTEXT (t); ; )
2349 {
2350 /* If we're a nested type of a !TREE_PUBLIC class, we might not
2351 have linkage, or we might just be in an anonymous namespace.
2352 If we're in a TREE_PUBLIC class, we have linkage. */
2353 if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
2354 return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
2355 else if (TREE_CODE (r) == FUNCTION_DECL)
2356 {
2357 if (!relaxed_p || !vague_linkage_p (r))
2358 return t;
2359 else
2360 r = CP_DECL_CONTEXT (r);
2361 }
2362 else
2363 break;
2364 }
2365
2366 return NULL_TREE;
2367
2368 case ARRAY_TYPE:
2369 case POINTER_TYPE:
2370 case REFERENCE_TYPE:
2371 case VECTOR_TYPE:
2372 return no_linkage_check (TREE_TYPE (t), relaxed_p);
2373
2374 case OFFSET_TYPE:
2375 ptrmem:
2376 r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
2377 relaxed_p);
2378 if (r)
2379 return r;
2380 return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
2381
2382 case METHOD_TYPE:
2383 case FUNCTION_TYPE:
2384 {
2385 tree parm = TYPE_ARG_TYPES (t);
2386 if (TREE_CODE (t) == METHOD_TYPE)
2387 /* The 'this' pointer isn't interesting; a method has the same
2388 linkage (or lack thereof) as its enclosing class. */
2389 parm = TREE_CHAIN (parm);
2390 for (;
2391 parm && parm != void_list_node;
2392 parm = TREE_CHAIN (parm))
2393 {
2394 r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
2395 if (r)
2396 return r;
2397 }
2398 return no_linkage_check (TREE_TYPE (t), relaxed_p);
2399 }
2400
2401 default:
2402 return NULL_TREE;
2403 }
2404 }
2405
2406 extern int depth_reached;
2407
2408 void
2409 cxx_print_statistics (void)
2410 {
2411 print_search_statistics ();
2412 print_class_statistics ();
2413 print_template_statistics ();
2414 if (GATHER_STATISTICS)
2415 fprintf (stderr, "maximum template instantiation depth reached: %d\n",
2416 depth_reached);
2417 }
2418
2419 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2420 (which is an ARRAY_TYPE). This counts only elements of the top
2421 array. */
2422
2423 tree
2424 array_type_nelts_top (tree type)
2425 {
2426 return fold_build2_loc (input_location,
2427 PLUS_EXPR, sizetype,
2428 array_type_nelts (type),
2429 size_one_node);
2430 }
2431
2432 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2433 (which is an ARRAY_TYPE). This one is a recursive count of all
2434 ARRAY_TYPEs that are clumped together. */
2435
2436 tree
2437 array_type_nelts_total (tree type)
2438 {
2439 tree sz = array_type_nelts_top (type);
2440 type = TREE_TYPE (type);
2441 while (TREE_CODE (type) == ARRAY_TYPE)
2442 {
2443 tree n = array_type_nelts_top (type);
2444 sz = fold_build2_loc (input_location,
2445 MULT_EXPR, sizetype, sz, n);
2446 type = TREE_TYPE (type);
2447 }
2448 return sz;
2449 }
2450
2451 /* Called from break_out_target_exprs via mapcar. */
2452
2453 static tree
2454 bot_manip (tree* tp, int* walk_subtrees, void* data)
2455 {
2456 splay_tree target_remap = ((splay_tree) data);
2457 tree t = *tp;
2458
2459 if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
2460 {
2461 /* There can't be any TARGET_EXPRs or their slot variables below this
2462 point. But we must make a copy, in case subsequent processing
2463 alters any part of it. For example, during gimplification a cast
2464 of the form (T) &X::f (where "f" is a member function) will lead
2465 to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
2466 *walk_subtrees = 0;
2467 *tp = unshare_expr (t);
2468 return NULL_TREE;
2469 }
2470 if (TREE_CODE (t) == TARGET_EXPR)
2471 {
2472 tree u;
2473
2474 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
2475 {
2476 u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1),
2477 tf_warning_or_error);
2478 if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t, 1)))
2479 AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true;
2480 }
2481 else
2482 u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t),
2483 tf_warning_or_error);
2484
2485 TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
2486 TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
2487 TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
2488
2489 /* Map the old variable to the new one. */
2490 splay_tree_insert (target_remap,
2491 (splay_tree_key) TREE_OPERAND (t, 0),
2492 (splay_tree_value) TREE_OPERAND (u, 0));
2493
2494 TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1));
2495
2496 /* Replace the old expression with the new version. */
2497 *tp = u;
2498 /* We don't have to go below this point; the recursive call to
2499 break_out_target_exprs will have handled anything below this
2500 point. */
2501 *walk_subtrees = 0;
2502 return NULL_TREE;
2503 }
2504 if (TREE_CODE (*tp) == SAVE_EXPR)
2505 {
2506 t = *tp;
2507 splay_tree_node n = splay_tree_lookup (target_remap,
2508 (splay_tree_key) t);
2509 if (n)
2510 {
2511 *tp = (tree)n->value;
2512 *walk_subtrees = 0;
2513 }
2514 else
2515 {
2516 copy_tree_r (tp, walk_subtrees, NULL);
2517 splay_tree_insert (target_remap,
2518 (splay_tree_key)t,
2519 (splay_tree_value)*tp);
2520 /* Make sure we don't remap an already-remapped SAVE_EXPR. */
2521 splay_tree_insert (target_remap,
2522 (splay_tree_key)*tp,
2523 (splay_tree_value)*tp);
2524 }
2525 return NULL_TREE;
2526 }
2527
2528 /* Make a copy of this node. */
2529 t = copy_tree_r (tp, walk_subtrees, NULL);
2530 if (TREE_CODE (*tp) == CALL_EXPR)
2531 {
2532 set_flags_from_callee (*tp);
2533
2534 /* builtin_LINE and builtin_FILE get the location where the default
2535 argument is expanded, not where the call was written. */
2536 tree callee = get_callee_fndecl (*tp);
2537 if (callee && DECL_BUILT_IN (callee))
2538 switch (DECL_FUNCTION_CODE (callee))
2539 {
2540 case BUILT_IN_FILE:
2541 case BUILT_IN_LINE:
2542 SET_EXPR_LOCATION (*tp, input_location);
2543 default:
2544 break;
2545 }
2546 }
2547 return t;
2548 }
2549
2550 /* Replace all remapped VAR_DECLs in T with their new equivalents.
2551 DATA is really a splay-tree mapping old variables to new
2552 variables. */
2553
2554 static tree
2555 bot_replace (tree* t, int* /*walk_subtrees*/, void* data)
2556 {
2557 splay_tree target_remap = ((splay_tree) data);
2558
2559 if (VAR_P (*t))
2560 {
2561 splay_tree_node n = splay_tree_lookup (target_remap,
2562 (splay_tree_key) *t);
2563 if (n)
2564 *t = (tree) n->value;
2565 }
2566 else if (TREE_CODE (*t) == PARM_DECL
2567 && DECL_NAME (*t) == this_identifier
2568 && !DECL_CONTEXT (*t))
2569 {
2570 /* In an NSDMI we need to replace the 'this' parameter we used for
2571 parsing with the real one for this function. */
2572 *t = current_class_ptr;
2573 }
2574 else if (TREE_CODE (*t) == CONVERT_EXPR
2575 && CONVERT_EXPR_VBASE_PATH (*t))
2576 {
2577 /* In an NSDMI build_base_path defers building conversions to virtual
2578 bases, and we handle it here. */
2579 tree basetype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (*t)));
2580 vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (current_class_type);
2581 int i; tree binfo;
2582 FOR_EACH_VEC_SAFE_ELT (vbases, i, binfo)
2583 if (BINFO_TYPE (binfo) == basetype)
2584 break;
2585 *t = build_base_path (PLUS_EXPR, TREE_OPERAND (*t, 0), binfo, true,
2586 tf_warning_or_error);
2587 }
2588
2589 return NULL_TREE;
2590 }
2591
2592 /* When we parse a default argument expression, we may create
2593 temporary variables via TARGET_EXPRs. When we actually use the
2594 default-argument expression, we make a copy of the expression
2595 and replace the temporaries with appropriate local versions. */
2596
2597 tree
2598 break_out_target_exprs (tree t)
2599 {
2600 static int target_remap_count;
2601 static splay_tree target_remap;
2602
2603 if (!target_remap_count++)
2604 target_remap = splay_tree_new (splay_tree_compare_pointers,
2605 /*splay_tree_delete_key_fn=*/NULL,
2606 /*splay_tree_delete_value_fn=*/NULL);
2607 cp_walk_tree (&t, bot_manip, target_remap, NULL);
2608 cp_walk_tree (&t, bot_replace, target_remap, NULL);
2609
2610 if (!--target_remap_count)
2611 {
2612 splay_tree_delete (target_remap);
2613 target_remap = NULL;
2614 }
2615
2616 return t;
2617 }
2618
2619 /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
2620 which we expect to have type TYPE. */
2621
2622 tree
2623 build_ctor_subob_ref (tree index, tree type, tree obj)
2624 {
2625 if (index == NULL_TREE)
2626 /* Can't refer to a particular member of a vector. */
2627 obj = NULL_TREE;
2628 else if (TREE_CODE (index) == INTEGER_CST)
2629 obj = cp_build_array_ref (input_location, obj, index, tf_none);
2630 else
2631 obj = build_class_member_access_expr (obj, index, NULL_TREE,
2632 /*reference*/false, tf_none);
2633 if (obj)
2634 {
2635 tree objtype = TREE_TYPE (obj);
2636 if (TREE_CODE (objtype) == ARRAY_TYPE && !TYPE_DOMAIN (objtype))
2637 {
2638 /* When the destination object refers to a flexible array member
2639 verify that it matches the type of the source object except
2640 for its domain and qualifiers. */
2641 gcc_assert (comptypes (TYPE_MAIN_VARIANT (type),
2642 TYPE_MAIN_VARIANT (objtype),
2643 COMPARE_REDECLARATION));
2644 }
2645 else
2646 gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
2647 }
2648
2649 return obj;
2650 }
2651
2652 /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
2653 build up subexpressions as we go deeper. */
2654
2655 static tree
2656 replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
2657 {
2658 tree obj = static_cast<tree>(data_);
2659
2660 if (TREE_CONSTANT (*t))
2661 {
2662 *walk_subtrees = false;
2663 return NULL_TREE;
2664 }
2665
2666 switch (TREE_CODE (*t))
2667 {
2668 case PLACEHOLDER_EXPR:
2669 {
2670 tree x = obj;
2671 for (; !(same_type_ignoring_top_level_qualifiers_p
2672 (TREE_TYPE (*t), TREE_TYPE (x)));
2673 x = TREE_OPERAND (x, 0))
2674 gcc_assert (TREE_CODE (x) == COMPONENT_REF);
2675 *t = x;
2676 *walk_subtrees = false;
2677 }
2678 break;
2679
2680 case CONSTRUCTOR:
2681 {
2682 constructor_elt *ce;
2683 vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t);
2684 for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
2685 {
2686 tree *valp = &ce->value;
2687 tree type = TREE_TYPE (*valp);
2688 tree subob = obj;
2689
2690 if (TREE_CODE (*valp) == CONSTRUCTOR
2691 && AGGREGATE_TYPE_P (type))
2692 {
2693 /* If we're looking at the initializer for OBJ, then build
2694 a sub-object reference. If we're looking at an
2695 initializer for another object, just pass OBJ down. */
2696 if (same_type_ignoring_top_level_qualifiers_p
2697 (TREE_TYPE (*t), TREE_TYPE (obj)))
2698 subob = build_ctor_subob_ref (ce->index, type, obj);
2699 if (TREE_CODE (*valp) == TARGET_EXPR)
2700 valp = &TARGET_EXPR_INITIAL (*valp);
2701 }
2702
2703 cp_walk_tree (valp, replace_placeholders_r,
2704 subob, NULL);
2705 }
2706 *walk_subtrees = false;
2707 break;
2708 }
2709
2710 default:
2711 break;
2712 }
2713
2714 return NULL_TREE;
2715 }
2716
2717 tree
2718 replace_placeholders (tree exp, tree obj)
2719 {
2720 tree *tp = &exp;
2721 if (TREE_CODE (exp) == TARGET_EXPR)
2722 tp = &TARGET_EXPR_INITIAL (exp);
2723 cp_walk_tree (tp, replace_placeholders_r, obj, NULL);
2724 return exp;
2725 }
2726
2727 /* Similar to `build_nt', but for template definitions of dependent
2728 expressions */
2729
2730 tree
2731 build_min_nt_loc (location_t loc, enum tree_code code, ...)
2732 {
2733 tree t;
2734 int length;
2735 int i;
2736 va_list p;
2737
2738 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
2739
2740 va_start (p, code);
2741
2742 t = make_node (code);
2743 SET_EXPR_LOCATION (t, loc);
2744 length = TREE_CODE_LENGTH (code);
2745
2746 for (i = 0; i < length; i++)
2747 {
2748 tree x = va_arg (p, tree);
2749 TREE_OPERAND (t, i) = x;
2750 }
2751
2752 va_end (p);
2753 return t;
2754 }
2755
2756
2757 /* Similar to `build', but for template definitions. */
2758
2759 tree
2760 build_min (enum tree_code code, tree tt, ...)
2761 {
2762 tree t;
2763 int length;
2764 int i;
2765 va_list p;
2766
2767 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
2768
2769 va_start (p, tt);
2770
2771 t = make_node (code);
2772 length = TREE_CODE_LENGTH (code);
2773 TREE_TYPE (t) = tt;
2774
2775 for (i = 0; i < length; i++)
2776 {
2777 tree x = va_arg (p, tree);
2778 TREE_OPERAND (t, i) = x;
2779 if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
2780 TREE_SIDE_EFFECTS (t) = 1;
2781 }
2782
2783 va_end (p);
2784 return t;
2785 }
2786
2787 /* Similar to `build', but for template definitions of non-dependent
2788 expressions. NON_DEP is the non-dependent expression that has been
2789 built. */
2790
2791 tree
2792 build_min_non_dep (enum tree_code code, tree non_dep, ...)
2793 {
2794 tree t;
2795 int length;
2796 int i;
2797 va_list p;
2798
2799 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
2800
2801 va_start (p, non_dep);
2802
2803 if (REFERENCE_REF_P (non_dep))
2804 non_dep = TREE_OPERAND (non_dep, 0);
2805
2806 t = make_node (code);
2807 length = TREE_CODE_LENGTH (code);
2808 TREE_TYPE (t) = TREE_TYPE (non_dep);
2809 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
2810
2811 for (i = 0; i < length; i++)
2812 {
2813 tree x = va_arg (p, tree);
2814 TREE_OPERAND (t, i) = x;
2815 }
2816
2817 if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR)
2818 /* This should not be considered a COMPOUND_EXPR, because it
2819 resolves to an overload. */
2820 COMPOUND_EXPR_OVERLOADED (t) = 1;
2821
2822 va_end (p);
2823 return convert_from_reference (t);
2824 }
2825
2826 /* Similar to `build_nt_call_vec', but for template definitions of
2827 non-dependent expressions. NON_DEP is the non-dependent expression
2828 that has been built. */
2829
2830 tree
2831 build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
2832 {
2833 tree t = build_nt_call_vec (fn, argvec);
2834 if (REFERENCE_REF_P (non_dep))
2835 non_dep = TREE_OPERAND (non_dep, 0);
2836 TREE_TYPE (t) = TREE_TYPE (non_dep);
2837 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
2838 return convert_from_reference (t);
2839 }
2840
2841 /* Similar to build_min_non_dep, but for expressions that have been resolved to
2842 a call to an operator overload. OP is the operator that has been
2843 overloaded. NON_DEP is the non-dependent expression that's been built,
2844 which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR. OVERLOAD is
2845 the overload that NON_DEP is calling. */
2846
2847 tree
2848 build_min_non_dep_op_overload (enum tree_code op,
2849 tree non_dep,
2850 tree overload, ...)
2851 {
2852 va_list p;
2853 int nargs, expected_nargs;
2854 tree fn, call;
2855 vec<tree, va_gc> *args;
2856
2857 if (REFERENCE_REF_P (non_dep))
2858 non_dep = TREE_OPERAND (non_dep, 0);
2859
2860 nargs = call_expr_nargs (non_dep);
2861
2862 expected_nargs = cp_tree_code_length (op);
2863 if (op == POSTINCREMENT_EXPR
2864 || op == POSTDECREMENT_EXPR)
2865 expected_nargs += 1;
2866 gcc_assert (nargs == expected_nargs);
2867
2868 args = make_tree_vector ();
2869 va_start (p, overload);
2870
2871 if (TREE_CODE (TREE_TYPE (overload)) == FUNCTION_TYPE)
2872 {
2873 fn = overload;
2874 for (int i = 0; i < nargs; i++)
2875 {
2876 tree arg = va_arg (p, tree);
2877 vec_safe_push (args, arg);
2878 }
2879 }
2880 else if (TREE_CODE (TREE_TYPE (overload)) == METHOD_TYPE)
2881 {
2882 tree object = va_arg (p, tree);
2883 tree binfo = TYPE_BINFO (TREE_TYPE (object));
2884 tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
2885 fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
2886 object, method, NULL_TREE);
2887 for (int i = 1; i < nargs; i++)
2888 {
2889 tree arg = va_arg (p, tree);
2890 vec_safe_push (args, arg);
2891 }
2892 }
2893 else
2894 gcc_unreachable ();
2895
2896 va_end (p);
2897 call = build_min_non_dep_call_vec (non_dep, fn, args);
2898 release_tree_vector (args);
2899
2900 tree call_expr = call;
2901 if (REFERENCE_REF_P (call_expr))
2902 call_expr = TREE_OPERAND (call_expr, 0);
2903 KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
2904
2905 return call;
2906 }
2907
2908 tree
2909 get_type_decl (tree t)
2910 {
2911 if (TREE_CODE (t) == TYPE_DECL)
2912 return t;
2913 if (TYPE_P (t))
2914 return TYPE_STUB_DECL (t);
2915 gcc_assert (t == error_mark_node);
2916 return t;
2917 }
2918
2919 /* Returns the namespace that contains DECL, whether directly or
2920 indirectly. */
2921
2922 tree
2923 decl_namespace_context (tree decl)
2924 {
2925 while (1)
2926 {
2927 if (TREE_CODE (decl) == NAMESPACE_DECL)
2928 return decl;
2929 else if (TYPE_P (decl))
2930 decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
2931 else
2932 decl = CP_DECL_CONTEXT (decl);
2933 }
2934 }
2935
2936 /* Returns true if decl is within an anonymous namespace, however deeply
2937 nested, or false otherwise. */
2938
2939 bool
2940 decl_anon_ns_mem_p (const_tree decl)
2941 {
2942 while (1)
2943 {
2944 if (decl == NULL_TREE || decl == error_mark_node)
2945 return false;
2946 if (TREE_CODE (decl) == NAMESPACE_DECL
2947 && DECL_NAME (decl) == NULL_TREE)
2948 return true;
2949 /* Classes and namespaces inside anonymous namespaces have
2950 TREE_PUBLIC == 0, so we can shortcut the search. */
2951 else if (TYPE_P (decl))
2952 return (TREE_PUBLIC (TYPE_MAIN_DECL (decl)) == 0);
2953 else if (TREE_CODE (decl) == NAMESPACE_DECL)
2954 return (TREE_PUBLIC (decl) == 0);
2955 else
2956 decl = DECL_CONTEXT (decl);
2957 }
2958 }
2959
2960 /* Subroutine of cp_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
2961 CALL_EXPRS. Return whether they are equivalent. */
2962
2963 static bool
2964 called_fns_equal (tree t1, tree t2)
2965 {
2966 /* Core 1321: dependent names are equivalent even if the overload sets
2967 are different. But do compare explicit template arguments. */
2968 tree name1 = dependent_name (t1);
2969 tree name2 = dependent_name (t2);
2970 if (name1 || name2)
2971 {
2972 tree targs1 = NULL_TREE, targs2 = NULL_TREE;
2973
2974 if (name1 != name2)
2975 return false;
2976
2977 if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
2978 targs1 = TREE_OPERAND (t1, 1);
2979 if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
2980 targs2 = TREE_OPERAND (t2, 1);
2981 return cp_tree_equal (targs1, targs2);
2982 }
2983 else
2984 return cp_tree_equal (t1, t2);
2985 }
2986
2987 /* Return truthvalue of whether T1 is the same tree structure as T2.
2988 Return 1 if they are the same. Return 0 if they are different. */
2989
2990 bool
2991 cp_tree_equal (tree t1, tree t2)
2992 {
2993 enum tree_code code1, code2;
2994
2995 if (t1 == t2)
2996 return true;
2997 if (!t1 || !t2)
2998 return false;
2999
3000 code1 = TREE_CODE (t1);
3001 code2 = TREE_CODE (t2);
3002
3003 if (code1 != code2)
3004 return false;
3005
3006 switch (code1)
3007 {
3008 case VOID_CST:
3009 /* There's only a single VOID_CST node, so we should never reach
3010 here. */
3011 gcc_unreachable ();
3012
3013 case INTEGER_CST:
3014 return tree_int_cst_equal (t1, t2);
3015
3016 case REAL_CST:
3017 return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
3018
3019 case STRING_CST:
3020 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3021 && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3022 TREE_STRING_LENGTH (t1));
3023
3024 case FIXED_CST:
3025 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
3026 TREE_FIXED_CST (t2));
3027
3028 case COMPLEX_CST:
3029 return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
3030 && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
3031
3032 case VECTOR_CST:
3033 return operand_equal_p (t1, t2, OEP_ONLY_CONST);
3034
3035 case CONSTRUCTOR:
3036 /* We need to do this when determining whether or not two
3037 non-type pointer to member function template arguments
3038 are the same. */
3039 if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
3040 || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
3041 return false;
3042 {
3043 tree field, value;
3044 unsigned int i;
3045 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
3046 {
3047 constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
3048 if (!cp_tree_equal (field, elt2->index)
3049 || !cp_tree_equal (value, elt2->value))
3050 return false;
3051 }
3052 }
3053 return true;
3054
3055 case TREE_LIST:
3056 if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
3057 return false;
3058 if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
3059 return false;
3060 return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
3061
3062 case SAVE_EXPR:
3063 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3064
3065 case CALL_EXPR:
3066 {
3067 tree arg1, arg2;
3068 call_expr_arg_iterator iter1, iter2;
3069 if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
3070 return false;
3071 for (arg1 = first_call_expr_arg (t1, &iter1),
3072 arg2 = first_call_expr_arg (t2, &iter2);
3073 arg1 && arg2;
3074 arg1 = next_call_expr_arg (&iter1),
3075 arg2 = next_call_expr_arg (&iter2))
3076 if (!cp_tree_equal (arg1, arg2))
3077 return false;
3078 if (arg1 || arg2)
3079 return false;
3080 return true;
3081 }
3082
3083 case TARGET_EXPR:
3084 {
3085 tree o1 = TREE_OPERAND (t1, 0);
3086 tree o2 = TREE_OPERAND (t2, 0);
3087
3088 /* Special case: if either target is an unallocated VAR_DECL,
3089 it means that it's going to be unified with whatever the
3090 TARGET_EXPR is really supposed to initialize, so treat it
3091 as being equivalent to anything. */
3092 if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
3093 && !DECL_RTL_SET_P (o1))
3094 /*Nop*/;
3095 else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
3096 && !DECL_RTL_SET_P (o2))
3097 /*Nop*/;
3098 else if (!cp_tree_equal (o1, o2))
3099 return false;
3100
3101 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3102 }
3103
3104 case WITH_CLEANUP_EXPR:
3105 if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
3106 return false;
3107 return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
3108
3109 case COMPONENT_REF:
3110 if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
3111 return false;
3112 return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3113
3114 case PARM_DECL:
3115 /* For comparing uses of parameters in late-specified return types
3116 with an out-of-class definition of the function, but can also come
3117 up for expressions that involve 'this' in a member function
3118 template. */
3119
3120 if (comparing_specializations && !CONSTRAINT_VAR_P (t1))
3121 /* When comparing hash table entries, only an exact match is
3122 good enough; we don't want to replace 'this' with the
3123 version from another function. But be more flexible
3124 with local parameters in a requires-expression. */
3125 return false;
3126
3127 if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
3128 {
3129 if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
3130 return false;
3131 if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
3132 return false;
3133 if (DECL_ARTIFICIAL (t1)
3134 || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
3135 && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
3136 return true;
3137 }
3138 return false;
3139
3140 case VAR_DECL:
3141 case CONST_DECL:
3142 case FIELD_DECL:
3143 case FUNCTION_DECL:
3144 case TEMPLATE_DECL:
3145 case IDENTIFIER_NODE:
3146 case SSA_NAME:
3147 return false;
3148
3149 case BASELINK:
3150 return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
3151 && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
3152 && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
3153 && cp_tree_equal (BASELINK_FUNCTIONS (t1),
3154 BASELINK_FUNCTIONS (t2)));
3155
3156 case TEMPLATE_PARM_INDEX:
3157 return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
3158 && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
3159 && (TEMPLATE_PARM_PARAMETER_PACK (t1)
3160 == TEMPLATE_PARM_PARAMETER_PACK (t2))
3161 && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
3162 TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
3163
3164 case TEMPLATE_ID_EXPR:
3165 return (cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3166 && cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3167
3168 case CONSTRAINT_INFO:
3169 return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
3170 CI_ASSOCIATED_CONSTRAINTS (t2));
3171
3172 case TREE_VEC:
3173 {
3174 unsigned ix;
3175 if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
3176 return false;
3177 for (ix = TREE_VEC_LENGTH (t1); ix--;)
3178 if (!cp_tree_equal (TREE_VEC_ELT (t1, ix),
3179 TREE_VEC_ELT (t2, ix)))
3180 return false;
3181 return true;
3182 }
3183
3184 case SIZEOF_EXPR:
3185 case ALIGNOF_EXPR:
3186 {
3187 tree o1 = TREE_OPERAND (t1, 0);
3188 tree o2 = TREE_OPERAND (t2, 0);
3189
3190 if (code1 == SIZEOF_EXPR)
3191 {
3192 if (SIZEOF_EXPR_TYPE_P (t1))
3193 o1 = TREE_TYPE (o1);
3194 if (SIZEOF_EXPR_TYPE_P (t2))
3195 o2 = TREE_TYPE (o2);
3196 }
3197 if (TREE_CODE (o1) != TREE_CODE (o2))
3198 return false;
3199 if (TYPE_P (o1))
3200 return same_type_p (o1, o2);
3201 else
3202 return cp_tree_equal (o1, o2);
3203 }
3204
3205 case MODOP_EXPR:
3206 {
3207 tree t1_op1, t2_op1;
3208
3209 if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
3210 return false;
3211
3212 t1_op1 = TREE_OPERAND (t1, 1);
3213 t2_op1 = TREE_OPERAND (t2, 1);
3214 if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
3215 return false;
3216
3217 return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
3218 }
3219
3220 case PTRMEM_CST:
3221 /* Two pointer-to-members are the same if they point to the same
3222 field or function in the same class. */
3223 if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
3224 return false;
3225
3226 return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
3227
3228 case OVERLOAD:
3229 if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2))
3230 return false;
3231 return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2));
3232
3233 case TRAIT_EXPR:
3234 if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
3235 return false;
3236 return same_type_p (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
3237 && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
3238
3239 case CAST_EXPR:
3240 case STATIC_CAST_EXPR:
3241 case REINTERPRET_CAST_EXPR:
3242 case CONST_CAST_EXPR:
3243 case DYNAMIC_CAST_EXPR:
3244 case IMPLICIT_CONV_EXPR:
3245 case NEW_EXPR:
3246 CASE_CONVERT:
3247 case NON_LVALUE_EXPR:
3248 case VIEW_CONVERT_EXPR:
3249 if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
3250 return false;
3251 /* Now compare operands as usual. */
3252 break;
3253
3254 case DEFERRED_NOEXCEPT:
3255 return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
3256 DEFERRED_NOEXCEPT_PATTERN (t2))
3257 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
3258 DEFERRED_NOEXCEPT_ARGS (t2)));
3259 break;
3260
3261 default:
3262 break;
3263 }
3264
3265 switch (TREE_CODE_CLASS (code1))
3266 {
3267 case tcc_unary:
3268 case tcc_binary:
3269 case tcc_comparison:
3270 case tcc_expression:
3271 case tcc_vl_exp:
3272 case tcc_reference:
3273 case tcc_statement:
3274 {
3275 int i, n;
3276
3277 n = cp_tree_operand_length (t1);
3278 if (TREE_CODE_CLASS (code1) == tcc_vl_exp
3279 && n != TREE_OPERAND_LENGTH (t2))
3280 return false;
3281
3282 for (i = 0; i < n; ++i)
3283 if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
3284 return false;
3285
3286 return true;
3287 }
3288
3289 case tcc_type:
3290 return same_type_p (t1, t2);
3291 default:
3292 gcc_unreachable ();
3293 }
3294 /* We can get here with --disable-checking. */
3295 return false;
3296 }
3297
3298 /* The type of ARG when used as an lvalue. */
3299
3300 tree
3301 lvalue_type (tree arg)
3302 {
3303 tree type = TREE_TYPE (arg);
3304 return type;
3305 }
3306
3307 /* The type of ARG for printing error messages; denote lvalues with
3308 reference types. */
3309
3310 tree
3311 error_type (tree arg)
3312 {
3313 tree type = TREE_TYPE (arg);
3314
3315 if (TREE_CODE (type) == ARRAY_TYPE)
3316 ;
3317 else if (TREE_CODE (type) == ERROR_MARK)
3318 ;
3319 else if (real_lvalue_p (arg))
3320 type = build_reference_type (lvalue_type (arg));
3321 else if (MAYBE_CLASS_TYPE_P (type))
3322 type = lvalue_type (arg);
3323
3324 return type;
3325 }
3326
3327 /* Does FUNCTION use a variable-length argument list? */
3328
3329 int
3330 varargs_function_p (const_tree function)
3331 {
3332 return stdarg_p (TREE_TYPE (function));
3333 }
3334
3335 /* Returns 1 if decl is a member of a class. */
3336
3337 int
3338 member_p (const_tree decl)
3339 {
3340 const_tree const ctx = DECL_CONTEXT (decl);
3341 return (ctx && TYPE_P (ctx));
3342 }
3343
3344 /* Create a placeholder for member access where we don't actually have an
3345 object that the access is against. */
3346
3347 tree
3348 build_dummy_object (tree type)
3349 {
3350 tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
3351 return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error);
3352 }
3353
3354 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
3355 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
3356 binfo path from current_class_type to TYPE, or 0. */
3357
3358 tree
3359 maybe_dummy_object (tree type, tree* binfop)
3360 {
3361 tree decl, context;
3362 tree binfo;
3363 tree current = current_nonlambda_class_type ();
3364
3365 if (current
3366 && (binfo = lookup_base (current, type, ba_any, NULL,
3367 tf_warning_or_error)))
3368 context = current;
3369 else
3370 {
3371 /* Reference from a nested class member function. */
3372 context = type;
3373 binfo = TYPE_BINFO (type);
3374 }
3375
3376 if (binfop)
3377 *binfop = binfo;
3378
3379 if (current_class_ref
3380 /* current_class_ref might not correspond to current_class_type if
3381 we're in tsubst_default_argument or a lambda-declarator; in either
3382 case, we want to use current_class_ref if it matches CONTEXT. */
3383 && (same_type_ignoring_top_level_qualifiers_p
3384 (TREE_TYPE (current_class_ref), context)))
3385 decl = current_class_ref;
3386 else
3387 decl = build_dummy_object (context);
3388
3389 return decl;
3390 }
3391
3392 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
3393
3394 int
3395 is_dummy_object (const_tree ob)
3396 {
3397 if (INDIRECT_REF_P (ob))
3398 ob = TREE_OPERAND (ob, 0);
3399 return (TREE_CODE (ob) == CONVERT_EXPR
3400 && TREE_OPERAND (ob, 0) == void_node);
3401 }
3402
3403 /* Returns 1 iff type T is something we want to treat as a scalar type for
3404 the purpose of deciding whether it is trivial/POD/standard-layout. */
3405
3406 bool
3407 scalarish_type_p (const_tree t)
3408 {
3409 if (t == error_mark_node)
3410 return 1;
3411
3412 return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
3413 }
3414
3415 /* Returns true iff T requires non-trivial default initialization. */
3416
3417 bool
3418 type_has_nontrivial_default_init (const_tree t)
3419 {
3420 t = strip_array_types (CONST_CAST_TREE (t));
3421
3422 if (CLASS_TYPE_P (t))
3423 return TYPE_HAS_COMPLEX_DFLT (t);
3424 else
3425 return 0;
3426 }
3427
3428 /* Returns true iff copying an object of type T (including via move
3429 constructor) is non-trivial. That is, T has no non-trivial copy
3430 constructors and no non-trivial move constructors. */
3431
3432 bool
3433 type_has_nontrivial_copy_init (const_tree t)
3434 {
3435 t = strip_array_types (CONST_CAST_TREE (t));
3436
3437 if (CLASS_TYPE_P (t))
3438 {
3439 gcc_assert (COMPLETE_TYPE_P (t));
3440 return ((TYPE_HAS_COPY_CTOR (t)
3441 && TYPE_HAS_COMPLEX_COPY_CTOR (t))
3442 || TYPE_HAS_COMPLEX_MOVE_CTOR (t));
3443 }
3444 else
3445 return 0;
3446 }
3447
3448 /* Returns 1 iff type T is a trivially copyable type, as defined in
3449 [basic.types] and [class]. */
3450
3451 bool
3452 trivially_copyable_p (const_tree t)
3453 {
3454 t = strip_array_types (CONST_CAST_TREE (t));
3455
3456 if (CLASS_TYPE_P (t))
3457 return ((!TYPE_HAS_COPY_CTOR (t)
3458 || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
3459 && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
3460 && (!TYPE_HAS_COPY_ASSIGN (t)
3461 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
3462 && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
3463 && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
3464 else
3465 return !CP_TYPE_VOLATILE_P (t) && scalarish_type_p (t);
3466 }
3467
3468 /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
3469 [class]. */
3470
3471 bool
3472 trivial_type_p (const_tree t)
3473 {
3474 t = strip_array_types (CONST_CAST_TREE (t));
3475
3476 if (CLASS_TYPE_P (t))
3477 return (TYPE_HAS_TRIVIAL_DFLT (t)
3478 && trivially_copyable_p (t));
3479 else
3480 return scalarish_type_p (t);
3481 }
3482
3483 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
3484
3485 bool
3486 pod_type_p (const_tree t)
3487 {
3488 /* This CONST_CAST is okay because strip_array_types returns its
3489 argument unmodified and we assign it to a const_tree. */
3490 t = strip_array_types (CONST_CAST_TREE(t));
3491
3492 if (!CLASS_TYPE_P (t))
3493 return scalarish_type_p (t);
3494 else if (cxx_dialect > cxx98)
3495 /* [class]/10: A POD struct is a class that is both a trivial class and a
3496 standard-layout class, and has no non-static data members of type
3497 non-POD struct, non-POD union (or array of such types).
3498
3499 We don't need to check individual members because if a member is
3500 non-std-layout or non-trivial, the class will be too. */
3501 return (std_layout_type_p (t) && trivial_type_p (t));
3502 else
3503 /* The C++98 definition of POD is different. */
3504 return !CLASSTYPE_NON_LAYOUT_POD_P (t);
3505 }
3506
3507 /* Returns true iff T is POD for the purpose of layout, as defined in the
3508 C++ ABI. */
3509
3510 bool
3511 layout_pod_type_p (const_tree t)
3512 {
3513 t = strip_array_types (CONST_CAST_TREE (t));
3514
3515 if (CLASS_TYPE_P (t))
3516 return !CLASSTYPE_NON_LAYOUT_POD_P (t);
3517 else
3518 return scalarish_type_p (t);
3519 }
3520
3521 /* Returns true iff T is a standard-layout type, as defined in
3522 [basic.types]. */
3523
3524 bool
3525 std_layout_type_p (const_tree t)
3526 {
3527 t = strip_array_types (CONST_CAST_TREE (t));
3528
3529 if (CLASS_TYPE_P (t))
3530 return !CLASSTYPE_NON_STD_LAYOUT (t);
3531 else
3532 return scalarish_type_p (t);
3533 }
3534
3535 /* Nonzero iff type T is a class template implicit specialization. */
3536
3537 bool
3538 class_tmpl_impl_spec_p (const_tree t)
3539 {
3540 return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
3541 }
3542
3543 /* Returns 1 iff zero initialization of type T means actually storing
3544 zeros in it. */
3545
3546 int
3547 zero_init_p (const_tree t)
3548 {
3549 /* This CONST_CAST is okay because strip_array_types returns its
3550 argument unmodified and we assign it to a const_tree. */
3551 t = strip_array_types (CONST_CAST_TREE(t));
3552
3553 if (t == error_mark_node)
3554 return 1;
3555
3556 /* NULL pointers to data members are initialized with -1. */
3557 if (TYPE_PTRDATAMEM_P (t))
3558 return 0;
3559
3560 /* Classes that contain types that can't be zero-initialized, cannot
3561 be zero-initialized themselves. */
3562 if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
3563 return 0;
3564
3565 return 1;
3566 }
3567
3568 /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
3569 warn_unused_result attribute. */
3570
3571 static tree
3572 handle_nodiscard_attribute (tree *node, tree name, tree /*args*/,
3573 int /*flags*/, bool *no_add_attrs)
3574 {
3575 if (TREE_CODE (*node) == FUNCTION_DECL)
3576 {
3577 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
3578 warning (OPT_Wattributes, "%qE attribute applied to %qD with void "
3579 "return type", name, *node);
3580 }
3581 else if (OVERLOAD_TYPE_P (*node))
3582 /* OK */;
3583 else
3584 {
3585 warning (OPT_Wattributes, "%qE attribute can only be applied to "
3586 "functions or to class or enumeration types", name);
3587 *no_add_attrs = true;
3588 }
3589 return NULL_TREE;
3590 }
3591
3592 /* Table of valid C++ attributes. */
3593 const struct attribute_spec cxx_attribute_table[] =
3594 {
3595 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3596 affects_type_identity } */
3597 { "java_interface", 0, 0, false, false, false,
3598 handle_java_interface_attribute, false },
3599 { "init_priority", 1, 1, true, false, false,
3600 handle_init_priority_attribute, false },
3601 { "abi_tag", 1, -1, false, false, false,
3602 handle_abi_tag_attribute, true },
3603 { NULL, 0, 0, false, false, false, NULL, false }
3604 };
3605
3606 /* Table of C++ standard attributes. */
3607 const struct attribute_spec std_attribute_table[] =
3608 {
3609 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3610 affects_type_identity } */
3611 { "maybe_unused", 0, 0, false, false, false,
3612 handle_unused_attribute, false },
3613 { "nodiscard", 0, 0, false, false, false,
3614 handle_nodiscard_attribute, false },
3615 { NULL, 0, 0, false, false, false, NULL, false }
3616 };
3617
3618 /* Handle a "java_interface" attribute; arguments as in
3619 struct attribute_spec.handler. */
3620 static tree
3621 handle_java_interface_attribute (tree* node,
3622 tree name,
3623 tree /*args*/,
3624 int flags,
3625 bool* no_add_attrs)
3626 {
3627 if (DECL_P (*node)
3628 || !CLASS_TYPE_P (*node)
3629 || !TYPE_FOR_JAVA (*node))
3630 {
3631 error ("%qE attribute can only be applied to Java class definitions",
3632 name);
3633 *no_add_attrs = true;
3634 return NULL_TREE;
3635 }
3636 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
3637 *node = build_variant_type_copy (*node);
3638 TYPE_JAVA_INTERFACE (*node) = 1;
3639
3640 return NULL_TREE;
3641 }
3642
3643 /* Handle an "init_priority" attribute; arguments as in
3644 struct attribute_spec.handler. */
3645 static tree
3646 handle_init_priority_attribute (tree* node,
3647 tree name,
3648 tree args,
3649 int /*flags*/,
3650 bool* no_add_attrs)
3651 {
3652 tree initp_expr = TREE_VALUE (args);
3653 tree decl = *node;
3654 tree type = TREE_TYPE (decl);
3655 int pri;
3656
3657 STRIP_NOPS (initp_expr);
3658 initp_expr = default_conversion (initp_expr);
3659 if (initp_expr)
3660 initp_expr = maybe_constant_value (initp_expr);
3661
3662 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
3663 {
3664 error ("requested init_priority is not an integer constant");
3665 cxx_constant_value (initp_expr);
3666 *no_add_attrs = true;
3667 return NULL_TREE;
3668 }
3669
3670 pri = TREE_INT_CST_LOW (initp_expr);
3671
3672 type = strip_array_types (type);
3673
3674 if (decl == NULL_TREE
3675 || !VAR_P (decl)
3676 || !TREE_STATIC (decl)
3677 || DECL_EXTERNAL (decl)
3678 || (TREE_CODE (type) != RECORD_TYPE
3679 && TREE_CODE (type) != UNION_TYPE)
3680 /* Static objects in functions are initialized the
3681 first time control passes through that
3682 function. This is not precise enough to pin down an
3683 init_priority value, so don't allow it. */
3684 || current_function_decl)
3685 {
3686 error ("can only use %qE attribute on file-scope definitions "
3687 "of objects of class type", name);
3688 *no_add_attrs = true;
3689 return NULL_TREE;
3690 }
3691
3692 if (pri > MAX_INIT_PRIORITY || pri <= 0)
3693 {
3694 error ("requested init_priority is out of range");
3695 *no_add_attrs = true;
3696 return NULL_TREE;
3697 }
3698
3699 /* Check for init_priorities that are reserved for
3700 language and runtime support implementations.*/
3701 if (pri <= MAX_RESERVED_INIT_PRIORITY)
3702 {
3703 warning
3704 (0, "requested init_priority is reserved for internal use");
3705 }
3706
3707 if (SUPPORTS_INIT_PRIORITY)
3708 {
3709 SET_DECL_INIT_PRIORITY (decl, pri);
3710 DECL_HAS_INIT_PRIORITY_P (decl) = 1;
3711 return NULL_TREE;
3712 }
3713 else
3714 {
3715 error ("%qE attribute is not supported on this platform", name);
3716 *no_add_attrs = true;
3717 return NULL_TREE;
3718 }
3719 }
3720
3721 /* DECL is being redeclared; the old declaration had the abi tags in OLD,
3722 and the new one has the tags in NEW_. Give an error if there are tags
3723 in NEW_ that weren't in OLD. */
3724
3725 bool
3726 check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
3727 {
3728 if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
3729 old = TREE_VALUE (old);
3730 if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
3731 new_ = TREE_VALUE (new_);
3732 bool err = false;
3733 for (const_tree t = new_; t; t = TREE_CHAIN (t))
3734 {
3735 tree str = TREE_VALUE (t);
3736 for (const_tree in = old; in; in = TREE_CHAIN (in))
3737 {
3738 tree ostr = TREE_VALUE (in);
3739 if (cp_tree_equal (str, ostr))
3740 goto found;
3741 }
3742 error ("redeclaration of %qD adds abi tag %E", decl, str);
3743 err = true;
3744 found:;
3745 }
3746 if (err)
3747 {
3748 inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
3749 return false;
3750 }
3751 return true;
3752 }
3753
3754 /* The abi_tag attribute with the name NAME was given ARGS. If they are
3755 ill-formed, give an error and return false; otherwise, return true. */
3756
3757 bool
3758 check_abi_tag_args (tree args, tree name)
3759 {
3760 if (!args)
3761 {
3762 error ("the %qE attribute requires arguments", name);
3763 return false;
3764 }
3765 for (tree arg = args; arg; arg = TREE_CHAIN (arg))
3766 {
3767 tree elt = TREE_VALUE (arg);
3768 if (TREE_CODE (elt) != STRING_CST
3769 || (!same_type_ignoring_top_level_qualifiers_p
3770 (strip_array_types (TREE_TYPE (elt)),
3771 char_type_node)))
3772 {
3773 error ("arguments to the %qE attribute must be narrow string "
3774 "literals", name);
3775 return false;
3776 }
3777 const char *begin = TREE_STRING_POINTER (elt);
3778 const char *end = begin + TREE_STRING_LENGTH (elt);
3779 for (const char *p = begin; p != end; ++p)
3780 {
3781 char c = *p;
3782 if (p == begin)
3783 {
3784 if (!ISALPHA (c) && c != '_')
3785 {
3786 error ("arguments to the %qE attribute must contain valid "
3787 "identifiers", name);
3788 inform (input_location, "%<%c%> is not a valid first "
3789 "character for an identifier", c);
3790 return false;
3791 }
3792 }
3793 else if (p == end - 1)
3794 gcc_assert (c == 0);
3795 else
3796 {
3797 if (!ISALNUM (c) && c != '_')
3798 {
3799 error ("arguments to the %qE attribute must contain valid "
3800 "identifiers", name);
3801 inform (input_location, "%<%c%> is not a valid character "
3802 "in an identifier", c);
3803 return false;
3804 }
3805 }
3806 }
3807 }
3808 return true;
3809 }
3810
3811 /* Handle an "abi_tag" attribute; arguments as in
3812 struct attribute_spec.handler. */
3813
3814 static tree
3815 handle_abi_tag_attribute (tree* node, tree name, tree args,
3816 int flags, bool* no_add_attrs)
3817 {
3818 if (!check_abi_tag_args (args, name))
3819 goto fail;
3820
3821 if (TYPE_P (*node))
3822 {
3823 if (!OVERLOAD_TYPE_P (*node))
3824 {
3825 error ("%qE attribute applied to non-class, non-enum type %qT",
3826 name, *node);
3827 goto fail;
3828 }
3829 else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
3830 {
3831 error ("%qE attribute applied to %qT after its definition",
3832 name, *node);
3833 goto fail;
3834 }
3835 else if (CLASS_TYPE_P (*node)
3836 && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
3837 {
3838 warning (OPT_Wattributes, "ignoring %qE attribute applied to "
3839 "template instantiation %qT", name, *node);
3840 goto fail;
3841 }
3842 else if (CLASS_TYPE_P (*node)
3843 && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
3844 {
3845 warning (OPT_Wattributes, "ignoring %qE attribute applied to "
3846 "template specialization %qT", name, *node);
3847 goto fail;
3848 }
3849
3850 tree attributes = TYPE_ATTRIBUTES (*node);
3851 tree decl = TYPE_NAME (*node);
3852
3853 /* Make sure all declarations have the same abi tags. */
3854 if (DECL_SOURCE_LOCATION (decl) != input_location)
3855 {
3856 if (!check_abi_tag_redeclaration (decl,
3857 lookup_attribute ("abi_tag",
3858 attributes),
3859 args))
3860 goto fail;
3861 }
3862 }
3863 else
3864 {
3865 if (!VAR_OR_FUNCTION_DECL_P (*node))
3866 {
3867 error ("%qE attribute applied to non-function, non-variable %qD",
3868 name, *node);
3869 goto fail;
3870 }
3871 else if (DECL_LANGUAGE (*node) == lang_c)
3872 {
3873 error ("%qE attribute applied to extern \"C\" declaration %qD",
3874 name, *node);
3875 goto fail;
3876 }
3877 }
3878
3879 return NULL_TREE;
3880
3881 fail:
3882 *no_add_attrs = true;
3883 return NULL_TREE;
3884 }
3885
3886 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
3887 thing pointed to by the constant. */
3888
3889 tree
3890 make_ptrmem_cst (tree type, tree member)
3891 {
3892 tree ptrmem_cst = make_node (PTRMEM_CST);
3893 TREE_TYPE (ptrmem_cst) = type;
3894 PTRMEM_CST_MEMBER (ptrmem_cst) = member;
3895 return ptrmem_cst;
3896 }
3897
3898 /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
3899 return an existing type if an appropriate type already exists. */
3900
3901 tree
3902 cp_build_type_attribute_variant (tree type, tree attributes)
3903 {
3904 tree new_type;
3905
3906 new_type = build_type_attribute_variant (type, attributes);
3907 if (TREE_CODE (new_type) == FUNCTION_TYPE
3908 || TREE_CODE (new_type) == METHOD_TYPE)
3909 {
3910 new_type = build_exception_variant (new_type,
3911 TYPE_RAISES_EXCEPTIONS (type));
3912 new_type = build_ref_qualified_type (new_type,
3913 type_memfn_rqual (type));
3914 }
3915
3916 /* Making a new main variant of a class type is broken. */
3917 gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
3918
3919 return new_type;
3920 }
3921
3922 /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
3923 Called only after doing all language independent checks. Only
3924 to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already
3925 compared in type_hash_eq. */
3926
3927 bool
3928 cxx_type_hash_eq (const_tree typea, const_tree typeb)
3929 {
3930 gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE
3931 || TREE_CODE (typea) == METHOD_TYPE);
3932
3933 return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
3934 TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
3935 }
3936
3937 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
3938 traversal. Called from walk_tree. */
3939
3940 tree
3941 cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
3942 void *data, hash_set<tree> *pset)
3943 {
3944 enum tree_code code = TREE_CODE (*tp);
3945 tree result;
3946
3947 #define WALK_SUBTREE(NODE) \
3948 do \
3949 { \
3950 result = cp_walk_tree (&(NODE), func, data, pset); \
3951 if (result) goto out; \
3952 } \
3953 while (0)
3954
3955 /* Not one of the easy cases. We must explicitly go through the
3956 children. */
3957 result = NULL_TREE;
3958 switch (code)
3959 {
3960 case DEFAULT_ARG:
3961 case TEMPLATE_TEMPLATE_PARM:
3962 case BOUND_TEMPLATE_TEMPLATE_PARM:
3963 case UNBOUND_CLASS_TEMPLATE:
3964 case TEMPLATE_PARM_INDEX:
3965 case TEMPLATE_TYPE_PARM:
3966 case TYPENAME_TYPE:
3967 case TYPEOF_TYPE:
3968 case UNDERLYING_TYPE:
3969 /* None of these have subtrees other than those already walked
3970 above. */
3971 *walk_subtrees_p = 0;
3972 break;
3973
3974 case BASELINK:
3975 WALK_SUBTREE (BASELINK_FUNCTIONS (*tp));
3976 *walk_subtrees_p = 0;
3977 break;
3978
3979 case PTRMEM_CST:
3980 WALK_SUBTREE (TREE_TYPE (*tp));
3981 *walk_subtrees_p = 0;
3982 break;
3983
3984 case TREE_LIST:
3985 WALK_SUBTREE (TREE_PURPOSE (*tp));
3986 break;
3987
3988 case OVERLOAD:
3989 WALK_SUBTREE (OVL_FUNCTION (*tp));
3990 WALK_SUBTREE (OVL_CHAIN (*tp));
3991 *walk_subtrees_p = 0;
3992 break;
3993
3994 case USING_DECL:
3995 WALK_SUBTREE (DECL_NAME (*tp));
3996 WALK_SUBTREE (USING_DECL_SCOPE (*tp));
3997 WALK_SUBTREE (USING_DECL_DECLS (*tp));
3998 *walk_subtrees_p = 0;
3999 break;
4000
4001 case RECORD_TYPE:
4002 if (TYPE_PTRMEMFUNC_P (*tp))
4003 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (*tp));
4004 break;
4005
4006 case TYPE_ARGUMENT_PACK:
4007 case NONTYPE_ARGUMENT_PACK:
4008 {
4009 tree args = ARGUMENT_PACK_ARGS (*tp);
4010 int i, len = TREE_VEC_LENGTH (args);
4011 for (i = 0; i < len; i++)
4012 WALK_SUBTREE (TREE_VEC_ELT (args, i));
4013 }
4014 break;
4015
4016 case TYPE_PACK_EXPANSION:
4017 WALK_SUBTREE (TREE_TYPE (*tp));
4018 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp));
4019 *walk_subtrees_p = 0;
4020 break;
4021
4022 case EXPR_PACK_EXPANSION:
4023 WALK_SUBTREE (TREE_OPERAND (*tp, 0));
4024 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp));
4025 *walk_subtrees_p = 0;
4026 break;
4027
4028 case CAST_EXPR:
4029 case REINTERPRET_CAST_EXPR:
4030 case STATIC_CAST_EXPR:
4031 case CONST_CAST_EXPR:
4032 case DYNAMIC_CAST_EXPR:
4033 case IMPLICIT_CONV_EXPR:
4034 if (TREE_TYPE (*tp))
4035 WALK_SUBTREE (TREE_TYPE (*tp));
4036
4037 {
4038 int i;
4039 for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i)
4040 WALK_SUBTREE (TREE_OPERAND (*tp, i));
4041 }
4042 *walk_subtrees_p = 0;
4043 break;
4044
4045 case TRAIT_EXPR:
4046 WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp));
4047 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp));
4048 *walk_subtrees_p = 0;
4049 break;
4050
4051 case DECLTYPE_TYPE:
4052 WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp));
4053 *walk_subtrees_p = 0;
4054 break;
4055
4056 case REQUIRES_EXPR:
4057 // Only recurse through the nested expression. Do not
4058 // walk the parameter list. Doing so causes false
4059 // positives in the pack expansion checker since the
4060 // requires parameters are introduced as pack expansions.
4061 WALK_SUBTREE (TREE_OPERAND (*tp, 1));
4062 *walk_subtrees_p = 0;
4063 break;
4064
4065 default:
4066 return NULL_TREE;
4067 }
4068
4069 /* We didn't find what we were looking for. */
4070 out:
4071 return result;
4072
4073 #undef WALK_SUBTREE
4074 }
4075
4076 /* Like save_expr, but for C++. */
4077
4078 tree
4079 cp_save_expr (tree expr)
4080 {
4081 /* There is no reason to create a SAVE_EXPR within a template; if
4082 needed, we can create the SAVE_EXPR when instantiating the
4083 template. Furthermore, the middle-end cannot handle C++-specific
4084 tree codes. */
4085 if (processing_template_decl)
4086 return expr;
4087 return save_expr (expr);
4088 }
4089
4090 /* Initialize tree.c. */
4091
4092 void
4093 init_tree (void)
4094 {
4095 list_hash_table = hash_table<list_hasher>::create_ggc (61);
4096 register_scoped_attributes (std_attribute_table, NULL);
4097 }
4098
4099 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
4100 is. Note that sfk_none is zero, so this function can be used as a
4101 predicate to test whether or not DECL is a special function. */
4102
4103 special_function_kind
4104 special_function_p (const_tree decl)
4105 {
4106 /* Rather than doing all this stuff with magic names, we should
4107 probably have a field of type `special_function_kind' in
4108 DECL_LANG_SPECIFIC. */
4109 if (DECL_INHERITED_CTOR_BASE (decl))
4110 return sfk_inheriting_constructor;
4111 if (DECL_COPY_CONSTRUCTOR_P (decl))
4112 return sfk_copy_constructor;
4113 if (DECL_MOVE_CONSTRUCTOR_P (decl))
4114 return sfk_move_constructor;
4115 if (DECL_CONSTRUCTOR_P (decl))
4116 return sfk_constructor;
4117 if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
4118 {
4119 if (copy_fn_p (decl))
4120 return sfk_copy_assignment;
4121 if (move_fn_p (decl))
4122 return sfk_move_assignment;
4123 }
4124 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
4125 return sfk_destructor;
4126 if (DECL_COMPLETE_DESTRUCTOR_P (decl))
4127 return sfk_complete_destructor;
4128 if (DECL_BASE_DESTRUCTOR_P (decl))
4129 return sfk_base_destructor;
4130 if (DECL_DELETING_DESTRUCTOR_P (decl))
4131 return sfk_deleting_destructor;
4132 if (DECL_CONV_FN_P (decl))
4133 return sfk_conversion;
4134
4135 return sfk_none;
4136 }
4137
4138 /* Returns nonzero if TYPE is a character type, including wchar_t. */
4139
4140 int
4141 char_type_p (tree type)
4142 {
4143 return (same_type_p (type, char_type_node)
4144 || same_type_p (type, unsigned_char_type_node)
4145 || same_type_p (type, signed_char_type_node)
4146 || same_type_p (type, char16_type_node)
4147 || same_type_p (type, char32_type_node)
4148 || same_type_p (type, wchar_type_node));
4149 }
4150
4151 /* Returns the kind of linkage associated with the indicated DECL. Th
4152 value returned is as specified by the language standard; it is
4153 independent of implementation details regarding template
4154 instantiation, etc. For example, it is possible that a declaration
4155 to which this function assigns external linkage would not show up
4156 as a global symbol when you run `nm' on the resulting object file. */
4157
4158 linkage_kind
4159 decl_linkage (tree decl)
4160 {
4161 /* This function doesn't attempt to calculate the linkage from first
4162 principles as given in [basic.link]. Instead, it makes use of
4163 the fact that we have already set TREE_PUBLIC appropriately, and
4164 then handles a few special cases. Ideally, we would calculate
4165 linkage first, and then transform that into a concrete
4166 implementation. */
4167
4168 /* Things that don't have names have no linkage. */
4169 if (!DECL_NAME (decl))
4170 return lk_none;
4171
4172 /* Fields have no linkage. */
4173 if (TREE_CODE (decl) == FIELD_DECL)
4174 return lk_none;
4175
4176 /* Things that are TREE_PUBLIC have external linkage. */
4177 if (TREE_PUBLIC (decl))
4178 return lk_external;
4179
4180 if (TREE_CODE (decl) == NAMESPACE_DECL)
4181 return lk_external;
4182
4183 /* Linkage of a CONST_DECL depends on the linkage of the enumeration
4184 type. */
4185 if (TREE_CODE (decl) == CONST_DECL)
4186 return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl)));
4187
4188 /* Things in local scope do not have linkage, if they don't have
4189 TREE_PUBLIC set. */
4190 if (decl_function_context (decl))
4191 return lk_none;
4192
4193 /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
4194 are considered to have external linkage for language purposes, as do
4195 template instantiations on targets without weak symbols. DECLs really
4196 meant to have internal linkage have DECL_THIS_STATIC set. */
4197 if (TREE_CODE (decl) == TYPE_DECL)
4198 return lk_external;
4199 if (VAR_OR_FUNCTION_DECL_P (decl))
4200 {
4201 if (!DECL_THIS_STATIC (decl))
4202 return lk_external;
4203
4204 /* Static data members and static member functions from classes
4205 in anonymous namespace also don't have TREE_PUBLIC set. */
4206 if (DECL_CLASS_CONTEXT (decl))
4207 return lk_external;
4208 }
4209
4210 /* Everything else has internal linkage. */
4211 return lk_internal;
4212 }
4213
4214 /* Returns the storage duration of the object or reference associated with
4215 the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
4216
4217 duration_kind
4218 decl_storage_duration (tree decl)
4219 {
4220 if (TREE_CODE (decl) == PARM_DECL)
4221 return dk_auto;
4222 if (TREE_CODE (decl) == FUNCTION_DECL)
4223 return dk_static;
4224 gcc_assert (VAR_P (decl));
4225 if (!TREE_STATIC (decl)
4226 && !DECL_EXTERNAL (decl))
4227 return dk_auto;
4228 if (CP_DECL_THREAD_LOCAL_P (decl))
4229 return dk_thread;
4230 return dk_static;
4231 }
4232 \f
4233 /* EXP is an expression that we want to pre-evaluate. Returns (in
4234 *INITP) an expression that will perform the pre-evaluation. The
4235 value returned by this function is a side-effect free expression
4236 equivalent to the pre-evaluated expression. Callers must ensure
4237 that *INITP is evaluated before EXP. */
4238
4239 tree
4240 stabilize_expr (tree exp, tree* initp)
4241 {
4242 tree init_expr;
4243
4244 if (!TREE_SIDE_EFFECTS (exp))
4245 init_expr = NULL_TREE;
4246 else if (VOID_TYPE_P (TREE_TYPE (exp)))
4247 {
4248 init_expr = exp;
4249 exp = void_node;
4250 }
4251 /* There are no expressions with REFERENCE_TYPE, but there can be call
4252 arguments with such a type; just treat it as a pointer. */
4253 else if (TREE_CODE (TREE_TYPE (exp)) == REFERENCE_TYPE
4254 || SCALAR_TYPE_P (TREE_TYPE (exp))
4255 || !lvalue_or_rvalue_with_address_p (exp))
4256 {
4257 init_expr = get_target_expr (exp);
4258 exp = TARGET_EXPR_SLOT (init_expr);
4259 if (CLASS_TYPE_P (TREE_TYPE (exp)))
4260 exp = move (exp);
4261 else
4262 exp = rvalue (exp);
4263 }
4264 else
4265 {
4266 bool xval = !real_lvalue_p (exp);
4267 exp = cp_build_addr_expr (exp, tf_warning_or_error);
4268 init_expr = get_target_expr (exp);
4269 exp = TARGET_EXPR_SLOT (init_expr);
4270 exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error);
4271 if (xval)
4272 exp = move (exp);
4273 }
4274 *initp = init_expr;
4275
4276 gcc_assert (!TREE_SIDE_EFFECTS (exp));
4277 return exp;
4278 }
4279
4280 /* Add NEW_EXPR, an expression whose value we don't care about, after the
4281 similar expression ORIG. */
4282
4283 tree
4284 add_stmt_to_compound (tree orig, tree new_expr)
4285 {
4286 if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
4287 return orig;
4288 if (!orig || !TREE_SIDE_EFFECTS (orig))
4289 return new_expr;
4290 return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
4291 }
4292
4293 /* Like stabilize_expr, but for a call whose arguments we want to
4294 pre-evaluate. CALL is modified in place to use the pre-evaluated
4295 arguments, while, upon return, *INITP contains an expression to
4296 compute the arguments. */
4297
4298 void
4299 stabilize_call (tree call, tree *initp)
4300 {
4301 tree inits = NULL_TREE;
4302 int i;
4303 int nargs = call_expr_nargs (call);
4304
4305 if (call == error_mark_node || processing_template_decl)
4306 {
4307 *initp = NULL_TREE;
4308 return;
4309 }
4310
4311 gcc_assert (TREE_CODE (call) == CALL_EXPR);
4312
4313 for (i = 0; i < nargs; i++)
4314 {
4315 tree init;
4316 CALL_EXPR_ARG (call, i) =
4317 stabilize_expr (CALL_EXPR_ARG (call, i), &init);
4318 inits = add_stmt_to_compound (inits, init);
4319 }
4320
4321 *initp = inits;
4322 }
4323
4324 /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
4325 to pre-evaluate. CALL is modified in place to use the pre-evaluated
4326 arguments, while, upon return, *INITP contains an expression to
4327 compute the arguments. */
4328
4329 static void
4330 stabilize_aggr_init (tree call, tree *initp)
4331 {
4332 tree inits = NULL_TREE;
4333 int i;
4334 int nargs = aggr_init_expr_nargs (call);
4335
4336 if (call == error_mark_node)
4337 return;
4338
4339 gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
4340
4341 for (i = 0; i < nargs; i++)
4342 {
4343 tree init;
4344 AGGR_INIT_EXPR_ARG (call, i) =
4345 stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
4346 inits = add_stmt_to_compound (inits, init);
4347 }
4348
4349 *initp = inits;
4350 }
4351
4352 /* Like stabilize_expr, but for an initialization.
4353
4354 If the initialization is for an object of class type, this function
4355 takes care not to introduce additional temporaries.
4356
4357 Returns TRUE iff the expression was successfully pre-evaluated,
4358 i.e., if INIT is now side-effect free, except for, possibly, a
4359 single call to a constructor. */
4360
4361 bool
4362 stabilize_init (tree init, tree *initp)
4363 {
4364 tree t = init;
4365
4366 *initp = NULL_TREE;
4367
4368 if (t == error_mark_node || processing_template_decl)
4369 return true;
4370
4371 if (TREE_CODE (t) == INIT_EXPR)
4372 t = TREE_OPERAND (t, 1);
4373 if (TREE_CODE (t) == TARGET_EXPR)
4374 t = TARGET_EXPR_INITIAL (t);
4375
4376 /* If the RHS can be stabilized without breaking copy elision, stabilize
4377 it. We specifically don't stabilize class prvalues here because that
4378 would mean an extra copy, but they might be stabilized below. */
4379 if (TREE_CODE (init) == INIT_EXPR
4380 && TREE_CODE (t) != CONSTRUCTOR
4381 && TREE_CODE (t) != AGGR_INIT_EXPR
4382 && (SCALAR_TYPE_P (TREE_TYPE (t))
4383 || lvalue_or_rvalue_with_address_p (t)))
4384 {
4385 TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
4386 return true;
4387 }
4388
4389 if (TREE_CODE (t) == COMPOUND_EXPR
4390 && TREE_CODE (init) == INIT_EXPR)
4391 {
4392 tree last = expr_last (t);
4393 /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
4394 if (!TREE_SIDE_EFFECTS (last))
4395 {
4396 *initp = t;
4397 TREE_OPERAND (init, 1) = last;
4398 return true;
4399 }
4400 }
4401
4402 if (TREE_CODE (t) == CONSTRUCTOR)
4403 {
4404 /* Aggregate initialization: stabilize each of the field
4405 initializers. */
4406 unsigned i;
4407 constructor_elt *ce;
4408 bool good = true;
4409 vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
4410 for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
4411 {
4412 tree type = TREE_TYPE (ce->value);
4413 tree subinit;
4414 if (TREE_CODE (type) == REFERENCE_TYPE
4415 || SCALAR_TYPE_P (type))
4416 ce->value = stabilize_expr (ce->value, &subinit);
4417 else if (!stabilize_init (ce->value, &subinit))
4418 good = false;
4419 *initp = add_stmt_to_compound (*initp, subinit);
4420 }
4421 return good;
4422 }
4423
4424 if (TREE_CODE (t) == CALL_EXPR)
4425 {
4426 stabilize_call (t, initp);
4427 return true;
4428 }
4429
4430 if (TREE_CODE (t) == AGGR_INIT_EXPR)
4431 {
4432 stabilize_aggr_init (t, initp);
4433 return true;
4434 }
4435
4436 /* The initialization is being performed via a bitwise copy -- and
4437 the item copied may have side effects. */
4438 return !TREE_SIDE_EFFECTS (init);
4439 }
4440
4441 /* Returns true if a cast to TYPE may appear in an integral constant
4442 expression. */
4443
4444 bool
4445 cast_valid_in_integral_constant_expression_p (tree type)
4446 {
4447 return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
4448 || cxx_dialect >= cxx11
4449 || dependent_type_p (type)
4450 || type == error_mark_node);
4451 }
4452
4453 /* Return true if we need to fix linkage information of DECL. */
4454
4455 static bool
4456 cp_fix_function_decl_p (tree decl)
4457 {
4458 /* Skip if DECL is not externally visible. */
4459 if (!TREE_PUBLIC (decl))
4460 return false;
4461
4462 /* We need to fix DECL if it a appears to be exported but with no
4463 function body. Thunks do not have CFGs and we may need to
4464 handle them specially later. */
4465 if (!gimple_has_body_p (decl)
4466 && !DECL_THUNK_P (decl)
4467 && !DECL_EXTERNAL (decl))
4468 {
4469 struct cgraph_node *node = cgraph_node::get (decl);
4470
4471 /* Don't fix same_body aliases. Although they don't have their own
4472 CFG, they share it with what they alias to. */
4473 if (!node || !node->alias
4474 || !vec_safe_length (node->ref_list.references))
4475 return true;
4476 }
4477
4478 return false;
4479 }
4480
4481 /* Clean the C++ specific parts of the tree T. */
4482
4483 void
4484 cp_free_lang_data (tree t)
4485 {
4486 if (TREE_CODE (t) == METHOD_TYPE
4487 || TREE_CODE (t) == FUNCTION_TYPE)
4488 {
4489 /* Default args are not interesting anymore. */
4490 tree argtypes = TYPE_ARG_TYPES (t);
4491 while (argtypes)
4492 {
4493 TREE_PURPOSE (argtypes) = 0;
4494 argtypes = TREE_CHAIN (argtypes);
4495 }
4496 }
4497 else if (TREE_CODE (t) == FUNCTION_DECL
4498 && cp_fix_function_decl_p (t))
4499 {
4500 /* If T is used in this translation unit at all, the definition
4501 must exist somewhere else since we have decided to not emit it
4502 in this TU. So make it an external reference. */
4503 DECL_EXTERNAL (t) = 1;
4504 TREE_STATIC (t) = 0;
4505 }
4506 if (TREE_CODE (t) == NAMESPACE_DECL)
4507 {
4508 /* The list of users of a namespace isn't useful for the middle-end
4509 or debug generators. */
4510 DECL_NAMESPACE_USERS (t) = NULL_TREE;
4511 /* Neither do we need the leftover chaining of namespaces
4512 from the binding level. */
4513 DECL_CHAIN (t) = NULL_TREE;
4514 }
4515 }
4516
4517 /* Stub for c-common. Please keep in sync with c-decl.c.
4518 FIXME: If address space support is target specific, then this
4519 should be a C target hook. But currently this is not possible,
4520 because this function is called via REGISTER_TARGET_PRAGMAS. */
4521 void
4522 c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
4523 {
4524 }
4525
4526 /* Return the number of operands in T that we care about for things like
4527 mangling. */
4528
4529 int
4530 cp_tree_operand_length (const_tree t)
4531 {
4532 enum tree_code code = TREE_CODE (t);
4533
4534 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
4535 return VL_EXP_OPERAND_LENGTH (t);
4536
4537 return cp_tree_code_length (code);
4538 }
4539
4540 /* Like cp_tree_operand_length, but takes a tree_code CODE. */
4541
4542 int
4543 cp_tree_code_length (enum tree_code code)
4544 {
4545 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
4546
4547 switch (code)
4548 {
4549 case PREINCREMENT_EXPR:
4550 case PREDECREMENT_EXPR:
4551 case POSTINCREMENT_EXPR:
4552 case POSTDECREMENT_EXPR:
4553 return 1;
4554
4555 case ARRAY_REF:
4556 return 2;
4557
4558 case EXPR_PACK_EXPANSION:
4559 return 1;
4560
4561 default:
4562 return TREE_CODE_LENGTH (code);
4563 }
4564 }
4565
4566 /* Implement -Wzero_as_null_pointer_constant. Return true if the
4567 conditions for the warning hold, false otherwise. */
4568 bool
4569 maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
4570 {
4571 if (c_inhibit_evaluation_warnings == 0
4572 && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
4573 {
4574 warning_at (loc, OPT_Wzero_as_null_pointer_constant,
4575 "zero as null pointer constant");
4576 return true;
4577 }
4578 return false;
4579 }
4580 \f
4581 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4582 /* Complain that some language-specific thing hanging off a tree
4583 node has been accessed improperly. */
4584
4585 void
4586 lang_check_failed (const char* file, int line, const char* function)
4587 {
4588 internal_error ("lang_* check: failed in %s, at %s:%d",
4589 function, trim_filename (file), line);
4590 }
4591 #endif /* ENABLE_TREE_CHECKING */
4592
4593 #include "gt-cp-tree.h"