考虑以下程序:
#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";
}
}
这可以编译并正常工作。但是,如果flag
改为false
,则 clang (Apple LLVM version 10.0.0 (clang-1000.10.44.4)) 给出编译器错误:
error: constexpr variable 'value' must be initialized by a constant expression
undefined function 'constexprValue<int, int, int>' cannot be used in a constant expression
这是clang中的错误吗?