https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127868
Bug ID: 127868
Summary: Unbounded template recursion in C++ frontend causing
SIGTERM
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: daniel-dev at hotmail dot de
Target Milestone: ---
# Test Case
template<typename...> struct S;
template<typename T, int N> struct R : R<typename R<T, N-1>::type, 2> {};
template<typename ...T> struct R<S<T...>, 1> { typedef S<T..., T...> type; };
using Foo = R<S<int>, 2>::type;
# Environment
- GCC version: gcc 16.2.1 20260810 (GCC)
- System type: x86_64-pc-linux-gnu (Linux)
- Configured with: as shown in g++ -v output (Arch Linux packaging build with
bootstrap-lto, etc.)
# Reproduction
- Command line: g++ -c test.cpp (or g++ -fsyntax-only test.cpp)
- Behavior: Compilation does not terminate in reasonable time; cc1plus is
eventually killed (OOM/SIGTERM). With default settings, no diagnostic message
is emitted before termination. Increasing -ftemplate-depth only delays
termination and ultimately results in the same resource exhaustion.
- Compiler output: g++: fatal error: Killed signal terminated program cc1plus
(when killed)
Crash also in current gcc trunk: https://godbolt.org/z/bTnd17W3K
The same bug already exists in clang:
https://github.com/llvm/llvm-project/issues/231090