相关疑难解决方法(0)

在保证副本省略的世界中的构造函数实例化

考虑这个例子:

template <typename T>
using type = typename T::type;

template <typename T>
struct A
{
    A(type<T>);
};

A<int> f();
A<int> g() { return f(); }
Run Code Online (Sandbox Code Playgroud)

由于int没有嵌套的typetypedef,gcc和clang都没有编译这段代码.但是为什么构造函数会被实例化呢?f()是一个与返回相同类型的prvalue,g()甚至不应该在那里移动.是什么导致我们实例化坏构造函数?

c++ templates c++17

6
推荐指数
1
解决办法
165
查看次数

标签 统计

c++ ×1

c++17 ×1

templates ×1