From ef5850f13b0319e07cdbdb387c7c8a81e1a80f50 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 27 Jun 2018 20:25:21 -0400 Subject: [PATCH] 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. From-SVN: r262204 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/pt.c | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7fabfa0109be..a9fcc709a923 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-06-26 Jason Merrill + + 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 PR c++/86291 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 79cfd0129226..71077a3b0498 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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; -- 2.47.2