Recursive computation using variable templates - gcc vs clang
问题 Consider the following example: #include <cstdio> template <int N> int fib = fib<N - 1> + fib<N - 2>; template <> int fib<2> = 1; template <> int fib<1> = 1; int main() { std::printf("%d %d %d", fib<4>, fib<5>, fib<6>); } GCC 7.x, 8.x, 9.x, and 10.x all print out the expected result of 3 5 8 . Clang 5.x, 6.x, 7.x, 8.x, 9.x, and 10.x all print out 1 3 4 as a result. live example on godbolt.org Clang's behavior is surprising. Is there any subtle interaction between variable template