]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/cp/call.c
PR c++/80290 - memory-hog with std::pair.
authorJason Merrill <jason@redhat.com>
Wed, 27 Jun 2018 02:59:38 +0000 (22:59 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 27 Jun 2018 02:59:38 +0000 (22:59 -0400)
commit6147a53a9cb946ab08acb0177cff29a40aee937b
tree059a3a0d5a3e138552dc289f6a8a57827ababb92
parentb8d636f00d94a8f04a3cc32025c9263450705e9d
PR c++/80290 - memory-hog with std::pair.

* pt.c (fn_type_unification): Add convs parameter.
(check_non_deducible_conversion): Remember conversion.
(check_non_deducible_conversions): New.  Do checks here.
(type_unification_real): Not here.  Remove flags parm.
* call.c (add_function_candidate): Make convs a parameter.
Don't recalculate the conversion if it's already set.
(add_template_candidate_real): Allocate convs here.
(good_conversion, conv_flags): New.

When the std::pair constructors got more complex to handle, it aggravated a
preexisting algorithmic problem in template overload resolution:

As part of template argument deduction in a call, once we've deduced all
the template arguments we can but before we substitute them to form an
actual declaration, for any function parameters that don't involve template
parameters we need to check that it's possible to convert the argument to
the parameter type (wg21.link/cwg1391).

As a result, we end up calculating the conversion twice: once here, and
then again in add_function_candidate as part of normal overload resolution.
Normally this isn't a big deal, but when the argument is a multiply-nested
initializer list, doubling the conversion processing at each level leads to
combinatorial explosion.

The patch for trunk avoids the duplication by remembering the conversion we
calculate at deduction time and then reusing it in overload resolution
rather than calculating it again.

From-SVN: r262172
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/pt.c