[Bug c++/87663] Exorbitant compile times

lumosimann at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Oct 26 21:09:00 GMT 2018


--- Comment #4 from Lukas Mosimann <lumosimann at gmail dot com> ---
Okay one last comment from my side (sorry for this two updates in short
intervals). I tried to further simplify it, and I came up with this code which
I think has the same problem.

template <typename T, T v>
struct integral_constant {
    static constexpr T value = v;
    using value_type = int; // remove this line

template <int X, int A>
struct F : integral_constant<int, F<X + (1 << A), A - 1>::value -
                                      F<X, A - 1>::value> {};

template <int X>
struct F<X, 0> : integral_constant<int, X> {};

int main() {
    F<0, 15>::value;
    return 0;

`integral_constant` with `value_type` compiles in 32 seconds on my machine.

`integral_constant` without `value_type` compiles in 1.6 seconds.

So we are talking about an 20x increase in compilation time. Things get worse
with larger N, e.g. `F<0, 16>`: 3.5 s vs. 167 s (48x increase).

More information about the Gcc-bugs mailing list