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