I've read lots of info about rvalue and returning local variables in C++ >= 11. From what I understood is that "just return by value, do not use move/forward and do not add && to method signature and the compiler will optimize it for you".
Okay, I want it happen:
#include <sstream>
std::stringstream GetStream() {
std::stringstream s("test");
return s;
}
auto main() -> int {
auto s = GetStream();
}
I get the nice
error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
return s;
error. I don't get it, why it tries the copy constructor? Shan't it use move constructor with all the nice things from c++11 here? I use "--std=c++14".
okay, this is a bug in my version of gcc (4.9.3). appears to be fixed in >= 5. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With