https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119094

            Bug ID: 119094
           Summary: gcc uses all memory in recursive calls with
                    increasingly complex templates
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sandberg.sven at gmail dot com
  Target Milestone: ---

The following program makes gcc use more and more memory until the system
imposes a limit (or crashes) (https://godbolt.org/z/WzdGMfc1s). (Warning: be
prepared to kill the compiler before the machine becomes unusable!)

```
template <class T, class U>
struct C {};

template <class T>
void explode() {
    explode<C<T, T>>();
}

int main() {
    explode<int>();
}
```

This may kill compile servers that don't have explicit guards against time or
memory over-use.

Other similar cases are guarded by -ftemplate-depth, but in this case the
template definition grows exponentially in the depth, so even small values for
the limit are ineffective in practice.

It would be better if there was a limit on the amount of memory used, or maybe
on the total size of a template, rather than just the depth.

clang seems to have the same problem.
  • [Bug c++/119094] New: gcc uses... sandberg.sven at gmail dot com via Gcc-bugs

Reply via email to