int main(){\n decltype(auto)&& a = 100;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n上面的代码,在GCC和Clang中出错。
\n\nint main(){\n decltype(int)&& a = 100;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这段代码正确。
\n\n在N4296中,
\n\n在\xc2\xa7 8.3.2/6
\n\n\n\n\n如果 typedef (7.1.3)、类型模板参数 (14.3.1) 或 decltype-specifier (7.1.6.2) 表示类型 TR\n 是对类型 T 的引用,则尝试创建type \xe2\x80\x9clvalue 对 cv TR\xe2\x80\x9d 的引用创建类型\n \xe2\x80\x9clvalue 对 T\xe2\x80\x9d 的引用,而尝试创建类型 \xe2\x80\ x9crvalue 对 cv TR\xe2\x80\x9d 的引用创建类型 TR。
\n
\xc2\xa7 中的decltype 说明符7.1.6.2
\n\n\n\n\ndecltype 说明符:
\n
\n \xe3\x80\x80\xe3\x80\x80decltype ( 表达式 )
\n \xe3\x80\x80\xe3\x80\x80decltype ( auto )
我认为\xc2\xa7 8.3.2/6的写法有问题。
\n\n为什么不允许引用 …
std :: aligned_storage :: type是POD类型.POD类型可以memcpy.但是,如果将新的非平凡可复制类型放置到std :: aligned_storage会发生什么?它能记得那个std :: aligned_storage吗?
非平凡可复制类型(非POD类型)不能memcpy,行为未定义.如果std :: aligned_storage memcpy是非平凡可复制的类型,它是否也是未定义的行为?
#include <new>
#include <type_traits>
#include <cstring>
#include <iostream>
struct y { int a; } ;
// non-trivially-copyable
struct t
{
y a;
int* p;
t(){ p = new int{ 300 }; }
t( t const& ){ a.a += 100; }
~t(){ delete p; }
};
int main()
{ // Block 1
{
t a; a.a.a = 100;
t b; b.a.a = 200;
// std::memcpy(&b,&a,sizeof(t)); // abort...non-trivially-copyable
} …Run Code Online (Sandbox Code Playgroud)