为什么 c++ 在返回本地 std::stringstream 时不使用 RVO?

why doesn't c++ uses RVO when returning local std::stringstream?

我在 C++ >= 11 中阅读了很多关于右值和返回局部变量的信息。据我了解,"just return by value, do not use move/forward and do not add && to method signature and the compiler will optimize it for you".

好的,我希望它发生:

#include <sstream>

std::stringstream GetStream() {
    std::stringstream s("test");
    return s;
}

auto main() -> int {
    auto s = GetStream();
}

我觉得不错

error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
     return s;

错误。我不明白,为什么它会尝试复制构造函数?它不是在这里使用移动构造函数和 c++11 中的所有好东西吗? 我使用“--std=c++14”。

好的,这是我的 gcc (4.9.3) 版本中的一个错误。似乎固定在 >= 5 中。 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316