Consider the following program:
#include <iostream>
template<typename... Params_t>
constexpr int constexprValue(Params_t...) { return 5; }
int main()
{
const bool flag = true;
if constexpr(flag)
{
constexpr int value = constexprValue(1, 2, 3);
std::cout << value << "\n";
}
}
This compiles and works fine. However, if flag
is changed to false
, then clang (Apple LLVM version 10.0.0 (clang-1000.10.44.4)) gives a compiler error:
error: constexpr variable 'value' must be initialized by a constant expression
undefined function 'constexprValue<int, int, int>' cannot be used in a constant expression
Is this a bug in clang?