re PR c++/57638 (warning container: 'integer_cst’ not supported by dump_type#<type...
[gcc.git] / gcc / cp / pt.c
index 8f88b10fef3c25531912035169c783ad3761ed5b..517f05b3f42144bd528a76d0d8904e143dad29be 100644 (file)
@@ -5375,7 +5375,7 @@ unify_no_common_base (bool explain_p, enum template_base_result r,
       {
       case tbr_ambiguous_baseclass:
        inform (input_location, "  %qT is an ambiguous base class of %qT",
-               arg, parm);
+               parm, arg);
        break;
       default:
        inform (input_location, "  %qT is not derived from %qT", arg, parm);
@@ -7561,7 +7561,7 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
       if (CLASS_TYPE_P (template_type) && is_dependent_type)
        /* If the type makes use of template parameters, the
           code that generates debugging information will crash.  */
-       DECL_IGNORED_P (TYPE_STUB_DECL (t)) = 1;
+       DECL_IGNORED_P (TYPE_MAIN_DECL (t)) = 1;
 
       /* Possibly limit visibility based on template args.  */
       TREE_PUBLIC (type_decl) = 1;
@@ -8863,9 +8863,8 @@ instantiate_class_template_1 (tree type)
                  else if (TREE_CODE (r) == FIELD_DECL)
                    {
                      /* Determine whether R has a valid type and can be
-                        completed later.  If R is invalid, then it is
-                        replaced by error_mark_node so that it will not be
-                        added to TYPE_FIELDS.  */
+                        completed later.  If R is invalid, then its type is
+                        replaced by error_mark_node.  */
                      tree rtype = TREE_TYPE (r);
                      if (can_complete_type_without_circularity (rtype))
                        complete_type (rtype);
@@ -8873,7 +8872,7 @@ instantiate_class_template_1 (tree type)
                      if (!COMPLETE_TYPE_P (rtype))
                        {
                          cxx_incomplete_type_error (r, rtype);
-                         r = error_mark_node;
+                         TREE_TYPE (r) = error_mark_node;
                        }
                    }
 
@@ -9202,8 +9201,15 @@ use_pack_expansion_extra_args_p (tree parm_packs,
                                 int arg_pack_len,
                                 bool has_empty_arg)
 {
+  /* If one pack has an expansion and another pack has a normal
+     argument or if one pack has an empty argument and an another
+     one hasn't then tsubst_pack_expansion cannot perform the
+     substitution and need to fall back on the
+     PACK_EXPANSION_EXTRA mechanism.  */
   if (parm_packs == NULL_TREE)
     return false;
+  else if (has_empty_arg)
+    return true;
 
   bool has_expansion_arg = false;
   for (int i = 0 ; i < arg_pack_len; ++i)
@@ -9221,13 +9227,7 @@ use_pack_expansion_extra_args_p (tree parm_packs,
            has_non_expansion_arg = true;
        }
 
-      /* If one pack has an expansion and another pack has a normal
-        argument or if one pack has an empty argument another one
-        hasn't then tsubst_pack_expansion cannot perform the
-        substitution and need to fall back on the
-        PACK_EXPANSION_EXTRA mechanism.  */
-      if ((has_expansion_arg && has_non_expansion_arg)
-         || (has_empty_arg && (has_expansion_arg || has_non_expansion_arg)))
+      if (has_expansion_arg && has_non_expansion_arg)
        return true;
     }
   return false;
@@ -10513,8 +10513,6 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
        /* We don't have to set DECL_CONTEXT here; it is set by
           finish_member_declaration.  */
        DECL_CHAIN (r) = NULL_TREE;
-       if (VOID_TYPE_P (type))
-         error ("instantiation of %q+D as type %qT", r, type);
 
        apply_late_template_attributes (&r, DECL_ATTRIBUTES (r), 0,
                                        args, complain, in_decl);
@@ -14401,7 +14399,10 @@ tsubst_copy_and_build (tree t,
         newlen = vec_safe_length (n);
        FOR_EACH_VEC_SAFE_ELT (n, idx, ce)
          {
-           if (ce->index && process_index_p)
+           if (ce->index && process_index_p
+               /* An identifier index is looked up in the type
+                  being initialized, not the current scope.  */
+               && TREE_CODE (ce->index) != IDENTIFIER_NODE)
              ce->index = RECUR (ce->index);
 
             if (PACK_EXPANSION_P (ce->value))
@@ -16960,7 +16961,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
           later.  */
        return unify_success (explain_p);
       else
-       return unify_type_mismatch (explain_p, tparm, arg);
+       return unify_type_mismatch (explain_p, tparm, TREE_TYPE (arg));
 
       /* If ARG is a parameter pack or an expansion, we cannot unify
         against it unless PARM is also a parameter pack.  */
@@ -17398,6 +17399,13 @@ mark_decl_instantiated (tree result, int extern_p)
   if (TREE_ASM_WRITTEN (result))
     return;
 
+  /* For anonymous namespace we don't need to do anything.  */
+  if (decl_anon_ns_mem_p (result))
+    {
+      gcc_assert (!TREE_PUBLIC (result));
+      return;
+    }
+
   if (TREE_CODE (result) != FUNCTION_DECL)
     /* The TREE_PUBLIC flag for function declarations will have been
        set correctly by tsubst.  */
@@ -20071,6 +20079,29 @@ type_dependent_expression_p (tree expression)
       && VAR_HAD_UNKNOWN_BOUND (expression))
     return true;
 
+  /* An array of unknown bound depending on a variadic parameter, eg:
+
+     template<typename... Args>
+       void foo (Args... args)
+       {
+         int arr[] = { args... };
+       }
+
+     template<int... vals>
+       void bar ()
+       {
+         int arr[] = { vals... };
+       }
+
+     If the array has no length and has an initializer, it must be that
+     we couldn't determine its length in cp_complete_array_type because
+     it is dependent.  */
+  if (VAR_P (expression)
+      && TREE_CODE (TREE_TYPE (expression)) == ARRAY_TYPE
+      && !TYPE_DOMAIN (TREE_TYPE (expression))
+      && DECL_INITIAL (expression))
+   return true;
+
   if (TREE_TYPE (expression) == unknown_type_node)
     {
       if (TREE_CODE (expression) == ADDR_EXPR)
@@ -20173,7 +20204,8 @@ instantiation_dependent_r (tree *tp, int *walk_subtrees,
 
     case TRAIT_EXPR:
       if (dependent_type_p (TRAIT_EXPR_TYPE1 (*tp))
-         || dependent_type_p (TRAIT_EXPR_TYPE2 (*tp)))
+         || (TRAIT_EXPR_TYPE2 (*tp)
+             && dependent_type_p (TRAIT_EXPR_TYPE2 (*tp))))
        return *tp;
       *walk_subtrees = false;
       return NULL_TREE;
@@ -20362,8 +20394,7 @@ any_template_arguments_need_structural_equality_p (tree args)
 
              if (error_operand_p (arg))
                return true;
-             else if (TREE_CODE (arg) == TEMPLATE_DECL
-                      || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
+             else if (TREE_CODE (arg) == TEMPLATE_DECL)
                continue;
              else if (TYPE_P (arg) && TYPE_STRUCTURAL_EQUALITY_P (arg))
                return true;