Summary: | [C++11] move constructor for stringstream | ||
---|---|---|---|
Product: | gcc | Reporter: | Johan Lundberg <lundberj> |
Component: | libstdc++ | Assignee: | Jonathan Wakely <redi> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | gcc, jaak |
Priority: | P3 | ||
Version: | 4.7.0 | ||
Target Milestone: | 5.0 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2014-05-16 00:00:00 | |
Bug Depends on: | 53626 | ||
Bug Blocks: |
Description
Johan Lundberg
2012-08-18 18:10:39 UTC
std::stringstream should be move constructable but there is no move constructor declared in include/std/sstream. This missing C++11 feature is dependent on basic_ios (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53626#add_comment) but additional work seem to be required for stringsteam and other dependent classes. The relevant standard section is 27.8.5 (Class template basic_stringstream). regards J. //Minimal example: #include <sstream> #include <utility> std::stringstream getss(){ std::stringstream q; return std::move(q); } compile_testtmp.cpp: In function ‘std::stringstream getss()’: compile_testtmp.cpp:7:22: error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’ In file included from compile_testtmp.cpp:2:0: /usr/include/c++/4.7/sstream:485:11: note: ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’ is implicitly deleted because the default definition would be ill-formed: /usr/include/c++/4.7/sstream:485:11: error: use of deleted function ‘std::basic_iostream<char>::basic_iostream(const std::basic_iostream<char>&)’ In file included from /usr/include/c++/4.7/sstream:39:0, from compile_testtmp.cpp:2: /usr/include/c++/4.7/istream:789:11: note: ‘std::basic_iostream<char>::basic_iostream(const std::basic_iostream<char>&)’ is implicitly deleted because the default definition would be ill-formed: /usr/include/c++/4.7/istream:789:11: error: use of deleted function ‘std::basic_istream<char>::basic_istream(const std::basic_istream<char>&)’ /usr/include/c++/4.7/istream:56:11: note: ‘std::basic_istream<char>::basic_istream(const std::basic_istream<char>&)’ is implicitly deleted because the default definition would be ill-formed: /usr/include/c++/4.7/istream:56:11: error: use of deleted function ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’ ... and further similar (~50 lines). Many C++11 bits having to do with iostream and even more those having to do with std::string are quite delicate in terms of ABI, thus the implementation is being delayed to when we globally break the ABI. It's known. (In reply to comment #2) > It's known. And documented http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011 Any progress? No, or this PR would have been updated. Can I offer technical assistance? That would be very welcome, thanks, Howard. We hope to complete the C++11 library for the next major release after 4.9, but there's still quite a lot to do. I haven't even analysed what we need to do to add move support to our streams (maybe Paolo has done). Here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1862.html#27.4.4%20-%20Class%20template%20basic_ios is a good list of what needs to be done. It is an old paper, so it needs to be cross-checked against N3936. But the differences (if any) should be few and minor. The changes in this part of the standard are confusing to understand, because of the use of virtual inheritance. However if one just blindly follows the recipe, backed up by a few unit tests, things will just work. The more difficult parts are the concrete streambufs: basic_filebuf and basic_streambuf. Once those are in place, the streams just fall into place with very little code. Author: redi Date: Mon Sep 22 13:34:09 2014 New Revision: 215463 URL: https://gcc.gnu.org/viewcvs?rev=215463&root=gcc&view=rev Log: Make streams movable and swappable. PR libstdc++/54316 PR libstdc++/53626 * config/abi/pre/gnu.ver: Add new exports. * config/io/basic_file_stdio.h (__basic_file): Support moving and swapping. * include/bits/basic_ios.h (basic_ios::move, basic_ios::swap): Likewise. * include/bits/ios_base.h (ios_base::_M_move, ios_base::_M_swap): Likewise. * include/bits/fstream.tcc (basic_filebuf): Likewise. * include/bits/move.h (__exchange): Define for C++11 mode. * include/ext/stdio_filebuf.h (stdio_filebuf): Support moving and swapping. * include/ext/stdio_sync_filebuf.h (stdio_sync_filebuf): Likewise. * include/std/fstream (basic_filebuf, basic_ifstream, basic_ofstream, basic_fstream): Likewise. * include/std/ios: Remove whitespace. * include/std/istream (basic_istream, basic_iostream): Support moving and swapping. * include/std/ostream (basic_ostream): Likewise. * include/std/sstream (basic_stringbuf, basic_istringstream, basic_ostringstream, basic_stringstream): Likewise. * include/std/streambuf (basic_streambuf): Do not default copy constructor and assignment on first declaration. * include/std/utility (exchange): Forward to __exchange. * testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc: New. * src/c++11/Makefile.am: Add stream-related files. * src/c++11/Makefile.in: Regenerate. * src/c++11/ext11-inst.cc (stdio_filebuf, stdio_sync_filebuf): New file for explicit instantiation definitions. * src/c++11/ios.cc: Move from src/c++98 to here. (ios_base::_M_move, ios_base::_M_swap): Define. * src/c++11/ios-inst.cc: Move from src/c++98 to here. * src/c++11/iostream-inst.cc: Likewise. * src/c++11/istream-inst.cc: Likewise. * src/c++11/ostream-inst.cc: Likewise. * src/c++11/sstream-inst.cc: Likewise. * src/c++11/streambuf-inst.cc: Likewise. * src/c++98/Makefile.am: Remove stream-related files. * src/c++98/Makefile.in: Regenerate. * src/c++98/ext-inst.cc (stdio_filebuf): Remove explicit instantiations. * src/c++98/misc-inst.cc (stdio_sync_filebuf): Likewise. * src/c++98/ios-inst.cc: Move to src/c++11/. * src/c++98/ios.cc: Move to src/c++11/. * src/c++98/iostream-inst.cc: Likewise. * src/c++98/istream-inst.cc: Likewise. * src/c++98/ostream-inst.cc: Likewise. * src/c++98/sstream-inst.cc: Likewise. * src/c++98/streambuf-inst.cc: Likewise. * testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc: New. * testsuite/27_io/basic_fstream/cons/move.cc: New. * testsuite/27_io/basic_fstream/assign/1.cc: New. * testsuite/27_io/basic_ifstream/cons/move.cc: New. * testsuite/27_io/basic_ifstream/assign/1.cc: New. * testsuite/27_io/basic_istringstream/assign/1.cc: New. * testsuite/27_io/basic_istringstream/cons/move.cc: New. * testsuite/27_io/basic_ofstream/cons/move.cc: New. * testsuite/27_io/basic_ofstream/assign/1.cc: New. * testsuite/27_io/basic_ostringstream/assign/1.cc: New. * testsuite/27_io/basic_ostringstream/cons/move.cc: New. * testsuite/27_io/basic_stringstream/assign/1.cc: New. * testsuite/27_io/basic_stringstream/cons/move.cc: New. Added: trunk/libstdc++-v3/src/c++11/ext11-inst.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/ios-inst.cc trunk/libstdc++-v3/src/c++11/ios-inst.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/ios-inst.cc trunk/libstdc++-v3/src/c++11/ios.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/ios.cc trunk/libstdc++-v3/src/c++11/iostream-inst.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/iostream-inst.cc trunk/libstdc++-v3/src/c++11/istream-inst.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/istream-inst.cc trunk/libstdc++-v3/src/c++11/ostream-inst.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/ostream-inst.cc trunk/libstdc++-v3/src/c++11/sstream-inst.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/sstream-inst.cc trunk/libstdc++-v3/src/c++11/streambuf-inst.cc - copied, changed from r215458, trunk/libstdc++-v3/src/c++98/streambuf-inst.cc trunk/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc trunk/libstdc++-v3/testsuite/27_io/basic_fstream/assign/ trunk/libstdc++-v3/testsuite/27_io/basic_fstream/assign/1.cc trunk/libstdc++-v3/testsuite/27_io/basic_fstream/cons/move.cc trunk/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/ trunk/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc trunk/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc trunk/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/ trunk/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/1.cc trunk/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/move.cc trunk/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/ trunk/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc trunk/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/move.cc trunk/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/ trunk/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/1.cc trunk/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/move.cc trunk/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/ trunk/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc trunk/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/move.cc Removed: trunk/libstdc++-v3/src/c++98/ios-inst.cc trunk/libstdc++-v3/src/c++98/ios.cc trunk/libstdc++-v3/src/c++98/iostream-inst.cc trunk/libstdc++-v3/src/c++98/istream-inst.cc trunk/libstdc++-v3/src/c++98/ostream-inst.cc trunk/libstdc++-v3/src/c++98/sstream-inst.cc trunk/libstdc++-v3/src/c++98/streambuf-inst.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/config/abi/pre/gnu.ver trunk/libstdc++-v3/config/io/basic_file_stdio.h trunk/libstdc++-v3/include/bits/basic_ios.h trunk/libstdc++-v3/include/bits/fstream.tcc trunk/libstdc++-v3/include/bits/ios_base.h trunk/libstdc++-v3/include/bits/move.h trunk/libstdc++-v3/include/ext/stdio_filebuf.h trunk/libstdc++-v3/include/ext/stdio_sync_filebuf.h trunk/libstdc++-v3/include/std/fstream trunk/libstdc++-v3/include/std/ios trunk/libstdc++-v3/include/std/istream trunk/libstdc++-v3/include/std/ostream trunk/libstdc++-v3/include/std/sstream trunk/libstdc++-v3/include/std/streambuf trunk/libstdc++-v3/include/std/utility trunk/libstdc++-v3/src/c++11/Makefile.am trunk/libstdc++-v3/src/c++11/Makefile.in trunk/libstdc++-v3/src/c++98/Makefile.am trunk/libstdc++-v3/src/c++98/Makefile.in trunk/libstdc++-v3/src/c++98/ext-inst.cc trunk/libstdc++-v3/src/c++98/misc-inst.cc Fixed for GCC 5 *** Bug 78423 has been marked as a duplicate of this bug. *** |