http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16564
--- Comment #19 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- (In reply to Volker Reichelt from comment #18) > The first error message about exceeding the maximum template instantiation > depth appears rather quickly. So maybe we could make the first error message > a fatal one to avoid further processing of potentially bogus nested classes. It seems to me GCC is doing something strange. See comment #14. But what you suggest seems to be what Clang++ is doing: $ /usr/bin/time clang++ test.cc test.cc:3:8: fatal error: recursive template instantiation exceeded maximum depth of 256 A<A> a; ^ test.cc:3:8: note: in instantiation of template class '...' requested here A<A> a; ^ test.cc:3:8: note: in instantiation of template class '...' requested here A<A> a; ^ test.cc:3:8: note: in instantiation of template class '...' requested here A<A> a; ^ test.cc:3:8: note: in instantiation of template class '...' requested here A<A> a; ^ test.cc:3:8: note: in instantiation of template class '...' requested here A<A> a; ^ test.cc:3:8: note: (skipping 247 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all) test.cc:3:8: note: in instantiation of template class 'A<A<A<A<A<int> > > > >' requested here A<A> a; ^ test.cc:3:8: note: in instantiation of template class 'A<A<A<A<int> > > >' requested here A<A> a; ^ test.cc:3:8: note: in instantiation of template class 'A<A<A<int> > >' requested here A<A> a; ^ test.cc:3:8: note: in instantiation of template class 'A<A<int> >' requested here A<A> a; ^ test.cc:7:8: note: in instantiation of template class 'A<int>' requested here A<int> a; ^ test.cc:3:8: note: use -ftemplate-depth=N to increase recursive template instantiation depth A<A> a; ^ 1 error generated. Command exited with non-zero status 1 0.11user 0.02system 0:00.14elapsed 96%CPU (0avgtext+0avgdata 67904maxresident)k 0inputs+0outputs (0major+6524minor)pagefaults 0swaps And GCC's output in recent versions would look better than this because it has automatic recursion detection: test.cc:3:8: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) instantiating ‘struct ...’ A<A> a; ^ test.cc:3:8: recursively required from ‘struct A<A<int> >’ test.cc:3:8: required from ‘struct A<int>’ test.cc:7:8: required from here