On the following example, gcc seems to loop and starts filling the ram after reporting the errors. Same issue on x86_64-linux-gnu or with older 4.x versions.
~/tmp$ cat test2.cpp class a { template<unsigned int s> struct _rec { static const char size = _rec< (s >> 1) >::size; }; template<> struct _rec <0> { static const char size = 0; }; static const unsigned int value = _rec < 1 >::size; } ~/tmp$ g++-4.3 -v -ftemplate-depth-4 test2.cpp Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.3-5' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.3.3 (Debian 4.3.3-5) COLLECT_GCC_OPTIONS='-v' '-ftemplate-depth-4' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/i486-linux-gnu/4.3.3/cc1plus -quiet -v -D_GNU_SOURCE test2.cpp -quiet -dumpbase test2.cpp -mtune=generic -auxbase test2 -version -ftemplate-depth-4 -o /tmp/ccZ7Hrtb.s ignoring nonexistent directory "/usr/local/include/i486-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../i486-linux-gnu/include" ignoring nonexistent directory "/usr/include/i486-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.3 /usr/include/c++/4.3/i486-linux-gnu /usr/include/c++/4.3/backward /usr/local/include /usr/lib/gcc/i486-linux-gnu/4.3.3/include /usr/lib/gcc/i486-linux-gnu/4.3.3/include-fixed /usr/include End of search list. GNU C++ (Debian 4.3.3-5) version 4.3.3 (i486-linux-gnu) compiled by GNU C version 4.3.3, GMP version 4.2.4, MPFR version 2.4.0-p2. GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64543 Compiler executable checksum: 6dda33bccb1e3fda2076fc047c4bfa75 test2.cpp:8: error: explicit specialization in non-namespace scope ‘class a’ test2.cpp:5: error: template instantiation depth exceeds maximum of 4 (use -ftemplate-depth-NN to increase the maximum) instantiating ‘a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<1u>::size’ test2.cpp:13: instantiated from here test2.cpp:5: error: template instantiation depth exceeds maximum of 4 (use -ftemplate-depth-NN to increase the maximum) instantiating ‘a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<1u>::size’ test2.cpp:13: instantiated from here test2.cpp:5: error: template instantiation depth exceeds maximum of 4 (use -ftemplate-depth-NN to increase the maximum) instantiating ‘a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<1u>::size’ test2.cpp:13: instantiated from here test2.cpp:5: error: ‘a::_rec<0u>::size’ cannot be initialized by a non-constant expression when being declared test2.cpp:5: error: template instantiation depth exceeds maximum of 4 (use -ftemplate-depth-NN to increase the maximum) instantiating ‘a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<1u>::size’ test2.cpp:13: instantiated from here test2.cpp:5: error: template instantiation depth exceeds maximum of 4 (use -ftemplate-depth-NN to increase the maximum) instantiating ‘a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<0u>::size’ test2.cpp:5: instantiated from ‘const char a::_rec<1u>::size’ test2.cpp:13: instantiated from here ^C (exit 130) -- Summary: gcc loops after reporting template instantiation errors Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mm at mezzarobba dot net GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39425