OSDN Git Service

PR c++/45588
[pf3gnuchains/gcc-fork.git] / gcc / cp / pt.c
index 9eeba8a..5c32484 100644 (file)
@@ -34,13 +34,12 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "pointer-set.h"
 #include "flags.h"
-#include "c-common.h"
 #include "cp-tree.h"
+#include "c-family/c-common.h"
 #include "cp-objcp-common.h"
 #include "tree-inline.h"
 #include "decl.h"
 #include "output.h"
-#include "except.h"
 #include "toplev.h"
 #include "timevar.h"
 #include "tree-iterator.h"
@@ -132,7 +131,7 @@ static int type_unification_real (tree, tree, tree, const tree *,
                                  unsigned int, int, unification_kind_t, int);
 static void note_template_header (int);
 static tree convert_nontype_argument_function (tree, tree);
-static tree convert_nontype_argument (tree, tree);
+static tree convert_nontype_argument (tree, tree, tsubst_flags_t);
 static tree convert_template_argument (tree, tree, tree,
                                       tsubst_flags_t, int, tree);
 static int for_each_template_parm (tree, tree_fn_t, void*,
@@ -159,7 +158,7 @@ static tree tsubst_template_arg (tree, tree, tsubst_flags_t, tree);
 static tree tsubst_template_args (tree, tree, tsubst_flags_t, tree);
 static tree tsubst_template_parms (tree, tree, tsubst_flags_t);
 static void regenerate_decl_from_template (tree, tree);
-static tree most_specialized_class (tree, tree);
+static tree most_specialized_class (tree, tree, tsubst_flags_t);
 static tree tsubst_aggr_type (tree, tree, tsubst_flags_t, tree, int);
 static tree tsubst_arg_types (tree, tree, tsubst_flags_t, tree);
 static tree tsubst_function_type (tree, tree, tsubst_flags_t, tree);
@@ -888,10 +887,10 @@ maybe_process_partial_specialization (tree type)
 
                  slot = (spec_entry **)
                    htab_find_slot (type_specializations, &elt, INSERT);
-                 *slot = GGC_NEW (spec_entry);
+                 *slot = ggc_alloc_spec_entry ();
                  **slot = elt;
                }
-             else if (COMPLETE_TYPE_P (inst) || TYPE_BEING_DEFINED (inst))
+             else if (COMPLETE_OR_OPEN_TYPE_P (inst))
                /* But if we've had an implicit instantiation, that's a
                   problem ([temp.expl.spec]/6).  */
                error ("specialization %qT after instantiation %qT",
@@ -1401,7 +1400,7 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend,
   if (!optimize_specialization_lookup_p (tmpl))
     {
       gcc_assert (tmpl && args && spec);
-      *slot = GGC_NEW (spec_entry);
+      *slot = ggc_alloc_spec_entry ();
       **slot = elt;
       if (TREE_CODE (spec) == FUNCTION_DECL && DECL_NAMESPACE_SCOPE_P (spec)
          && PRIMARY_TEMPLATE_P (tmpl)
@@ -1567,31 +1566,43 @@ iterative_hash_template_arg (tree arg, hashval_t val)
       gcc_assert (seen_error ());
       return val;
 
+    case CAST_EXPR:
+    case STATIC_CAST_EXPR:
+    case REINTERPRET_CAST_EXPR:
+    case CONST_CAST_EXPR:
+    case DYNAMIC_CAST_EXPR:
+    case NEW_EXPR:
+      val = iterative_hash_template_arg (TREE_TYPE (arg), val);
+      /* Now hash operands as usual.  */
+      break;
+
     default:
-      switch (tclass)
-       {
-       case tcc_type:
-         if (TYPE_CANONICAL (arg))
-           return iterative_hash_object (TYPE_HASH (TYPE_CANONICAL (arg)),
-                                         val);
-         else if (TREE_CODE (arg) == DECLTYPE_TYPE)
-           return iterative_hash_template_arg (DECLTYPE_TYPE_EXPR (arg), val);
-         /* Otherwise just compare the types during lookup.  */
-         return val;
+      break;
+    }
+
+  switch (tclass)
+    {
+    case tcc_type:
+      if (TYPE_CANONICAL (arg))
+       return iterative_hash_object (TYPE_HASH (TYPE_CANONICAL (arg)),
+                                     val);
+      else if (TREE_CODE (arg) == DECLTYPE_TYPE)
+       return iterative_hash_template_arg (DECLTYPE_TYPE_EXPR (arg), val);
+      /* Otherwise just compare the types during lookup.  */
+      return val;
 
-       case tcc_declaration:
-       case tcc_constant:
-         return iterative_hash_expr (arg, val);
+    case tcc_declaration:
+    case tcc_constant:
+      return iterative_hash_expr (arg, val);
 
-       default:
-         gcc_assert (IS_EXPR_CODE_CLASS (tclass));
-         {
-           unsigned n = TREE_OPERAND_LENGTH (arg);
-           for (i = 0; i < n; ++i)
-             val = iterative_hash_template_arg (TREE_OPERAND (arg, i), val);
-           return val;
-         }
-       }
+    default:
+      gcc_assert (IS_EXPR_CODE_CLASS (tclass));
+      {
+       unsigned n = TREE_OPERAND_LENGTH (arg);
+       for (i = 0; i < n; ++i)
+         val = iterative_hash_template_arg (TREE_OPERAND (arg, i), val);
+       return val;
+      }
     }
   gcc_unreachable ();
   return 0;
@@ -2554,7 +2565,7 @@ check_explicit_specialization (tree declarator,
                     definition, not in the original declaration.  */
                  DECL_ARGUMENTS (result) = DECL_ARGUMENTS (decl);
                  for (parm = DECL_ARGUMENTS (result); parm;
-                      parm = TREE_CHAIN (parm))
+                      parm = DECL_CHAIN (parm))
                    DECL_CONTEXT (parm) = result;
                }
              return register_specialization (tmpl, gen_tmpl, targs,
@@ -3832,6 +3843,7 @@ process_partial_specialization (tree decl)
   tree inner_args = INNERMOST_TEMPLATE_ARGS (specargs);
   tree main_inner_parms = DECL_INNERMOST_TEMPLATE_PARMS (maintmpl);
   tree inner_parms;
+  tree inst;
   int nargs = TREE_VEC_LENGTH (inner_args);
   int ntparms;
   int  i;
@@ -3875,10 +3887,10 @@ process_partial_specialization (tree decl)
 
      or some such would have been OK.  */
   tpd.level = TMPL_PARMS_DEPTH (current_template_parms);
-  tpd.parms = (int *) alloca (sizeof (int) * ntparms);
+  tpd.parms = XALLOCAVEC (int, ntparms);
   memset (tpd.parms, 0, sizeof (int) * ntparms);
 
-  tpd.arg_uses_template_parms = (int *) alloca (sizeof (int) * nargs);
+  tpd.arg_uses_template_parms = XALLOCAVEC (int, nargs);
   memset (tpd.arg_uses_template_parms, 0, sizeof (int) * nargs);
   for (i = 0; i < nargs; ++i)
     {
@@ -3993,12 +4005,11 @@ process_partial_specialization (tree decl)
                   if (!tpd2.parms)
                     {
                       /* We haven't yet initialized TPD2.  Do so now.  */
-                      tpd2.arg_uses_template_parms 
-                        = (int *) alloca (sizeof (int) * nargs);
+                      tpd2.arg_uses_template_parms = XALLOCAVEC (int, nargs);
                       /* The number of parameters here is the number in the
                          main template, which, as checked in the assertion
                          above, is NARGS.  */
-                      tpd2.parms = (int *) alloca (sizeof (int) * nargs);
+                      tpd2.parms = XALLOCAVEC (int, nargs);
                       tpd2.level = 
                         TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (maintmpl));
                     }
@@ -4047,6 +4058,22 @@ process_partial_specialization (tree decl)
     = tree_cons (specargs, inner_parms,
                  DECL_TEMPLATE_SPECIALIZATIONS (maintmpl));
   TREE_TYPE (DECL_TEMPLATE_SPECIALIZATIONS (maintmpl)) = type;
+
+  for (inst = DECL_TEMPLATE_INSTANTIATIONS (maintmpl); inst;
+       inst = TREE_CHAIN (inst))
+    {
+      tree inst_type = TREE_VALUE (inst);
+      if (COMPLETE_TYPE_P (inst_type)
+         && CLASSTYPE_IMPLICIT_INSTANTIATION (inst_type))
+       {
+         tree spec = most_specialized_class (inst_type, maintmpl, tf_none);
+         if (spec && TREE_TYPE (spec) == type)
+           permerror (input_location,
+                      "partial specialization of %qT after instantiation "
+                      "of %qT", type, inst_type);
+       }
+    }
+
   return decl;
 }
 
@@ -4419,7 +4446,7 @@ push_template_decl_real (tree decl, bool is_friend)
               TREE_VALUE (argtype) = error_mark_node;
             }
 
-          arg = TREE_CHAIN (arg);
+          arg = DECL_CHAIN (arg);
           argtype = TREE_CHAIN (argtype);
         }
 
@@ -4773,8 +4800,8 @@ redeclare_class_template (tree type, tree parms)
 /* Simplify EXPR if it is a non-dependent expression.  Returns the
    (possibly simplified) expression.  */
 
-tree
-fold_non_dependent_expr (tree expr)
+static tree
+fold_non_dependent_expr_sfinae (tree expr, tsubst_flags_t complain)
 {
   if (expr == NULL_TREE)
     return NULL_TREE;
@@ -4796,7 +4823,7 @@ fold_non_dependent_expr (tree expr)
       processing_template_decl = 0;
       expr = tsubst_copy_and_build (expr,
                                    /*args=*/NULL_TREE,
-                                   tf_error,
+                                   complain,
                                    /*in_decl=*/NULL_TREE,
                                    /*function_p=*/false,
                                    /*integral_constant_expression_p=*/true);
@@ -4805,6 +4832,12 @@ fold_non_dependent_expr (tree expr)
   return expr;
 }
 
+tree
+fold_non_dependent_expr (tree expr)
+{
+  return fold_non_dependent_expr_sfinae (expr, tf_error);
+}
+
 /* EXPR is an expression which is used in a constant-expression context.
    For instance, it could be a VAR_DECL with a constant initializer.
    Extract the innermost constant expression.
@@ -4882,6 +4915,36 @@ check_valid_ptrmem_cst_expr (tree type, tree expr)
   return false;
 }
 
+/* Returns TRUE iff the address of OP is value-dependent.
+
+   14.6.2.4 [temp.dep.temp]:
+   A non-integral non-type template-argument is dependent if its type is
+   dependent or it has either of the following forms
+     qualified-id
+     & qualified-id
+   and contains a nested-name-specifier which specifies a class-name that
+   names a dependent type.
+
+   We generalize this to just say that the address of a member of a
+   dependent class is value-dependent; the above doesn't cover the
+   address of a static data member named with an unqualified-id.  */
+
+static bool
+has_value_dependent_address (tree op)
+{
+  /* We could use get_inner_reference here, but there's no need;
+     this is only relevant for template non-type arguments, which
+     can only be expressed as &id-expression.  */
+  if (DECL_P (op))
+    {
+      tree ctx = CP_DECL_CONTEXT (op);
+      if (TYPE_P (ctx) && dependent_type_p (ctx))
+       return true;
+    }
+
+  return false;
+}
+
 /* Attempt to convert the non-type template parameter EXPR to the
    indicated TYPE.  If the conversion is successful, return the
    converted value.  If the conversion is unsuccessful, return
@@ -4903,7 +4966,7 @@ check_valid_ptrmem_cst_expr (tree type, tree expr)
    hacks can go away after we fix the double coercion problem.  */
 
 static tree
-convert_nontype_argument (tree type, tree expr)
+convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 {
   tree expr_type;
 
@@ -4912,14 +4975,21 @@ convert_nontype_argument (tree type, tree expr)
      catch this later), but only to provide better diagnostic for this
      common user mistake. As suggested by DR 100, we do not mention
      linkage issues in the diagnostic as this is not the point.  */
+  /* FIXME we're making this OK.  */
   if (TREE_CODE (expr) == STRING_CST)
     {
-      error ("%qE is not a valid template argument for type %qT "
-            "because string literals can never be used in this context",
-            expr, type);
+      if (complain & tf_error)
+       error ("%qE is not a valid template argument for type %qT "
+              "because string literals can never be used in this context",
+              expr, type);
       return NULL_TREE;
     }
 
+  /* Add the ADDR_EXPR now for the benefit of
+     value_dependent_expression_p.  */
+  if (TYPE_PTROBV_P (type))
+    expr = decay_conversion (expr);
+
   /* If we are in a template, EXPR may be non-dependent, but still
      have a syntactic, rather than semantic, form.  For example, EXPR
      might be a SCOPE_REF, rather than the VAR_DECL to which the
@@ -4927,11 +4997,18 @@ convert_nontype_argument (tree type, tree expr)
      so that access checking can be performed when the template is
      instantiated -- but here we need the resolved form so that we can
      convert the argument.  */
-  expr = fold_non_dependent_expr (expr);
+  if (TYPE_REF_OBJ_P (type)
+      && has_value_dependent_address (expr))
+    /* If we want the address and it's value-dependent, don't fold.  */;
+  else if (!type_unknown_p (expr))
+    expr = fold_non_dependent_expr_sfinae (expr, complain);
   if (error_operand_p (expr))
     return error_mark_node;
   expr_type = TREE_TYPE (expr);
-  expr = mark_rvalue_use (expr);
+  if (TREE_CODE (type) == REFERENCE_TYPE)
+    expr = mark_lvalue_use (expr);
+  else
+    expr = mark_rvalue_use (expr);
 
   /* HACK: Due to double coercion, we can get a
      NOP_EXPR<REFERENCE_TYPE>(ADDR_EXPR<POINTER_TYPE> (arg)) here,
@@ -4992,15 +5069,16 @@ convert_nontype_argument (tree type, tree expr)
         do not fold into integer constants.  */
       if (TREE_CODE (expr) != INTEGER_CST)
        {
-         error ("%qE is not a valid template argument for type %qT "
-                "because it is a non-constant expression", expr, type);
+         if (complain & tf_error)
+           error ("%qE is not a valid template argument for type %qT "
+                  "because it is a non-constant expression", expr, type);
          return NULL_TREE;
        }
 
       /* At this point, an implicit conversion does what we want,
         because we already know that the expression is of integral
         type.  */
-      expr = ocp_convert (type, expr, CONV_IMPLICIT, LOOKUP_PROTECT);
+      expr = perform_implicit_conversion (type, expr, complain);
       if (expr == error_mark_node)
        return error_mark_node;
 
@@ -5250,7 +5328,8 @@ convert_nontype_argument (tree type, tree expr)
 
   /* Sanity check: did we actually convert the argument to the
      right type?  */
-  gcc_assert (same_type_p (type, TREE_TYPE (expr)));
+  gcc_assert (same_type_ignoring_top_level_qualifiers_p
+             (type, TREE_TYPE (expr)));
   return expr;
 }
 
@@ -5715,7 +5794,7 @@ convert_template_argument (tree parm,
           conversions can occur is part of determining which
           function template to call, or whether a given explicit
           argument specification is valid.  */
-       val = convert_nontype_argument (t, orig_arg);
+       val = convert_nontype_argument (t, orig_arg, complain);
       else
        val = orig_arg;
 
@@ -5922,15 +6001,15 @@ coerce_template_parms (tree parms,
     {
       if (complain & tf_error)
        {
-          const char *or_more = "";
           if (variadic_p)
             {
-              or_more = " or more";
               --nparms;
+             error ("wrong number of template arguments "
+                    "(%d, should be %d or more)", nargs, nparms);
             }
-
-         error ("wrong number of template arguments (%d, should be %d%s)",
-                 nargs, nparms, or_more);
+         else
+            error ("wrong number of template arguments "
+                   "(%d, should be %d)", nargs, nparms);
 
          if (in_decl)
            error ("provided for %q+D", in_decl);
@@ -6155,7 +6234,7 @@ add_pending_template (tree d)
   if (level)
     push_tinst_level (d);
 
-  pt = GGC_NEW (struct pending_template);
+  pt = ggc_alloc_pending_template ();
   pt->next = NULL;
   pt->tinst = current_tinst_level;
   if (last_pending_template)
@@ -6471,11 +6550,16 @@ lookup_template_class (tree d1,
               i > 0 && t != NULL_TREE;
               --i, t = TREE_CHAIN (t))
            {
-             tree a = coerce_template_parms (TREE_VALUE (t),
-                                             arglist, gen_tmpl,
-                                             complain,
-                                             /*require_all_args=*/true,
-                                             /*use_default_args=*/true);
+             tree a;
+             if (i == saved_depth)
+               a = coerce_template_parms (TREE_VALUE (t),
+                                          arglist, gen_tmpl,
+                                          complain,
+                                          /*require_all_args=*/true,
+                                          /*use_default_args=*/true);
+             else
+               /* Outer levels should have already been coerced.  */
+               a = TMPL_ARGS_LEVEL (arglist, i);
 
              /* Don't process further if one of the levels fails.  */
              if (a == error_mark_node)
@@ -6718,7 +6802,7 @@ lookup_template_class (tree d1,
       elt.spec = t;
       slot = (spec_entry **) htab_find_slot_with_hash (type_specializations,
                                                       &elt, hash, INSERT);
-      *slot = GGC_NEW (spec_entry);
+      *slot = ggc_alloc_spec_entry ();
       **slot = elt;
 
       /* Note this use of the partial instantiation so we can check it
@@ -7076,7 +7160,7 @@ push_tinst_level (tree d)
       return 0;
     }
 
-  new_level = GGC_NEW (struct tinst_level);
+  new_level = ggc_alloc_tinst_level ();
   new_level->decl = d;
   new_level->locus = input_location;
   new_level->in_system_header_p = in_system_header;
@@ -7661,11 +7745,9 @@ perform_typedefs_access_check (tree tmpl, tree targs)
     return;
 
   saved_location = input_location;
-  for (i = 0;
-       VEC_iterate (qualified_typedef_usage_t,
+  FOR_EACH_VEC_ELT (qualified_typedef_usage_t,
                    get_types_needing_access_check (tmpl),
-                   i, iter);
-       ++i)
+                   i, iter)
     {
       tree type_decl = iter->typedef_decl;
       tree type_scope = iter->context;
@@ -7699,8 +7781,7 @@ instantiate_class_template (tree type)
   if (type == error_mark_node)
     return error_mark_node;
 
-  if (TYPE_BEING_DEFINED (type)
-      || COMPLETE_TYPE_P (type)
+  if (COMPLETE_OR_OPEN_TYPE_P (type)
       || uses_template_parms (type))
     return type;
 
@@ -7710,7 +7791,7 @@ instantiate_class_template (tree type)
 
   /* Determine what specialization of the original template to
      instantiate.  */
-  t = most_specialized_class (type, templ);
+  t = most_specialized_class (type, templ, tf_warning_or_error);
   if (t == error_mark_node)
     {
       TYPE_BEING_DEFINED (type) = 1;
@@ -7764,16 +7845,17 @@ instantiate_class_template (tree type)
   /* Set the input location to the most specialized template definition.
      This is needed if tsubsting causes an error.  */
   typedecl = TYPE_MAIN_DECL (pattern);
-  input_location = DECL_SOURCE_LOCATION (typedecl);
+  input_location = DECL_SOURCE_LOCATION (TYPE_NAME (type)) =
+    DECL_SOURCE_LOCATION (typedecl);
 
   TYPE_HAS_USER_CONSTRUCTOR (type) = TYPE_HAS_USER_CONSTRUCTOR (pattern);
   TYPE_HAS_NEW_OPERATOR (type) = TYPE_HAS_NEW_OPERATOR (pattern);
   TYPE_HAS_ARRAY_NEW_OPERATOR (type) = TYPE_HAS_ARRAY_NEW_OPERATOR (pattern);
   TYPE_GETS_DELETE (type) = TYPE_GETS_DELETE (pattern);
-  TYPE_HAS_ASSIGN_REF (type) = TYPE_HAS_ASSIGN_REF (pattern);
-  TYPE_HAS_CONST_ASSIGN_REF (type) = TYPE_HAS_CONST_ASSIGN_REF (pattern);
-  TYPE_HAS_INIT_REF (type) = TYPE_HAS_INIT_REF (pattern);
-  TYPE_HAS_CONST_INIT_REF (type) = TYPE_HAS_CONST_INIT_REF (pattern);
+  TYPE_HAS_COPY_ASSIGN (type) = TYPE_HAS_COPY_ASSIGN (pattern);
+  TYPE_HAS_CONST_COPY_ASSIGN (type) = TYPE_HAS_CONST_COPY_ASSIGN (pattern);
+  TYPE_HAS_COPY_CTOR (type) = TYPE_HAS_COPY_CTOR (pattern);
+  TYPE_HAS_CONST_COPY_CTOR (type) = TYPE_HAS_CONST_COPY_CTOR (pattern);
   TYPE_HAS_DEFAULT_CONSTRUCTOR (type) = TYPE_HAS_DEFAULT_CONSTRUCTOR (pattern);
   TYPE_HAS_CONVERSION (type) = TYPE_HAS_CONVERSION (pattern);
   TYPE_PACKED (type) = TYPE_PACKED (pattern);
@@ -7795,8 +7877,7 @@ instantiate_class_template (tree type)
      instantiate it, and that lookup should instantiate the enclosing
      class.  */
   gcc_assert (!DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (pattern))
-             || COMPLETE_TYPE_P (TYPE_CONTEXT (type))
-             || TYPE_BEING_DEFINED (TYPE_CONTEXT (type)));
+             || COMPLETE_OR_OPEN_TYPE_P (TYPE_CONTEXT (type)));
 
   base_list = NULL_TREE;
   if (BINFO_N_BASE_BINFOS (pbinfo))
@@ -8158,7 +8239,7 @@ instantiate_class_template (tree type)
      any member functions.  We don't do this earlier because the
      default arguments may reference members of the class.  */
   if (!PRIMARY_TEMPLATE_P (templ))
-    for (t = TYPE_METHODS (type); t; t = TREE_CHAIN (t))
+    for (t = TYPE_METHODS (type); t; t = DECL_CHAIN (t))
       if (TREE_CODE (t) == FUNCTION_DECL
          /* Implicitly generated member functions will not have template
             information; they are not instantiations, but instead are
@@ -8199,9 +8280,12 @@ tsubst_template_arg (tree t, tree args, tsubst_flags_t complain, tree in_decl)
     r = tsubst (t, args, complain, in_decl);
   else
     {
+      if (!(complain & tf_warning))
+       ++c_inhibit_evaluation_warnings;
       r = tsubst_expr (t, args, complain, in_decl,
                       /*integral_constant_expression_p=*/true);
-      r = fold_non_dependent_expr (r);
+      if (!(complain & tf_warning))
+       --c_inhibit_evaluation_warnings;
     }
   return r;
 }
@@ -8223,7 +8307,7 @@ make_fnparm_pack (tree spec_parm)
   /* Fill in PARMVEC and PARMTYPEVEC with all of the parameters.  */
   parmvec = make_tree_vec (len);
   parmtypevec = make_tree_vec (len);
-  for (i = 0; i < len; i++, spec_parm = TREE_CHAIN (spec_parm))
+  for (i = 0; i < len; i++, spec_parm = DECL_CHAIN (spec_parm))
     {
       TREE_VEC_ELT (parmvec, i) = spec_parm;
       TREE_VEC_ELT (parmtypevec, i) = TREE_TYPE (spec_parm);
@@ -8503,7 +8587,7 @@ get_pattern_parm (tree parm, tree tmpl)
   if (DECL_ARTIFICIAL (parm))
     {
       for (patparm = DECL_ARGUMENTS (pattern);
-          patparm; patparm = TREE_CHAIN (patparm))
+          patparm; patparm = DECL_CHAIN (patparm))
        if (DECL_ARTIFICIAL (patparm)
            && DECL_NAME (parm) == DECL_NAME (patparm))
          break;
@@ -8527,7 +8611,7 @@ tsubst_template_args (tree t, tree args, tsubst_flags_t complain, tree in_decl)
   tree orig_t = t;
   int len = TREE_VEC_LENGTH (t);
   int need_new = 0, i, expanded_len_adjust = 0, out;
-  tree *elts = (tree *) alloca (len * sizeof (tree));
+  tree *elts = XALLOCAVEC (tree, len);
 
   for (i = 0; i < len; i++)
     {
@@ -8898,7 +8982,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
              RETURN (error_mark_node);
 
            r = copy_decl (t);
-           TREE_CHAIN (r) = NULL_TREE;
+           DECL_CHAIN (r) = NULL_TREE;
            TREE_TYPE (r) = new_type;
            DECL_TEMPLATE_RESULT (r)
              = build_decl (DECL_SOURCE_LOCATION (decl),
@@ -8948,7 +9032,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
           than the old one.  */
        r = copy_decl (t);
        gcc_assert (DECL_LANG_SPECIFIC (r) != 0);
-       TREE_CHAIN (r) = NULL_TREE;
+       DECL_CHAIN (r) = NULL_TREE;
 
        DECL_TEMPLATE_INFO (r) = build_template_info (t, args);
 
@@ -9158,7 +9242,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
           assigned to the instantiation.  */
        DECL_INTERFACE_KNOWN (r) = !TREE_PUBLIC (r);
        DECL_DEFER_OUTPUT (r) = 0;
-       TREE_CHAIN (r) = NULL_TREE;
+       DECL_CHAIN (r) = NULL_TREE;
        DECL_PENDING_INLINE_INFO (r) = 0;
        DECL_PENDING_INLINE_P (r) = 0;
        DECL_SAVED_TREE (r) = NULL_TREE;
@@ -9357,12 +9441,12 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
             /* Build a proper chain of parameters when substituting
                into a function parameter pack.  */
             if (prev_r)
-              TREE_CHAIN (prev_r) = r;
+              DECL_CHAIN (prev_r) = r;
           }
 
-       if (TREE_CHAIN (t))
-         TREE_CHAIN (r) = tsubst (TREE_CHAIN (t), args,
-                                  complain, TREE_CHAIN (t));
+       if (DECL_CHAIN (t))
+         DECL_CHAIN (r) = tsubst (DECL_CHAIN (t), args,
+                                  complain, DECL_CHAIN (t));
 
         /* FIRST_R contains the start of the chain we've built.  */
         r = first_r;
@@ -9387,7 +9471,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
                         /*integral_constant_expression_p=*/true);
        /* We don't have to set DECL_CONTEXT here; it is set by
           finish_member_declaration.  */
-       TREE_CHAIN (r) = NULL_TREE;
+       DECL_CHAIN (r) = NULL_TREE;
        if (VOID_TYPE_P (type))
          error ("instantiation of %q+D as type %qT", r, type);
 
@@ -9414,7 +9498,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
       else
        {
          r = copy_node (t);
-         TREE_CHAIN (r) = NULL_TREE;
+         DECL_CHAIN (r) = NULL_TREE;
        }
       break;
 
@@ -9614,7 +9698,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
        else
          register_local_specialization (r, t);
 
-       TREE_CHAIN (r) = NULL_TREE;
+       DECL_CHAIN (r) = NULL_TREE;
 
        apply_late_template_attributes (&r, DECL_ATTRIBUTES (r),
                                        /*flags=*/0,
@@ -9838,7 +9922,15 @@ tsubst_exception_specification (tree fntype,
 
   specs = TYPE_RAISES_EXCEPTIONS (fntype);
   new_specs = NULL_TREE;
-  if (specs)
+  if (specs && TREE_PURPOSE (specs))
+    {
+      /* A noexcept-specifier.  */
+      new_specs = tsubst_copy_and_build
+       (TREE_PURPOSE (specs), args, complain, in_decl, /*function_p=*/false,
+        /*integral_constant_expression_p=*/true);
+      new_specs = build_noexcept_spec (new_specs, complain);
+    }
+  else if (specs)
     {
       if (! TREE_VALUE (specs))
        new_specs = specs;
@@ -9912,6 +10004,7 @@ tsubst_exception_specification (tree fntype,
 tree
 tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 {
+  enum tree_code code;
   tree type, r;
 
   if (t == NULL_TREE || t == error_mark_node
@@ -9928,7 +10021,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
   if (args == NULL_TREE)
     return t;
 
-  if (TREE_CODE (t) == IDENTIFIER_NODE)
+  code = TREE_CODE (t);
+
+  if (code == IDENTIFIER_NODE)
     type = IDENTIFIER_TYPE_VALUE (t);
   else
     type = TREE_TYPE (t);
@@ -9971,16 +10066,16 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
     }
 
   if (type
-      && TREE_CODE (t) != TYPENAME_TYPE
-      && TREE_CODE (t) != TEMPLATE_TYPE_PARM
-      && TREE_CODE (t) != IDENTIFIER_NODE
-      && TREE_CODE (t) != FUNCTION_TYPE
-      && TREE_CODE (t) != METHOD_TYPE)
+      && code != TYPENAME_TYPE
+      && code != TEMPLATE_TYPE_PARM
+      && code != IDENTIFIER_NODE
+      && code != FUNCTION_TYPE
+      && code != METHOD_TYPE)
     type = tsubst (type, args, complain, in_decl);
   if (type == error_mark_node)
     return error_mark_node;
 
-  switch (TREE_CODE (t))
+  switch (code)
     {
     case RECORD_TYPE:
     case UNION_TYPE:
@@ -10021,6 +10116,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
            && !TREE_TYPE (max))
          TREE_TYPE (max) = TREE_TYPE (TREE_OPERAND (max, 0));
 
+       max = mark_rvalue_use (max);
        max = fold_decl_constant_value (max);
 
        /* If we're in a partial instantiation, preserve the magic NOP_EXPR
@@ -10110,7 +10206,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
                  };  */
              return t;
 
-           if (TREE_CODE (t) == TEMPLATE_TYPE_PARM)
+           if (code == TEMPLATE_TYPE_PARM)
              {
                int quals;
                gcc_assert (TYPE_P (arg));
@@ -10120,7 +10216,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
                return cp_build_qualified_type_real
                  (arg, quals, complain | tf_ignore_bad_quals);
              }
-           else if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM)
+           else if (code == BOUND_TEMPLATE_TEMPLATE_PARM)
              {
                /* We are processing a type constructed from a
                   template template parameter.  */
@@ -10159,7 +10255,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
        /* If we get here, we must have been looking at a parm for a
           more deeply nested template.  Make a new version of this
           template parameter, but with a lower level.  */
-       switch (TREE_CODE (t))
+       switch (code)
          {
          case TEMPLATE_TYPE_PARM:
          case TEMPLATE_TEMPLATE_PARM:
@@ -10169,7 +10265,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
                r = tsubst (TYPE_MAIN_VARIANT (t), args, complain, in_decl);
                r = cp_build_qualified_type_real
                  (r, cp_type_quals (t),
-                  complain | (TREE_CODE (t) == TEMPLATE_TYPE_PARM
+                  complain | (code == TEMPLATE_TYPE_PARM
                               ? tf_ignore_bad_quals : 0));
              }
            else
@@ -10197,7 +10293,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
                else
                  TYPE_CANONICAL (r) = canonical_type_parameter (r);
 
-               if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM)
+               if (code == BOUND_TEMPLATE_TEMPLATE_PARM)
                  {
                    tree argvec = tsubst (TYPE_TI_ARGS (t), args,
                                          complain, in_decl);
@@ -10268,14 +10364,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
     case POINTER_TYPE:
     case REFERENCE_TYPE:
       {
-       enum tree_code code;
-
        if (type == TREE_TYPE (t) && TREE_CODE (type) != METHOD_TYPE)
          return t;
 
-       code = TREE_CODE (t);
-
-
        /* [temp.deduct]
 
           Type deduction may fail for any of the following
@@ -10460,7 +10551,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
          return error_mark_node;
 
        return fold_build2_loc (input_location,
-                           TREE_CODE (t), TREE_TYPE (t), e1, e2);
+                               code, TREE_TYPE (t), e1, e2);
       }
 
     case NEGATE_EXPR:
@@ -10470,7 +10561,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
        if (e == error_mark_node)
          return error_mark_node;
 
-       return fold_build1_loc (input_location, TREE_CODE (t), TREE_TYPE (t), e);
+       return fold_build1_loc (input_location, code, TREE_TYPE (t), e);
       }
 
     case TYPENAME_TYPE:
@@ -10626,9 +10717,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
     case TYPE_ARGUMENT_PACK:
     case NONTYPE_ARGUMENT_PACK:
       {
-        tree r = TYPE_P (t)
-          ? cxx_make_type (TREE_CODE (t))
-          : make_node (TREE_CODE (t));
+        tree r = TYPE_P (t) ? cxx_make_type (code) : make_node (code);
         tree packed_out = 
           tsubst_template_args (ARGUMENT_PACK_ARGS (t), 
                                 args,
@@ -10638,7 +10727,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 
         /* For template nontype argument packs, also substitute into
            the type.  */
-        if (TREE_CODE (t) == NONTYPE_ARGUMENT_PACK)
+        if (code == NONTYPE_ARGUMENT_PACK)
           TREE_TYPE (r) = tsubst (TREE_TYPE (t), args, complain, in_decl);
 
         return r;
@@ -10646,8 +10735,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
       break;
 
     default:
-      sorry ("use of %qs in template",
-            tree_code_name [(int) TREE_CODE (t)]);
+      sorry ("use of %qs in template", tree_code_name [(int) code]);
       return error_mark_node;
     }
 }
@@ -10691,6 +10779,8 @@ tsubst_baselink (tree baselink, tree object_type,
     if (IDENTIFIER_TYPENAME_P (name))
       name = mangle_conv_op_name_for_type (optype);
     baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1);
+    if (!baselink)
+      return error_mark_node;
 
     /* If lookup found a single function, mark it as used at this
        point.  (If it lookup found multiple functions the one selected
@@ -11266,8 +11356,13 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
       gcc_unreachable ();
 
     case OFFSET_REF:
-      mark_used (TREE_OPERAND (t, 1));
-      return t;
+      r = build2
+       (code, tsubst (TREE_TYPE (t), args, complain, in_decl),
+        tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl),
+        tsubst_copy (TREE_OPERAND (t, 1), args, complain, in_decl));
+      PTRMEM_OK_P (r) = PTRMEM_OK_P (t);
+      mark_used (TREE_OPERAND (r, 1));
+      return r;
 
     case EXPR_PACK_EXPANSION:
       error ("invalid use of pack expansion expression");
@@ -11619,14 +11714,19 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
                        tree t = RECUR (init);
 
                        if (init && !t)
-                         /* If we had an initializer but it
-                            instantiated to nothing,
-                            value-initialize the object.  This will
-                            only occur when the initializer was a
-                            pack expansion where the parameter packs
-                            used in that expansion were of length
-                            zero.  */
-                         init = build_value_init (TREE_TYPE (decl));
+                         {
+                           /* If we had an initializer but it
+                              instantiated to nothing,
+                              value-initialize the object.  This will
+                              only occur when the initializer was a
+                              pack expansion where the parameter packs
+                              used in that expansion were of length
+                              zero.  */
+                           init = build_value_init (TREE_TYPE (decl),
+                                                    complain);
+                           if (TREE_CODE (init) == AGGR_INIT_EXPR)
+                             init = get_target_expr (init);
+                         }
                        else
                          init = t;
                      }
@@ -12245,6 +12345,17 @@ tsubst_copy_and_build (tree t,
        return cxx_sizeof_or_alignof_expr (op1, TREE_CODE (t), 
                                            complain & tf_error);
 
+    case NOEXCEPT_EXPR:
+      op1 = TREE_OPERAND (t, 0);
+      ++cp_unevaluated_operand;
+      ++c_inhibit_evaluation_warnings;
+      op1 = tsubst_copy_and_build (op1, args, complain, in_decl,
+                                  /*function_p=*/false,
+                                  /*integral_constant_expression_p=*/false);
+      --cp_unevaluated_operand;
+      --c_inhibit_evaluation_warnings;
+      return finish_noexcept_expr (op1, complain);
+
     case MODOP_EXPR:
       {
        tree r = build_x_modify_expr
@@ -12443,15 +12554,24 @@ tsubst_copy_and_build (tree t,
          ret = build_offset_ref_call_from_tree (function, &call_args);
        else if (TREE_CODE (function) == COMPONENT_REF)
          {
-           if (!BASELINK_P (TREE_OPERAND (function, 1)))
+           tree instance = TREE_OPERAND (function, 0);
+           tree fn = TREE_OPERAND (function, 1);
+
+           if (processing_template_decl
+               && (type_dependent_expression_p (instance)
+                   || (!BASELINK_P (fn)
+                       && TREE_CODE (fn) != FIELD_DECL)
+                   || type_dependent_expression_p (fn)
+                   || any_type_dependent_arguments_p (call_args)))
+             ret = build_nt_call_vec (function, call_args);
+           else if (!BASELINK_P (fn))
              ret = finish_call_expr (function, &call_args,
                                       /*disallow_virtual=*/false,
                                       /*koenig_p=*/false,
                                       complain);
            else
              ret = (build_new_method_call
-                     (TREE_OPERAND (function, 0),
-                      TREE_OPERAND (function, 1),
+                     (instance, fn,
                       &call_args, NULL_TREE,
                       qualified_p ? LOOKUP_NONVIRTUAL : LOOKUP_NORMAL,
                       /*fn_p=*/NULL,
@@ -12691,7 +12811,7 @@ tsubst_copy_and_build (tree t,
 
        n = VEC_copy (constructor_elt, gc, CONSTRUCTOR_ELTS (t));
         newlen = VEC_length (constructor_elt, n);
-       for (idx = 0; VEC_iterate (constructor_elt, n, idx, ce); idx++)
+       FOR_EACH_VEC_ELT (constructor_elt, n, idx, ce)
          {
            if (ce->index && process_index_p)
              ce->index = RECUR (ce->index);
@@ -12725,8 +12845,7 @@ tsubst_copy_and_build (tree t,
             VEC(constructor_elt,gc) *old_n = n;
 
             n = VEC_alloc (constructor_elt, gc, newlen);
-            for (idx = 0; VEC_iterate (constructor_elt, old_n, idx, ce); 
-                 idx++)
+            FOR_EACH_VEC_ELT (constructor_elt, old_n, idx, ce)
               {
                 if (TREE_CODE (ce->value) == TREE_VEC)
                   {
@@ -13064,7 +13183,7 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain)
      instantiate all the alternate entry points as well.  We do this
      by cloning the instantiation of the main entry point, not by
      instantiating the template clones.  */
-  if (TREE_CHAIN (gen_tmpl) && DECL_CLONED_FUNCTION_P (TREE_CHAIN (gen_tmpl)))
+  if (DECL_CHAIN (gen_tmpl) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (gen_tmpl)))
     clone_function_decl (fndecl, /*update_method_vec_p=*/0);
 
   return fndecl;
@@ -15915,7 +16034,7 @@ most_general_template (tree decl)
    returned.  */
 
 static tree
-most_specialized_class (tree type, tree tmpl)
+most_specialized_class (tree type, tree tmpl, tsubst_flags_t complain)
 {
   tree list = NULL_TREE;
   tree t;
@@ -16035,6 +16154,8 @@ most_specialized_class (tree type, tree tmpl)
     {
       const char *str;
       char *spaces = NULL;
+      if (!(complain & tf_error))
+       return error_mark_node;
       error ("ambiguous class template instantiation for %q#T", type);
       str = TREE_CHAIN (list) ? _("candidates are:") : _("candidate is:");
       for (t = list; t; t = TREE_CHAIN (t))
@@ -16333,12 +16454,12 @@ do_type_instantiation (tree t, tree storage, tsubst_flags_t complain)
        interpretation is that it should be an explicit instantiation.  */
 
     if (! static_p)
-      for (tmp = TYPE_METHODS (t); tmp; tmp = TREE_CHAIN (tmp))
+      for (tmp = TYPE_METHODS (t); tmp; tmp = DECL_CHAIN (tmp))
        if (TREE_CODE (tmp) == FUNCTION_DECL
            && DECL_TEMPLATE_INSTANTIATION (tmp))
          instantiate_class_member (tmp, extern_p);
 
-    for (tmp = TYPE_FIELDS (t); tmp; tmp = TREE_CHAIN (tmp))
+    for (tmp = TYPE_FIELDS (t); tmp; tmp = DECL_CHAIN (tmp))
       if (TREE_CODE (tmp) == VAR_DECL && DECL_TEMPLATE_INSTANTIATION (tmp))
        instantiate_class_member (tmp, extern_p);
 
@@ -16426,8 +16547,8 @@ regenerate_decl_from_template (tree decl, tree tmpl)
              DECL_ATTRIBUTES (decl_parm) = attributes;
              cplus_decl_attributes (&decl_parm, attributes, /*flags=*/0);
            }
-         decl_parm = TREE_CHAIN (decl_parm);
-         pattern_parm = TREE_CHAIN (pattern_parm);
+         decl_parm = DECL_CHAIN (decl_parm);
+         pattern_parm = DECL_CHAIN (pattern_parm);
        }
       /* Merge any parameters that match with the function parameter
          pack.  */
@@ -16459,7 +16580,7 @@ regenerate_decl_from_template (tree decl, tree tmpl)
                   DECL_ATTRIBUTES (decl_parm) = attributes;
                   cplus_decl_attributes (&decl_parm, attributes, /*flags=*/0);
                 }
-              decl_parm = TREE_CHAIN (decl_parm);
+              decl_parm = DECL_CHAIN (decl_parm);
             }
         }
       /* Merge additional specifiers from the CODE_PATTERN.  */
@@ -16869,8 +16990,8 @@ instantiate_decl (tree d, int defer_ok,
       while (tmpl_parm && !FUNCTION_PARAMETER_PACK_P (tmpl_parm))
        {
          register_local_specialization (spec_parm, tmpl_parm);
-         tmpl_parm = TREE_CHAIN (tmpl_parm);
-         spec_parm = TREE_CHAIN (spec_parm);
+         tmpl_parm = DECL_CHAIN (tmpl_parm);
+         spec_parm = DECL_CHAIN (spec_parm);
        }
       if (tmpl_parm && FUNCTION_PARAMETER_PACK_P (tmpl_parm))
         {
@@ -16878,7 +16999,7 @@ instantiate_decl (tree d, int defer_ok,
              TMPL_PARM, then move on.  */
          tree argpack = make_fnparm_pack (spec_parm);
           register_local_specialization (argpack, tmpl_parm);
-          tmpl_parm = TREE_CHAIN (tmpl_parm);
+          tmpl_parm = DECL_CHAIN (tmpl_parm);
          spec_parm = NULL_TREE;
         }
       gcc_assert (!spec_parm);
@@ -17174,7 +17295,8 @@ tsubst_enum (tree tag, tree newtag, tree args)
       set_current_access_from_decl (decl);
 
       /* Actually build the enumerator itself.  */
-      build_enumerator (DECL_NAME (decl), value, newtag);
+      build_enumerator
+       (DECL_NAME (decl), value, newtag, DECL_SOURCE_LOCATION (decl));
     }
 
   finish_enum (newtag);
@@ -17463,40 +17585,6 @@ dependent_scope_p (tree scope)
          && !currently_open_class (scope));
 }
 
-/* Returns TRUE if EXPRESSION is dependent, according to CRITERION.  */
-
-static bool
-dependent_scope_ref_p (tree expression, bool criterion (tree))
-{
-  tree scope;
-  tree name;
-
-  gcc_assert (TREE_CODE (expression) == SCOPE_REF);
-
-  if (!TYPE_P (TREE_OPERAND (expression, 0)))
-    return true;
-
-  scope = TREE_OPERAND (expression, 0);
-  name = TREE_OPERAND (expression, 1);
-
-  /* [temp.dep.expr]
-
-     An id-expression is type-dependent if it contains a
-     nested-name-specifier that contains a class-name that names a
-     dependent type.  */
-  /* The suggested resolution to Core Issue 224 implies that if the
-     qualifying type is the current class, then we must peek
-     inside it.  */
-  if (DECL_P (name)
-      && currently_open_class (scope)
-      && !criterion (name))
-    return false;
-  if (dependent_type_p (scope))
-    return true;
-
-  return false;
-}
-
 /* Returns TRUE if the EXPRESSION is value-dependent, in the sense of
    [temp.dep.constexpr].  EXPRESSION is already known to be a constant
    expression.  */
@@ -17579,8 +17667,17 @@ value_dependent_expression_p (tree expression)
        return dependent_type_p (expression);
       return type_dependent_expression_p (expression);
 
+    case NOEXCEPT_EXPR:
+      expression = TREE_OPERAND (expression, 0);
+      /* FIXME why check value-dependency?  */
+      return (type_dependent_expression_p (expression)
+             || value_dependent_expression_p (expression));
+
     case SCOPE_REF:
-      return dependent_scope_ref_p (expression, value_dependent_expression_p);
+      {
+       tree name = TREE_OPERAND (expression, 1);
+       return value_dependent_expression_p (name);
+      }
 
     case COMPONENT_REF:
       return (value_dependent_expression_p (TREE_OPERAND (expression, 0))
@@ -17617,6 +17714,13 @@ value_dependent_expression_p (tree expression)
       return ((value_dependent_expression_p (TREE_OPERAND (expression, 0)))
              || (value_dependent_expression_p (TREE_OPERAND (expression, 2))));
 
+    case ADDR_EXPR:
+      {
+       tree op = TREE_OPERAND (expression, 0);
+       return (value_dependent_expression_p (op)
+               || has_value_dependent_address (op));
+      }
+
     default:
       /* A constant expression is value-dependent if any subexpression is
         value-dependent.  */
@@ -17680,6 +17784,7 @@ type_dependent_expression_p (tree expression)
   if (TREE_CODE (expression) == PSEUDO_DTOR_EXPR
       || TREE_CODE (expression) == SIZEOF_EXPR
       || TREE_CODE (expression) == ALIGNOF_EXPR
+      || TREE_CODE (expression) == NOEXCEPT_EXPR
       || TREE_CODE (expression) == TRAIT_EXPR
       || TREE_CODE (expression) == TYPEID_EXPR
       || TREE_CODE (expression) == DELETE_EXPR
@@ -17715,10 +17820,19 @@ type_dependent_expression_p (tree expression)
        return dependent_type_p (type);
     }
 
-  if (TREE_CODE (expression) == SCOPE_REF
-      && dependent_scope_ref_p (expression,
-                               type_dependent_expression_p))
-    return true;
+  if (TREE_CODE (expression) == SCOPE_REF)
+    {
+      tree scope = TREE_OPERAND (expression, 0);
+      tree name = TREE_OPERAND (expression, 1);
+
+      /* 14.6.2.2 [temp.dep.expr]: An id-expression is type-dependent if it
+        contains an identifier associated by name lookup with one or more
+        declarations declared with a dependent type, or...a
+        nested-name-specifier or qualified-id that names a member of an
+        unknown specialization.  */
+      return (type_dependent_expression_p (name)
+             || dependent_scope_p (scope));
+    }
 
   if (TREE_CODE (expression) == FUNCTION_DECL
       && DECL_LANG_SPECIFIC (expression)
@@ -17821,7 +17935,7 @@ any_type_dependent_arguments_p (const VEC(tree,gc) *args)
   unsigned int i;
   tree arg;
 
-  for (i = 0; VEC_iterate (tree, args, i, arg); ++i)
+  FOR_EACH_VEC_ELT (tree, args, i, arg)
     {
       if (type_dependent_expression_p (arg))
        return true;
@@ -18257,7 +18371,7 @@ make_args_non_dependent (VEC(tree,gc) *args)
   unsigned int ix;
   tree arg;
 
-  for (ix = 0; VEC_iterate (tree, args, ix, arg); ++ix)
+  FOR_EACH_VEC_ELT (tree, args, ix, arg)
     {
       tree newarg = build_non_dependent_expr (arg);
       if (newarg != arg)
@@ -18560,11 +18674,9 @@ append_type_to_template_for_access_check (tree templ,
   gcc_assert (type_decl && (TREE_CODE (type_decl) == TYPE_DECL));
 
   /* Make sure we don't append the type to the template twice.  */
-  for (i = 0;
-       VEC_iterate (qualified_typedef_usage_t,
+  FOR_EACH_VEC_ELT (qualified_typedef_usage_t,
                    get_types_needing_access_check (templ),
-                   i, iter);
-       ++i)
+                   i, iter)
     if (iter->typedef_decl == type_decl && scope == iter->context)
       return;