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

            Bug ID: 66059
           Summary: make_integer_sequence should use a log(N)
                    implementation
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: compile-time-hog
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rhalbersma at gmail dot com
  Target Milestone: ---

The following program fails to compile for g++ 4.9.0 and further 

#include <utility>

int main()
{
    constexpr auto N = 1024;
    using T = std::make_integer_sequence<int, N>;
    static_assert(T::size() == N, "");
}

fatal error: template instantiation depth exceeds maximum of 900 (use
-ftemplate-depth= to increase the maximum)

Note that Clang with -stdlib=libc++ can compile integer sequences of up to one
million for machines with enough memory, and around 65K for online compilers
such as wandbox.com. Clang + libstdc++ requires -ftemplate-depth=N for N beyond
256. 

Changing g++ default template instantiation depth beyond 900 is not a viable
solution. It simply masks the problem of excessive template instantiations. 

Instead, the implementation of make_integer_sequence<T, N> should be made to
scale as log(N). See e.g. http://stackoverflow.com/a/17426611/819272

Reply via email to