1 // RUN: %clang_cc1 -verify %s -DTEST=1 2 // RUN: %clang_cc1 -verify %s -DTEST=2 3 // RUN: %clang_cc1 -verify %s -DTEST=3 4 // REQUIRES: thread_support 5 6 // FIXME: Detection of, or recovery from, stack exhaustion does not work on 7 // NetBSD at the moment. Since this is a best-effort mitigation for exceeding 8 // implementation limits, just disable the test. 9 // UNSUPPORTED: system-netbsd 10 11 // asan has own stack-overflow check. 12 // UNSUPPORTED: asan 13 14 // expected-warning@* 0-1{{stack nearly exhausted}} 15 // expected-note@* 0+{{}} 16 17 #if TEST == 1 18 19 template<int N> struct X : X<N-1> {}; 20 template<> struct X<0> {}; 21 X<1000> x; 22 23 template<typename ...T> struct tuple {}; 24 template<typename ...T> auto f(tuple<T...> t) -> decltype(f(tuple<T...>(t))) {} // expected-error {{exceeded maximum depth}} 25 void g() { f(tuple<int, int>()); } 26 27 int f(X<0>); 28 template<int N> auto f(X<N>) -> f(X<N-1>()); 29 30 int k = f(X<1000>()); 31 32 #elif TEST == 2 33 34 namespace template_argument_recursion { 35 struct ostream; 36 template<typename T> T &&declval(); 37 38 namespace mlir { 39 template<typename T, typename = decltype(declval<ostream&>() << declval<T&>())> 40 ostream &operator<<(ostream& os, const T& obj); // expected-error {{exceeded maximum depth}} 41 struct Value; 42 } 43 44 void printFunctionalType(ostream &os, mlir::Value &v) { os << v; } 45 } 46 47 #elif TEST == 3 48 49 namespace template_parameter_type_recursion { 50 struct ostream; 51 template<typename T> T &&declval(); 52 template<bool B, typename T> struct enable_if { using type = T; }; 53 54 namespace mlir { 55 template<typename T, typename enable_if<declval<ostream&>() << declval<T&>(), void*>::type = nullptr> 56 ostream &operator<<(ostream& os, const T& obj); // expected-error {{exceeded maximum depth}} 57 struct Value; 58 } 59 60 void printFunctionalType(ostream &os, mlir::Value &v) { os << v; } 61 } 62 63 #else 64 #error unknown test 65 #endif 66