I had tried to compile code like template<int dim> class cls { cls<dim-1> c[16]; }; template<> class cls<0> { }; int main() { cls<200> c; return 0; } and had error: g++: Internal error: Segmentation fault (program cc1plus) Please submit a full bug report. See <URL:http://gcc.gnu.org/bugs.html> for instructions. I think, in this case better output maybe something like "no enough memory", "unable to compile" etc. Information as defined in http://gcc.gnu.org/bugs.html - the options given when GCC was configured/built --prefix=/usr --libexecdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++ - the complete command line that triggers the bug g++ bug.cpp - the compiler output (error messages, warnings, etc.) g++: Internal error: Segmentation fault (program cc1plus) Please submit a full bug report. See <URL:http://gcc.gnu.org/bugs.html> for instructions. - the preprocessed file (*.i*) that triggers the bug, generated by adding -save-temps to the complete compilation command, or, in the case of a bug report for the GNAT front end, a complete set of source files (see below) Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.3/specs Configured with: ../gcc-3.4.3/configure --prefix=/usr --libexecdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++ Thread model: posix gcc version 3.4.3 /usr/lib/gcc/i686-pc-linux-gnu/3.4.3/cc1plus -E -quiet -v -D_GNU_SOURCE bug.cpp -mtune=pentiumpro ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3 /usr/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/i686-pc-linux-gnu /usr/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/backward /usr/local/include /usr/lib/gcc/i686-pc-linux-gnu/3.4.3/include /usr/include End of search list. # 1 "bug.cpp" # 1 "<built-in>" # 1 "<command line>" # 1 "bug.cpp" template<int dim> class cls { cls<dim-1> c[16]; }; template<> class cls<0> { }; int main() { cls<200> c; return 0; }
Ahh, exploding recursive templates... For future reference, you could limit the recursion depth explicitly, using -ftemplate-depth-n from a gcc-3.4.0 man page: Set the maximum instantiation depth for template classes to n. A limit on the template instantiation depth is needed to detect endless recursions during template class instantiation. ANSI/ISO C++ conforming programs must not rely on a maximum depth greater than 17. I think 42 would seem more appropriate than 17, but that is for The Committee to decide. :)
note the size of class cls grows exponentially with its template parameter.