对于由于成员字段的初始值设定项无效而不允许创建对象的聚合类型,std::is_constructible
应返回什么?
举个例子
#include <type_traits> template <class T> struct A { T x{}; }; static_assert( !std::is_constructible_v<A<int&>> );
A<int&> obj;
格式不正确,因为它无法从{}
初始化int&
。因此,我希望上面的示例程序能够像GCC中那样编译得很好。但MSVC接受相反的static_assert( std::is_constructible_v<A<int&>> );
语句,因为A
的默认构造函数没有被正式删除。Clang以第三种方式停止编译并返回错误:
error: non-const lvalue reference to type 'int' cannot bind to an initializer list temporary T x{}; ^~ : note: in instantiation of default member initializer 'A<int &>::x' requested here struct A { ^
在线演示:https://gcc.godbolt.org/z/nnxcGn7WG
根据标准,哪一种行为是正确的?