https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62266
Bug ID: 62266 Summary: Loop unrolling with template metaprogramming not aggressive enough Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cand at gmx dot com The following code fails to compile with all GCC versions I have, up to g++ (GCC) 5.0.0 20140817 (experimental). It also fails with clang, but it would be nice for this to work, as it would save some writing. The index i is in constant bounds, and so the compiler should be able to fully unroll this loop into "foo<0>(); foo<1>(); foo<2>();". #include <stdio.h> template <int T> void foo() { printf("%u\n", T); } int main() { int i; for (i = 0; i < 3; i++) { foo<i>(); } return 0; }