http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54318

             Bug #: 54318
           Summary: [C++11] Bogus "template instantiation depth exceeds
                    maximum" error + segfault
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: zeratul...@hotmail.com


The following code:


template <typename T>
struct wrapped
{
    typedef T type;
};

template <typename T>
typename T::type unwrap1(T);

int unwrap(int);

template <typename T>
auto unwrap(T t) -> decltype(unwrap(unwrap1(t)))
{
    return unwrap(unwrap1(t));
}

int main()
{
    unwrap(wrapped<wrapped<int>>());
}


Seems to produce an infinite loop in GCC, as it displays the same error message
over and over again, and eventualy segfaults.

Here is the error message:

test.cpp:13:6: error: template instantiation depth exceeds maximum of 900 (use
-ftemplate-depth= to increase the maximum) substituting 'template<class T>
typename T::type unwrap1(T) [with T = wrapped<wrapped<int> >]'
 auto unwrap(T t) -> decltype(unwrap(unwrap1(t)))
      ^
test.cpp:13:6:   recursively required by substitution of 'template<class T>
decltype (unwrap(unwrap1(t))) unwrap(T) [with T = wrapped<int>]'
test.cpp:13:6:   required by substitution of 'template<class T> decltype
(unwrap(unwrap1(t))) unwrap(T) [with T = wrapped<int>]'
test.cpp:15:29:   template instantiation depth exceeds maximum of 900 (use
-ftemplate-depth= to increase the maximum) substituting 'template<class T>
typename T::type unwrap1(T) [with T = wrapped<wrapped<int> >]'

The last 3 lines are repeated thousands of times until finally:

g++: internal compiler error: Segmentation fault (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


I believe the code is valid. Clang compiles it without errors.

Reply via email to