A simple test to make sure your constexpr actually executed at compile time is to use std::array :
#include <array> std::array<int, Fibonacci<5>::value> arr; std::array<int, fib(5)> arr2;
gcc has no complaints .
See this comment by Bjarne Straustrup :
... according to the standard, the constexpr function can be evaluated at compiler time or run time if it is not used as a constant expression, in which case it must be evaluated at compile time. To guarantee compilation time, we must either use it where a constant expression is required (for example, as associated with an array or as a case label) or use it to initialize constexpr. I hope that no self-respecting compiler misses the optimization opportunity to do what I originally said: "The constexpr function is evaluated at compile time if all its arguments are constant expressions."
user1508519
source share