https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80290

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org

--- Comment #28 from Jason Merrill <jason at gcc dot gnu.org> ---
This is definitely an algorithmic complexity issue.  With 4 levels of pair, we
do 3886 substitutions of default arguments.  With 5 levels, we do 23326, a bit
more than 5x as many.

The basic problem seems to be that for function parameters that have no
deducible template parameters, we check convertibility as part of type
deduction, and then we check convertibility again once we've actually formed
the candidate.  And many of the pair constructor templates use the pair
template parameters in their parameter types, which are non-deducible in this
context.

With a simple example like

template <class T, class U>
struct A
{ 
  template <class U2 = U>
  A(T, U) { }
};

using A1 = A<int, int>;
using A2 = A<int, A1>;
using A3 = A<int, A2>;

A1 a1 = { 1, 1 };
A2 a2 = { 1, { 1, 1 } };
A3 a3 = { 1, { 1, { 1, 1 } } };

We end up considering the constructor template once for a1, three times (rather
than twice) for a2, and seven times (rather than three times) for a3.

If the second parameter is U2, and therefore deduced, the number of constructor
calls scales linearly as expected.

Reply via email to