]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/80290 - memory-hog with std::pair.
authorJason Merrill <jason@redhat.com>
Thu, 28 Jun 2018 00:25:21 +0000 (20:25 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 28 Jun 2018 00:25:21 +0000 (20:25 -0400)
* pt.c (type_unification_real): Skip non-dependent conversion
check for a nested list argument.
(braced_init_depth): New.

From-SVN: r262204

gcc/cp/ChangeLog
gcc/cp/pt.c

index 7fabfa0109bedfcf93b97cfae7b33e8581c57523..a9fcc709a9230fd33b23d6c5df1f14c391d220b4 100644 (file)
@@ -1,3 +1,10 @@
+2018-06-26  Jason Merrill  <jason@redhat.com>
+
+       PR c++/80290 - memory-hog with std::pair.
+       * pt.c (type_unification_real): Skip non-dependent conversion
+       check for a nested list argument.
+       (braced_init_depth): New.
+
 2018-06-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/86291
index 79cfd01292260a91b3e9fb2f72d03158ebe1013f..71077a3b049847ccc6a67653e0da3027fa9cc8b2 100644 (file)
@@ -19242,6 +19242,24 @@ try_array_deduction (tree tparms, tree targs, tree parm)
                          /*nondeduced*/false, array_deduction_r);
 }
 
+/* Returns how many levels of { } INIT contains.  */
+
+static int
+braced_init_depth (tree init)
+{
+  if (!init || !BRACE_ENCLOSED_INITIALIZER_P (init))
+    return 0;
+  unsigned i; tree val;
+  unsigned max = 0;
+  FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), i, val)
+    {
+      unsigned elt_d = braced_init_depth (val);
+      if (elt_d > max)
+       max = elt_d;
+    }
+  return max + 1;
+}
+
 /* Most parms like fn_type_unification.
 
    If SUBR is 1, we're being called recursively (to unify the
@@ -19478,6 +19496,10 @@ type_unification_real (tree tparms,
 
            if (uses_template_parms (parm))
              continue;
+           /* Workaround for c++/80290: avoid combinatorial explosion on
+              deeply nested braced init-lists.  */
+           if (braced_init_depth (arg) > 2)
+             continue;
            if (check_non_deducible_conversion (parm, arg, strict, flags,
                                                explain_p))
              return 1;