Open Quuxplusone opened 12 years ago
Attached brainfuck.cpp
(1382 bytes, text/x-c++src): Example program
This bug still exists.
Clang crashes when attempting to compile this (preprocessed) code with options:
-std=c++11 -ftemplate-depth=2000
template<unsigned... _Indexes>
struct _Index_tuple
{
typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
};
template<unsigned _Num>
struct _Build_index_tuple
{
typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type;
};
template<>
struct _Build_index_tuple<0>
{
typedef _Index_tuple<> __type;
};
template<typename _Tp, _Tp... _Idx>
struct integer_sequence
{
typedef _Tp value_type;
static constexpr unsigned size() { return sizeof...(_Idx); }
};
template<typename _Tp, _Tp _Num,
typename _ISeq = typename _Build_index_tuple<_Num>::__type>
struct _Make_integer_sequence;
template<typename _Tp, _Tp _Num, unsigned... _Idx>
struct _Make_integer_sequence<_Tp, _Num, _Index_tuple<_Idx...>>
{
typedef integer_sequence<_Tp, static_cast<_Tp>(_Idx)...> __type;
};
template<typename _Tp, _Tp _Num>
using make_integer_sequence
= typename _Make_integer_sequence<_Tp, _Num>::__type;
template<unsigned... _Idx>
using index_sequence = integer_sequence<unsigned, _Idx...>;
template<unsigned _Num>
using make_index_sequence = make_integer_sequence<unsigned, _Num>;
auto t = make_index_sequence<2000>();
Causes a segmentation fault.
Tested on Clang 3.5 and Clang 3.6 on x86_64 Linux.
The above code is from libstdc++ (which is why it contains underscored names)
with integer_sequence from C++14, but is compilable as C++11. The equivalent
code from libc++ does not trigger the template instantation depth problem.
brainfuck.cpp
(1382 bytes, text/x-c++src)clang++ dies with a segfault when decomposing template types nested deeper than the maximum template instantiation depth. A test program to trigger this is attached.