===================================================================
@@ -8905,8 +8911,15 @@ instantiate_class_template_1 (tree type)
gcc_assert (TREE_CODE (templ) == TEMPLATE_DECL);
/* Determine what specialization of the original template to
- instantiate. */
- t = most_specialized_class (type, tf_warning_or_error);
+ instantiate. Note: protect vs too deep instantiation. */
+ if (push_tinst_level (type))
+ {
+ t = most_specialized_class (type, tf_warning_or_error);
+ pop_tinst_level ();
+ }
+ else
+ t = error_mark_node;
+
if (t == error_mark_node)
{
TYPE_BEING_DEFINED (type) = 1;
===================================================================
@@ -0,0 +1,25 @@
+// PR c++/58059
+// { dg-do compile { target c++11 } }
+
+template<bool, typename T = void> struct enable_if { typedef T type; };
+template<typename T> struct enable_if<false, T> { };
+
+// This code is nonsense; it was produced by minimizing the problem repeatedly.
+constexpr bool test_func(int value) {
+ return true;
+}
+template <int TParm, class Enable=void>
+struct test_class {
+ static constexpr int value = 0;
+};
+template <int TParm>
+struct test_class<
+ TParm,
+ // This line ultimately causes the crash.
+ typename enable_if<test_func(test_class<TParm-1>::value)>::type // { dg-error "depth exceeds" }
+ > {
+ static constexpr int value = 1;
+};
+
+// This instantiation is required in order to crash.
+template class test_class<2,void>;
===================================================================
@@ -5,9 +5,7 @@ template <int I> struct F
{
int operator()()
{
- F<I+1> f; // { dg-error "incomplete type" "incomplete" }
- // { dg-bogus "exceeds maximum.*exceeds maximum" "exceeds" { xfail *-*-* } 8 }
- // { dg-error "exceeds maximum" "exceeds" { xfail *-*-* } 8 }
+ F<I+1> f; // { dg-error "depth exceeds|incomplete" }
return f()*I; // { dg-message "recursively" "recurse" }
}
};
===================================================================
@@ -0,0 +1,5 @@
+// PR c++/51488
+
+template<class T,class U=void> struct s;
+template<class T> struct s<T,typename s<T>::a> {};
+s<int> ca; // { dg-error "depth exceeds|incomplete" }