以下程序在GCC 5.2下可以编译,但在clang 3.6下无法编译:
constexpr bool flag();
template <bool b = flag()>
constexpr bool test()
{
return b;
}
int main()
{
}
我在使用clang时收到的错误信息是:
main.cpp:3:20: error: non-type template argument is not a constant expression
template <bool b = flag()>
^~~~~~
main.cpp:3:20: note: undefined function 'flag' cannot be used in a constant expression
main.cpp:1:16: note: declared here
constexpr bool flag();
^
main.cpp:4:16: error: no return statement in constexpr function
constexpr bool test()
^
我的问题是:谁是正确的?换句话说,这个程序是否格式不正确?