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