为什么我不能通过值将rvalue std :: stringstream传递给函数?

uk4*_*321 4 c++ rvalue move-semantics c++11

为什么这段代码不能编译?

#include <sstream>

void f(std::stringstream) { }

int main() {
    f(std::stringstream{});
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
         f(std::stringstream{});
                              ^
Run Code Online (Sandbox Code Playgroud)

如果我std::stringstream用另一种不可复制的类型替换它可以正常工作.不应该使用stringstream移动构造函数吗?

小智 7

缺少的移动构造函数stringstream是GCC实现C++标准库时已知的缺失特性.如果我正确地阅读该报告的评论,它会故意丢失,因为它会依赖于其他变化,而那些其他变化会破坏ABI,因此GCC人员选择仅打破ABI一次(如果可能),那个时候还没来.