According to the standard
27.9.1.11 basic_ofstream constructors
or, its more “readable” version http://en.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream , std::basic_ostream<>
has a move constructor, so the code should compile.
clang++ 3.5 compiles it with -std=c++11
or -std=c++1y
. Also gcc5 compiles it, so probably it is not implemented in libstdc++ for gcc < 5
Interestingly, the lack of move semantics is not mentioned on gcc’s stdlibc++ implementation https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2014
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316 for a bug report, thanks to @BoBTFish for pointing out. It is confirmed that the issue was fixed in gcc5.