Index: test/SemaTemplate/recursive-template-factorial.cpp
===================================================================
--- test/SemaTemplate/recursive-template-factorial.cpp	(revision 0)
+++ test/SemaTemplate/recursive-template-factorial.cpp	(working copy)
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -ftemplate-depth 256 -ftemplate-backtrace-limit 10 -fsyntax-only -verify %s
+
+// Ensure that the compiler itself does not run out of stack space when parsing 
+// recursive templates.
+template <int N> struct Factorial {
+  enum {
+    value = N * Factorial<N - 1>::value // expected-error {{exceeded maximum depth}} \
+                                        // expected-note 9 {{instantiation of template class}} \
+                                        // expected-note {{contexts in backtrace}} \
+                                        // expected-note {{use -ftemplate-depth=N}}
+  };
+};
+
+template <> struct Factorial<0> {
+  enum {
+    value = 1
+  };
+};
+
+Factorial<256> f256;
+Factorial<2048> f2048; // expected-note{{instantiation of template class}}
