[英]why doesn't c++ uses RVO when returning local std::stringstream?
我已經閱讀了很多關於rvalue和在C ++中返回局部變量的信息> = 11.據我所知,“只是按值返回,不要使用move / forward而不添加&&方法簽名,編譯器會優化它適合你“。
好的,我希望它發生:
#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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.