https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91990
Bug ID: 91990 Summary: Too slow compilation of recursively-nested template class with two instances of its template parent Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: b7.10110111 at gmail dot com Target Milestone: --- Consider the following code: ``` template<int i> class A { typedef A<i-1> B; B x, y; }; template<> class A<0> { char m; }; int main() { A<LEVEL> a; } ``` Depending on the value of `LEVEL`, g++ compilation takes exponential time. But if you replace `x, y` with `x[2]`, compilation will be in constant (negligibly small) time. I've tested this on g++ 6.5.0, 8.3.0 and 9.1.0, and in all these versions the problem of slow compilation reproduces. For comparison, clang++ 6.0 compiles both versions (with `x, y` and `x[2]`) in negligibly small time regardless of `LEVEL` (tested up to `LEVEL=906`, on 907 it crashes).