@@ -4,3 +4,47 @@ struct HasTypeWithSelfAsParam {
44};
55
66using WillBeInfinite = HasTypeWithSelfAsParam<int >;
7+
8+ namespace RegressionTest {
9+
10+ // This is a regression test to check that we don't instantiate exponentially
11+ // large templates. The below template will instantiate hundreds of thousands
12+ // (or more) of specializations before hitting the 8-template-param-deep limit.
13+ template <class E , int >
14+ struct SliceExpr {
15+ using type = typename E::type;
16+ E expr;
17+
18+ typename E::type* test () { return nullptr ; }
19+ };
20+
21+ template <class T >
22+ struct Array {
23+ using type = T;
24+ };
25+
26+ template <class E >
27+ struct ValExpr {
28+ using type = typename E::type;
29+ E expr;
30+
31+ ValExpr<SliceExpr<E, 1 >> test1 () { return {SliceExpr<E, 1 >{expr}}; }
32+ ValExpr<SliceExpr<E, 2 >> test2 () { return {SliceExpr<E, 2 >{expr}}; }
33+ ValExpr<SliceExpr<E, 3 >> test3 () { return {SliceExpr<E, 3 >{expr}}; }
34+ ValExpr<SliceExpr<E, 4 >> test4 () { return {SliceExpr<E, 4 >{expr}}; }
35+ ValExpr<SliceExpr<E, 5 >> test5 () { return {SliceExpr<E, 5 >{expr}}; }
36+ ValExpr<SliceExpr<E, 6 >> test6 () { return {SliceExpr<E, 6 >{expr}}; }
37+ ValExpr<SliceExpr<E, 7 >> test7 () { return {SliceExpr<E, 7 >{expr}}; }
38+ ValExpr<SliceExpr<E, 8 >> test8 () { return {SliceExpr<E, 8 >{expr}}; }
39+ ValExpr<SliceExpr<E, 9 >> test9 () { return {SliceExpr<E, 8 >{expr}}; }
40+ ValExpr<SliceExpr<E, 11 >> test11 () { return {SliceExpr<E, 11 >{expr}}; }
41+ ValExpr<SliceExpr<E, 12 >> test12 () { return {SliceExpr<E, 12 >{expr}}; }
42+ };
43+
44+ // This class template is exponentially slow to *fully* instantiate (and the
45+ // exponent is the number of testX methods). Make sure that we can still
46+ // partially import it without importing all of its child template
47+ // instantiations.
48+ void user (ValExpr<Array<int >> *) { }
49+
50+ } // end namespace 'RegressionTest'
0 commit comments