考虑以下示例:
template <typename T>
using type = typename T::type;
template <typename T>
struct A
{
A(type<T>);
};
A<int> f();
A<int> g() { return f(); }
由于int
没有嵌套的type
typedef,所以既不gcc也不clang编译此代码。但是为什么会实例化构造函数呢?f()
是与g()
返回类型相同的prvalue,甚至不应该有移动操作。是什么导致我们实例化了错误的构造函数?