我正在学习decltype(auto)
非类型模板参数的 C++17 新特性。我写了一个简单的代码片段如下:
#include <type_traits>
template<decltype(auto) arg>
struct Foo {};
int
main()
{
constexpr int x = 42;
static_assert(std::is_same_v<Foo<42>, Foo<x>>);
}
据我了解,Foo<42>
应该与Foo<x>
.
但是,该static_assert
语句使用 clang++、MSVC 19.27 编译,但使用 GCC 10.2、MSVC 19.25 编译失败。
我的问题是:为什么编译器的行为不同?标准对此有何评论?
链接到编译器资源管理器:
铿锵++ https://godbolt.org/z/66M695
gcc https://godbolt.org/z/3v5Mhd
MSVC 19.25 https://godbolt.org/z/qP6v89
MSVC 19.27 https://godbolt.org/z/14aK5Y