请考虑以下代码:
template <int* > struct foo { };
int main() {
foo<(int*)42> f;
(void)f;
}
Run Code Online (Sandbox Code Playgroud)
当用-std=c++11
or 编译clang 3.8.0时-std=c++14
,程序编译.在编译时-std=c++1z
,它会出错:
main.cpp:4:9: error: non-type template argument is not a constant expression
foo<(int*)42> f;
^~~~~~~~
Run Code Online (Sandbox Code Playgroud)
无论C++模式如何,gcc 5.3.0都不编译代码,我认为这是正确的.C++ 14和C++ 1z之间的clang有什么区别?为什么它接受代码?C++ 1z中有什么变化与此相关吗?