小编Coc*_*coa的帖子

为什么无法形成对“decltype(auto)”的引用

int main(){\n    decltype(auto)&& a = 100;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

上面的代码,在GCC和Clang中出错。

\n\n
int main(){\n    decltype(int)&& a = 100;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这段代码正确。

\n\n

在N4296中,

\n\n

在\xc2\xa7 8.3.2/6

\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
\n\n

\xc2\xa7 中的decltype 说明符7.1.6.2

\n\n
\n

decltype 说明符:
\n \xe3\x80\x80\xe3\x80\x80decltype ( 表达式 )
\n \xe3\x80\x80\xe3\x80\x80decltype ( auto )

\n
\n\n

我认为\xc2\xa7 8.3.2/6的写法有问题。

\n\n

为什么不允许引用 …

c++ decltype c++14

5
推荐指数
1
解决办法
605
查看次数

可以memcpy为std :: aligned_storage吗?

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)

c++ memcpy object-lifetime c++14

5
推荐指数
1
解决办法
495
查看次数

标签 统计

c++ ×2

c++14 ×2

decltype ×1

memcpy ×1

object-lifetime ×1