diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-09-22 13:34:09 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-09-22 13:34:09 +0000 |
commit | 28f8cba268ceb976aa8ce17bd3177d990e8c85d2 (patch) | |
tree | 56471caae5e872ad7a27f4e39b5f246f4a5245c8 /libstdc++-v3 | |
parent | 3979f78787bdc6db3e1679b6015a1a403bb097ba (diff) | |
download | gcc-28f8cba268ceb976aa8ce17bd3177d990e8c85d2.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@215463 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
43 files changed, 1888 insertions, 70 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7682e279876..04749d772b0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,69 @@ +2014-09-19 Jonathan Wakely <jwakely@redhat.com> + + 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. + 2014-09-17 Jason Merrill <jason@redhat.com> * libsupc++/dyncast.cc (__dynamic_cast): Handle mid-destruction diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 41fac71adaf..669e36d7ece 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -989,7 +989,8 @@ GLIBCXX_3.4.10 { _ZNSt15basic_streambufI[cw]St11char_traitsI[cw]EE6stosscEv; _ZN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EE4syncEv; - _ZN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EE[5-9C]*; + _ZN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EE[5-9]*; + _ZN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EEC[12]EP*; _ZN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EED[^2]*; } GLIBCXX_3.4.9; @@ -1375,6 +1376,47 @@ GLIBCXX_3.4.21 { # void std::thread::_M_start_thread(__shared_base_type, void(*)()) _ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFvvE; + # Move/swap functions for iostreams + _ZNSt8ios_base7_M_swapERS_; + _ZNSt8ios_base7_M_moveERS_; + _ZNSt9basic_iosI[cw]St11char_traitsI[cw]EE4moveE[OR]S2_; + _ZNSt9basic_iosI[cw]St11char_traitsI[cw]EE4swapERS2_; + _ZNSt9basic_iosI[cw]St11char_traitsI[cw]EE9set_rdbuf*; + _ZNSt15basic_streambufI[cw]St11char_traitsI[cw]EE4swapERS2_; + _ZNS[dio]4swapERS[dio]; + _ZNS[dio]aSEOS[dio]; + _ZNS[dio]C[12]EOS[dio]; + _ZNSt13basic_[io]streamIwSt11char_traitsIwEE4swapERS2_; + _ZNSt13basic_[io]streamIwSt11char_traitsIwEEaSEOS2_; + _ZNSt13basic_[io]streamIwSt11char_traitsIwEEC[12]EOS2_; + _ZNSt14basic_iostreamIwSt11char_traitsIwEE4swapERS2_; + _ZNSt14basic_iostreamIwSt11char_traitsIwEEaSEOS2_; + _ZNSt14basic_iostreamIwSt11char_traitsIwEEC[12]EOS2_; + _ZNSt13basic_filebufI[cw]St11char_traitsI[cw]EE4swapERS2_; + _ZNSt13basic_filebufI[cw]St11char_traitsI[cw]EEaSEOS2_; + _ZNSt13basic_filebufI[cw]St11char_traitsI[cw]EEC[12]EOS2_; + _ZNSt13basic_fstreamI[cw]St11char_traitsI[cw]EE4swapERS2_; + _ZNSt13basic_fstreamI[cw]St11char_traitsI[cw]EEaSEOS2_; + _ZNSt13basic_fstreamI[cw]St11char_traitsI[cw]EEC[12]EOS2_; + _ZNSt14basic_[io]fstreamI[cw]St11char_traitsI[cw]EE4swapERS2_; + _ZNSt14basic_[io]fstreamI[cw]St11char_traitsI[cw]EEaSEOS2_; + _ZNSt14basic_[io]fstreamI[cw]St11char_traitsI[cw]EEC[12]EOS2_; + _ZNSt15basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EE4swapERS3_; + _ZNSt15basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EEaSEOS3_; + _ZNSt15basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]EOS3_; + _ZNSt18basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EE4swapERS3_; + _ZNSt18basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEaSEOS3_; + _ZNSt18basic_stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]EOS3_; + _ZNSt19basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EE4swapERS3_; + _ZNSt19basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEaSEOS3_; + _ZNSt19basic_[io]stringstreamI[cw]St11char_traitsI[cw]ESaI[cw]EEC[12]EOS3_; + _ZN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EEaSEOS3_; + _ZN9__gnu_cxx18stdio_sync_filebufI[cw]St11char_traitsI[cw]EEC[12]EOS3_; + + # basic_ostream<C,T>::basic_ostream(basic_iostream<C,T>*) + _ZNSoC[12]EPSd; + _ZNSt13basic_ostreamIwSt11char_traitsIwEEC[12]EPSt14basic_iostreamIwS1_E; + } GLIBCXX_3.4.20; diff --git a/libstdc++-v3/config/io/basic_file_stdio.h b/libstdc++-v3/config/io/basic_file_stdio.h index b457ec5bb9a..f58164e131f 100644 --- a/libstdc++-v3/config/io/basic_file_stdio.h +++ b/libstdc++-v3/config/io/basic_file_stdio.h @@ -38,6 +38,7 @@ #include <bits/c++config.h> #include <bits/c++io.h> // for __c_lock and __c_file +#include <bits/move.h> // for swap #include <ios> namespace std _GLIBCXX_VISIBILITY(default) @@ -61,6 +62,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: __basic_file(__c_lock* __lock = 0) throw (); +#if __cplusplus >= 201103L + __basic_file(__basic_file&& __rv, __c_lock* __lock = 0) noexcept + : _M_cfile(__rv._M_cfile), _M_cfile_created(__rv._M_cfile_created) + { + __rv._M_cfile = nullptr; + __rv._M_cfile_created = false; + } + + __basic_file& operator=(const __basic_file&) = delete; + __basic_file& operator=(__basic_file&&) = delete; + + void + swap(__basic_file& __f) noexcept + { + std::swap(_M_cfile, __f._M_cfile); + std::swap(_M_cfile_created, __f._M_cfile_created); + } +#endif + __basic_file* open(const char* __name, ios_base::openmode __mode, int __prot = 0664); diff --git a/libstdc++-v3/include/bits/basic_ios.h b/libstdc++-v3/include/bits/basic_ios.h index 58bede4d759..10263ed07a4 100644 --- a/libstdc++-v3/include/bits/basic_ios.h +++ b/libstdc++-v3/include/bits/basic_ios.h @@ -36,6 +36,7 @@ #include <bits/locale_classes.h> #include <bits/locale_facets.h> #include <bits/streambuf_iterator.h> +#include <bits/move.h> namespace std _GLIBCXX_VISIBILITY(default) { @@ -465,6 +466,41 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void init(basic_streambuf<_CharT, _Traits>* __sb); +#if __cplusplus >= 201103L + basic_ios(const basic_ios&) = delete; + basic_ios& operator=(const basic_ios&) = delete; + + void + move(basic_ios& __rhs) + { + ios_base::_M_move(__rhs); + _M_cache_locale(_M_ios_locale); + this->tie(__rhs.tie(nullptr)); + _M_fill = __rhs._M_fill; + _M_fill_init = __rhs._M_fill_init; + _M_streambuf = nullptr; + } + + void + move(basic_ios&& __rhs) + { this->move(__rhs); } + + void + swap(basic_ios& __rhs) noexcept + { + ios_base::_M_swap(__rhs); + _M_cache_locale(_M_ios_locale); + __rhs._M_cache_locale(__rhs._M_ios_locale); + std::swap(_M_tie, __rhs._M_tie); + std::swap(_M_fill, __rhs._M_fill); + std::swap(_M_fill_init, __rhs._M_fill_init); + } + + void + set_rdbuf(basic_streambuf<_CharT, _Traits>* __sb) + { _M_streambuf = __sb; } +#endif + void _M_cache_locale(const locale& __loc); }; diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 21a67cdae97..b0404ea8dbd 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -37,6 +37,7 @@ #pragma GCC system_header #include <bits/cxxabi_forced.h> +#include <bits/move.h> // for swap namespace std _GLIBCXX_VISIBILITY(default) { @@ -88,6 +89,90 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_codecvt = &use_facet<__codecvt_type>(this->_M_buf_locale); } +#if __cplusplus >= 201103L + template<typename _CharT, typename _Traits> + basic_filebuf<_CharT, _Traits>:: + basic_filebuf(basic_filebuf&& __rhs) + : __streambuf_type(__rhs), + _M_lock(), _M_file(std::move(__rhs._M_file), &_M_lock), + _M_mode(std::__exchange(__rhs._M_mode, ios_base::openmode(0))), + _M_state_beg(std::move(__rhs._M_state_beg)), + _M_state_cur(std::move(__rhs._M_state_cur)), + _M_state_last(std::move(__rhs._M_state_last)), + _M_buf(std::__exchange(__rhs._M_buf, nullptr)), + _M_buf_size(std::__exchange(__rhs._M_buf_size, 1)), + _M_buf_allocated(std::__exchange(__rhs._M_buf_allocated, false)), + _M_reading(std::__exchange(__rhs._M_reading, false)), + _M_writing(std::__exchange(__rhs._M_writing, false)), + _M_pback(__rhs._M_pback), + _M_pback_cur_save(std::__exchange(__rhs._M_pback_cur_save, nullptr)), + _M_pback_end_save(std::__exchange(__rhs._M_pback_end_save, nullptr)), + _M_pback_init(std::__exchange(__rhs._M_pback_init, false)), + _M_codecvt(__rhs._M_codecvt), + _M_ext_buf(std::__exchange(__rhs._M_ext_buf, nullptr)), + _M_ext_buf_size(std::__exchange(__rhs._M_ext_buf_size, 0)), + _M_ext_next(std::__exchange(__rhs._M_ext_next, nullptr)), + _M_ext_end(std::__exchange(__rhs._M_ext_end, nullptr)) + { + __rhs._M_set_buffer(-1); + __rhs._M_state_last = __rhs._M_state_cur = __rhs._M_state_beg; + } + + template<typename _CharT, typename _Traits> + basic_filebuf<_CharT, _Traits>& + basic_filebuf<_CharT, _Traits>:: + operator=(basic_filebuf&& __rhs) + { + this->close(); + __streambuf_type::operator=(__rhs); + _M_file.swap(__rhs._M_file); + _M_mode = std::__exchange(__rhs._M_mode, ios_base::openmode(0)); + _M_state_beg = std::move(__rhs._M_state_beg); + _M_state_cur = std::move(__rhs._M_state_cur); + _M_state_last = std::move(__rhs._M_state_last); + _M_buf = std::__exchange(__rhs._M_buf, nullptr); + _M_buf_size = std::__exchange(__rhs._M_buf_size, 1); + _M_buf_allocated = std::__exchange(__rhs._M_buf_allocated, false); + _M_ext_buf = std::__exchange(__rhs._M_ext_buf, nullptr); + _M_ext_buf_size = std::__exchange(__rhs._M_ext_buf_size, 0); + _M_ext_next = std::__exchange(__rhs._M_ext_next, nullptr); + _M_ext_end = std::__exchange(__rhs._M_ext_end, nullptr); + _M_reading = std::__exchange(__rhs._M_reading, false); + _M_writing = std::__exchange(__rhs._M_writing, false); + _M_pback_cur_save = std::__exchange(__rhs._M_pback_cur_save, nullptr); + _M_pback_end_save = std::__exchange(__rhs._M_pback_end_save, nullptr); + _M_pback_init = std::__exchange(__rhs._M_pback_init, false); + __rhs._M_set_buffer(-1); + __rhs._M_state_last = __rhs._M_state_cur = __rhs._M_state_beg; + return *this; + } + + template<typename _CharT, typename _Traits> + void + basic_filebuf<_CharT, _Traits>:: + swap(basic_filebuf& __rhs) + { + __streambuf_type::swap(__rhs); + _M_file.swap(__rhs._M_file); + std::swap(_M_mode, __rhs._M_mode); + std::swap(_M_state_beg, __rhs._M_state_beg); + std::swap(_M_state_cur, __rhs._M_state_cur); + std::swap(_M_state_last, __rhs._M_state_last); + std::swap(_M_buf, __rhs._M_buf); + std::swap(_M_buf_size, __rhs._M_buf_size); + std::swap(_M_buf_allocated, __rhs._M_buf_allocated); + std::swap(_M_ext_buf, __rhs._M_ext_buf); + std::swap(_M_ext_buf_size, __rhs._M_ext_buf_size); + std::swap(_M_ext_next, __rhs._M_ext_next); + std::swap(_M_ext_end, __rhs._M_ext_end); + std::swap(_M_reading, __rhs._M_reading); + std::swap(_M_writing, __rhs._M_writing); + std::swap(_M_pback_cur_save, __rhs._M_pback_cur_save); + std::swap(_M_pback_end_save, __rhs._M_pback_end_save); + std::swap(_M_pback_init, __rhs._M_pback_init); + } +#endif + template<typename _CharT, typename _Traits> typename basic_filebuf<_CharT, _Traits>::__filebuf_type* basic_filebuf<_CharT, _Traits>:: diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index 4aade6855fb..fb448fd1091 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -794,6 +794,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ios_base& operator=(const ios_base&) = delete; + + protected: + void + _M_move(ios_base&) noexcept; + + void + _M_swap(ios_base& __rhs) noexcept; #endif }; diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index dc4ac0fea58..2fd0d37e2ed 100644 --- a/libstdc++-v3/include/bits/move.h +++ b/libstdc++-v3/include/bits/move.h @@ -135,6 +135,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION addressof(_Tp& __r) noexcept { return std::__addressof(__r); } + // C++11 version of std::exchange for internal use. + template <typename _Tp, typename _Up = _Tp> + inline _Tp + __exchange(_Tp& __obj, _Up&& __new_val) + { + _Tp __old_val = std::move(__obj); + __obj = std::forward<_Up>(__new_val); + return __old_val; + } + /// @} group utilities _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/ext/stdio_filebuf.h b/libstdc++-v3/include/ext/stdio_filebuf.h index 28741637f84..8d016902174 100644 --- a/libstdc++-v3/include/ext/stdio_filebuf.h +++ b/libstdc++-v3/include/ext/stdio_filebuf.h @@ -97,6 +97,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION virtual ~stdio_filebuf(); +#if __cplusplus >= 201103L + stdio_filebuf(stdio_filebuf&&) = default; + stdio_filebuf& operator=(stdio_filebuf&&) = default; + + void + swap(stdio_filebuf& __fb) + { std::basic_filebuf<_CharT, _Traits>::swap(__fb); } +#endif + /** * @return The underlying file descriptor. * diff --git a/libstdc++-v3/include/ext/stdio_sync_filebuf.h b/libstdc++-v3/include/ext/stdio_sync_filebuf.h index 73283a74b9f..c881172aae3 100644 --- a/libstdc++-v3/include/ext/stdio_sync_filebuf.h +++ b/libstdc++-v3/include/ext/stdio_sync_filebuf.h @@ -35,6 +35,7 @@ #include <unistd.h> #include <cstdio> #include <bits/c++io.h> // For __c_file +#include <bits/move.h> // For __exchange #ifdef _GLIBCXX_USE_WCHAR_T #include <cwchar> @@ -64,8 +65,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename traits_type::off_type off_type; private: + typedef std::basic_streambuf<_CharT, _Traits> __streambuf_type; + // Underlying stdio FILE - std::__c_file* const _M_file; + std::__c_file* _M_file; // Last character gotten. This is used when pbackfail is // called from basic_streambuf::sungetc() @@ -77,6 +80,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_file(__f), _M_unget_buf(traits_type::eof()) { } +#if __cplusplus >= 201103L + stdio_sync_filebuf(stdio_sync_filebuf&& __fb) noexcept + : __streambuf_type(std::move(__fb)), + _M_file(__fb._M_file), _M_unget_buf(__fb._M_unget_buf) + { + __fb._M_file = nullptr; + __fb._M_unget_buf = traits_type::eof(); + } + + stdio_sync_filebuf& + operator=(stdio_sync_filebuf&& __fb) noexcept + { + __streambuf_type::operator=(__fb); + _M_file = std::__exchange(__fb._M_file, nullptr); + _M_unget_buf = std::__exchange(__fb._M_unget_buf, traits_type::eof()); + return *this; + } + + void + swap(stdio_sync_filebuf& __fb) + { + __streambuf_type::swap(__fb); + std::swap(_M_file, __fb._M_file); + std::swap(_M_unget_buf, __fb._M_unget_buf); + } +#endif + /** * @return The underlying FILE*. * diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream index 4d802f153a4..fcf5f94e36e 100644 --- a/libstdc++-v3/include/std/fstream +++ b/libstdc++-v3/include/std/fstream @@ -125,7 +125,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __state_type _M_state_last; /// Pointer to the beginning of internal buffer. - char_type* _M_buf; + char_type* _M_buf; /** * Actual size of internal buffer. This number is equal to the size @@ -226,6 +226,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ basic_filebuf(); +#if __cplusplus >= 201103L + basic_filebuf(const basic_filebuf&) = delete; + basic_filebuf(basic_filebuf&&); +#endif + /** * @brief The destructor closes the file first. */ @@ -233,6 +238,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_filebuf() { this->close(); } +#if __cplusplus >= 201103L + basic_filebuf& operator=(const basic_filebuf&) = delete; + basic_filebuf& operator=(basic_filebuf&&); + void swap(basic_filebuf&); +#endif + // Members: /** * @brief Returns true if the external file is open. @@ -504,6 +515,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->init(&_M_filebuf); this->open(__s, __mode); } + + basic_ifstream(const basic_ifstream&) = delete; + + basic_ifstream(basic_ifstream&& __rhs) + : __istream_type(std::move(__rhs)), + _M_filebuf(std::move(__rhs._M_filebuf)) + { __istream_type::set_rdbuf(&_M_filebuf); } #endif /** @@ -515,6 +533,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_ifstream() { } +#if __cplusplus >= 201103L + // 27.8.3.2 Assign and swap: + + basic_ifstream& + operator=(const basic_ifstream&) = delete; + + basic_ifstream& + operator=(basic_ifstream&& __rhs) + { + __istream_type::operator=(std::move(__rhs)); + _M_filebuf = std::move(__rhs._M_filebuf); + return *this; + } + + void + swap(basic_ifstream& __rhs) + { + __istream_type::swap(__rhs); + _M_filebuf.swap(__rhs._M_filebuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -679,6 +719,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->init(&_M_filebuf); this->open(__s, __mode); } + + basic_ofstream(const basic_ofstream&) = delete; + + basic_ofstream(basic_ofstream&& __rhs) + : __ostream_type(std::move(__rhs)), + _M_filebuf(std::move(__rhs._M_filebuf)) + { __ostream_type::set_rdbuf(&_M_filebuf); } #endif /** @@ -690,6 +737,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_ofstream() { } +#if __cplusplus >= 201103L + // 27.8.3.2 Assign and swap: + + basic_ofstream& + operator=(const basic_ofstream&) = delete; + + basic_ofstream& + operator=(basic_ofstream&& __rhs) + { + __ostream_type::operator=(std::move(__rhs)); + _M_filebuf = std::move(__rhs._M_filebuf); + return *this; + } + + void + swap(basic_ofstream& __rhs) + { + __ostream_type::swap(__rhs); + _M_filebuf.swap(__rhs._M_filebuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -852,6 +921,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->init(&_M_filebuf); this->open(__s, __mode); } + + basic_fstream(const basic_fstream&) = delete; + + basic_fstream(basic_fstream&& __rhs) + : __iostream_type(std::move(__rhs)), + _M_filebuf(std::move(__rhs._M_filebuf)) + { __iostream_type::set_rdbuf(&_M_filebuf); } #endif /** @@ -863,6 +939,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_fstream() { } +#if __cplusplus >= 201103L + // 27.8.3.2 Assign and swap: + + basic_fstream& + operator=(const basic_fstream&) = delete; + + basic_fstream& + operator=(basic_fstream&& __rhs) + { + __iostream_type::operator=(std::move(__rhs)); + _M_filebuf = std::move(__rhs._M_filebuf); + return *this; + } + + void + swap(basic_fstream& __rhs) + { + __iostream_type::swap(__rhs); + _M_filebuf.swap(__rhs._M_filebuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -947,6 +1045,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } }; +#if __cplusplus >= 201103L + /// Swap specialization for filebufs. + template <class _CharT, class _Traits> + inline void + swap(basic_filebuf<_CharT, _Traits>& __x, + basic_filebuf<_CharT, _Traits>& __y) + { __x.swap(__y); } + + /// Swap specialization for ifstreams. + template <class _CharT, class _Traits> + inline void + swap(basic_ifstream<_CharT, _Traits>& __x, + basic_ifstream<_CharT, _Traits>& __y) + { __x.swap(__y); } + + /// Swap specialization for ofstreams. + template <class _CharT, class _Traits> + inline void + swap(basic_ofstream<_CharT, _Traits>& __x, + basic_ofstream<_CharT, _Traits>& __y) + { __x.swap(__y); } + + /// Swap specialization for fstreams. + template <class _CharT, class _Traits> + inline void + swap(basic_fstream<_CharT, _Traits>& __x, + basic_fstream<_CharT, _Traits>& __y) + { __x.swap(__y); } +#endif + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/std/ios b/libstdc++-v3/include/std/ios index 5d69c4be3d2..acfd7c20ae8 100644 --- a/libstdc++-v3/include/std/ios +++ b/libstdc++-v3/include/std/ios @@ -40,7 +40,7 @@ #include <bits/char_traits.h> // For char_traits, streamoff, streamsize, fpos #include <bits/localefwd.h> // For class locale #include <bits/ios_base.h> // For ios_base declarations. -#include <streambuf> +#include <streambuf> #include <bits/basic_ios.h> #endif /* _GLIBCXX_IOS */ diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream index f0637680d3b..3a4761624e2 100644 --- a/libstdc++-v3/include/std/istream +++ b/libstdc++-v3/include/std/istream @@ -607,6 +607,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_gcount(streamsize(0)) { this->init(0); } +#if __cplusplus >= 201103L + basic_istream(const basic_istream&) = delete; + + basic_istream(basic_istream&& __rhs) + : __ios_type(), _M_gcount(__rhs._M_gcount) + { + __ios_type::move(__rhs); + __rhs._M_gcount = 0; + } + + // 27.7.3.3 Assign/swap + + basic_istream& operator=(const basic_istream&) = delete; + + basic_istream& + operator=(basic_istream&& __rhs) + { + swap(__rhs); + return *this; + } + + void + swap(basic_istream& __rhs) + { + __ios_type::swap(__rhs); + std::swap(_M_gcount, __rhs._M_gcount); + } +#endif + template<typename _ValueT> __istream_type& _M_extract(_ValueT& __v); @@ -829,6 +858,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION protected: basic_iostream() : __istream_type(), __ostream_type() { } + +#if __cplusplus >= 201103L + basic_iostream(const basic_iostream&) = delete; + + basic_iostream(basic_iostream&& __rhs) + : __istream_type(std::move(__rhs)), __ostream_type(this) + { } + + // 27.7.3.3 Assign/swap + + basic_iostream& operator=(const basic_iostream&) = delete; + + basic_iostream& + operator=(basic_iostream&& __rhs) + { + swap(__rhs); + return *this; + } + + void + swap(basic_iostream& __rhs) + { __istream_type::swap(__rhs); } +#endif }; /** diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index a25b3d033e6..748b805ee7d 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -384,6 +384,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION basic_ostream() { this->init(0); } +#if __cplusplus >= 201103L + // Non-standard constructor that does not call init() + basic_ostream(basic_iostream<_CharT, _Traits>*) { } + + basic_ostream(const basic_ostream&) = delete; + + basic_ostream(basic_ostream&& __rhs) + : __ios_type() + { __ios_type::move(__rhs); } + + // 27.7.3.3 Assign/swap + + basic_ostream& operator=(const basic_ostream&) = delete; + + basic_ostream& + operator=(basic_ostream&& __rhs) + { + swap(__rhs); + return *this; + } + + void + swap(basic_ostream& __rhs) + { __ios_type::swap(__rhs); } +#endif + template<typename _ValueT> __ostream_type& _M_insert(_ValueT __v); diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index f97caba14ae..f074edaf2e1 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -113,6 +113,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : __streambuf_type(), _M_mode(), _M_string(__str.data(), __str.size()) { _M_stringbuf_init(__mode); } +#if __cplusplus >= 201103L + basic_stringbuf(const basic_stringbuf&) = delete; + + basic_stringbuf(basic_stringbuf&& __rhs) + : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)), + _M_mode(__rhs._M_mode), _M_string(std::move(__rhs._M_string)) + { __rhs._M_stringbuf_init(__rhs._M_mode); } + + // 27.8.2.2 Assign and swap: + + basic_stringbuf& + operator=(const basic_stringbuf&) = delete; + + basic_stringbuf& + operator=(basic_stringbuf&& __rhs) + { + const __streambuf_type& __base = __rhs; + __streambuf_type::operator=(__base); + this->pubimbue(__rhs.getloc()); + _M_mode = __rhs._M_mode; + _M_string = std::move(__rhs._M_string); + __rhs._M_stringbuf_init(__rhs._M_mode); + return *this; + } + + void + swap(basic_stringbuf& __rhs) + { + __streambuf_type& __base = __rhs; + __streambuf_type::swap(__base); + __rhs.pubimbue(this->pubimbue(__rhs.getloc())); + std::swap(_M_mode, __rhs._M_mode); + std::swap(_M_string, __rhs._M_string); + } +#endif + // Get and set: /** * @brief Copying out the string buffer. @@ -337,6 +373,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_istringstream() { } +#if __cplusplus >= 201103L + basic_istringstream(const basic_istringstream&) = delete; + + basic_istringstream(basic_istringstream&& __rhs) + : __istream_type(std::move(__rhs)), + _M_stringbuf(std::move(__rhs._M_stringbuf)) + { __istream_type::set_rdbuf(&_M_stringbuf); } + + // 27.8.3.2 Assign and swap: + + basic_istringstream& + operator=(const basic_istringstream&) = delete; + + basic_istringstream& + operator=(basic_istringstream&& __rhs) + { + __istream_type::operator=(std::move(__rhs)); + _M_stringbuf = std::move(__rhs._M_stringbuf); + return *this; + } + + void + swap(basic_istringstream& __rhs) + { + __istream_type::swap(__rhs); + _M_stringbuf.swap(__rhs._M_stringbuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -452,6 +517,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_ostringstream() { } +#if __cplusplus >= 201103L + basic_ostringstream(const basic_ostringstream&) = delete; + + basic_ostringstream(basic_ostringstream&& __rhs) + : __ostream_type(std::move(__rhs)), + _M_stringbuf(std::move(__rhs._M_stringbuf)) + { __ostream_type::set_rdbuf(&_M_stringbuf); } + + // 27.8.3.2 Assign and swap: + + basic_ostringstream& + operator=(const basic_ostringstream&) = delete; + + basic_ostringstream& + operator=(basic_ostringstream&& __rhs) + { + __ostream_type::operator=(std::move(__rhs)); + _M_stringbuf = std::move(__rhs._M_stringbuf); + return *this; + } + + void + swap(basic_ostringstream& __rhs) + { + __ostream_type::swap(__rhs); + _M_stringbuf.swap(__rhs._M_stringbuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -564,6 +658,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~basic_stringstream() { } +#if __cplusplus >= 201103L + basic_stringstream(const basic_stringstream&) = delete; + + basic_stringstream(basic_stringstream&& __rhs) + : __iostream_type(std::move(__rhs)), + _M_stringbuf(std::move(__rhs._M_stringbuf)) + { __iostream_type::set_rdbuf(&_M_stringbuf); } + + // 27.8.3.2 Assign and swap: + + basic_stringstream& + operator=(const basic_stringstream&) = delete; + + basic_stringstream& + operator=(basic_stringstream&& __rhs) + { + __iostream_type::operator=(std::move(__rhs)); + _M_stringbuf = std::move(__rhs._M_stringbuf); + return *this; + } + + void + swap(basic_stringstream& __rhs) + { + __iostream_type::swap(__rhs); + _M_stringbuf.swap(__rhs._M_stringbuf); + } +#endif + // Members: /** * @brief Accessing the underlying buffer. @@ -594,6 +717,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _M_stringbuf.str(__s); } }; +#if __cplusplus >= 201103L + /// Swap specialization for stringbufs. + template <class _CharT, class _Traits, class _Allocator> + inline void + swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, + basic_stringbuf<_CharT, _Traits, _Allocator>& __y) + { __x.swap(__y); } + + /// Swap specialization for istringstreams. + template <class _CharT, class _Traits, class _Allocator> + inline void + swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, + basic_istringstream<_CharT, _Traits, _Allocator>& __y) + { __x.swap(__y); } + + /// Swap specialization for ostringstreams. + template <class _CharT, class _Traits, class _Allocator> + inline void + swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, + basic_ostringstream<_CharT, _Traits, _Allocator>& __y) + { __x.swap(__y); } + + /// Swap specialization for stringstreams. + template <class _CharT, class _Traits, class _Allocator> + inline void + swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, + basic_stringstream<_CharT, _Traits, _Allocator>& __y) + { __x.swap(__y); } +#endif + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf index d3aa0ee29b5..fce165f4e38 100644 --- a/libstdc++-v3/include/std/streambuf +++ b/libstdc++-v3/include/std/streambuf @@ -798,24 +798,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus < 201103L private: - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // Side effect of DR 50. - basic_streambuf(const basic_streambuf& __sb) - : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur), - _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg), - _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_end), - _M_buf_locale(__sb._M_buf_locale) - { } - - basic_streambuf& - operator=(const basic_streambuf&) { return *this; } #else protected: - basic_streambuf(const basic_streambuf&) = default; +#endif + basic_streambuf(const basic_streambuf&); basic_streambuf& - operator=(const basic_streambuf&) = default; + operator=(const basic_streambuf&); +#if __cplusplus >= 201103L void swap(basic_streambuf& __sb) { @@ -830,6 +821,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif }; +#if __cplusplus >= 201103L + template<typename _CharT, typename _Traits> + std::basic_streambuf<_CharT, _Traits>:: + basic_streambuf(const basic_streambuf&) = default; + + template<typename _CharT, typename _Traits> + std::basic_streambuf<_CharT, _Traits>& + std::basic_streambuf<_CharT, _Traits>:: + operator=(const basic_streambuf&) = default; +#endif + // Explicit specialization declarations, defined in src/streambuf.cc. template<> streamsize diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index 6d12839e509..cb7e1126ed0 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -191,11 +191,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template <typename _Tp, typename _Up = _Tp> inline _Tp exchange(_Tp& __obj, _Up&& __new_val) - { - _Tp __old_val = std::move(__obj); - __obj = std::forward<_Up>(__new_val); - return __old_val; - } + { return std::__exchange(__obj, std::forward<_Up>(__new_val)); } #endif // Stores a tuple of indices. Used by tuple and pair, and by bind() to diff --git a/libstdc++-v3/src/c++11/Makefile.am b/libstdc++-v3/src/c++11/Makefile.am index cf1e3beaa83..39425d41c22 100644 --- a/libstdc++-v3/src/c++11/Makefile.am +++ b/libstdc++-v3/src/c++11/Makefile.am @@ -36,6 +36,7 @@ sources = \ future.cc \ hash_c++0x.cc \ hashtable_c++0x.cc \ + ios.cc \ limits.cc \ mutex.cc \ placeholders.cc \ @@ -49,7 +50,14 @@ sources = \ if ENABLE_EXTERN_TEMPLATE # XTEMPLATE_FLAGS = -fno-implicit-templates inst_sources = \ + ext11-inst.cc \ fstream-inst.cc \ + ios-inst.cc \ + iostream-inst.cc \ + istream-inst.cc \ + ostream-inst.cc \ + sstream-inst.cc \ + streambuf-inst.cc \ string-inst.cc \ wstring-inst.cc else diff --git a/libstdc++-v3/src/c++11/Makefile.in b/libstdc++-v3/src/c++11/Makefile.in index 83b7bd155b9..70c6c4b61fd 100644 --- a/libstdc++-v3/src/c++11/Makefile.in +++ b/libstdc++-v3/src/c++11/Makefile.in @@ -69,11 +69,15 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) libc__11convenience_la_LIBADD = am__objects_1 = chrono.lo condition_variable.lo debug.lo \ functexcept.lo functional.lo future.lo hash_c++0x.lo \ - hashtable_c++0x.lo limits.lo mutex.lo placeholders.lo \ + hashtable_c++0x.lo ios.lo limits.lo mutex.lo placeholders.lo \ random.lo regex.lo shared_ptr.lo snprintf_lite.lo \ system_error.lo thread.lo -@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = fstream-inst.lo \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ string-inst.lo wstring-inst.lo +@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = ext11-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ fstream-inst.lo ios-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ iostream-inst.lo istream-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ ostream-inst.lo sstream-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ streambuf-inst.lo string-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ wstring-inst.lo am_libc__11convenience_la_OBJECTS = $(am__objects_1) $(am__objects_2) libc__11convenience_la_OBJECTS = $(am_libc__11convenience_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) @@ -319,6 +323,7 @@ sources = \ future.cc \ hash_c++0x.cc \ hashtable_c++0x.cc \ + ios.cc \ limits.cc \ mutex.cc \ placeholders.cc \ @@ -334,7 +339,14 @@ sources = \ # XTEMPLATE_FLAGS = -fno-implicit-templates @ENABLE_EXTERN_TEMPLATE_TRUE@inst_sources = \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ ext11-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ fstream-inst.cc \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ ios-inst.cc \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ iostream-inst.cc \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ istream-inst.cc \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ ostream-inst.cc \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ sstream-inst.cc \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ streambuf-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ string-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ wstring-inst.cc diff --git a/libstdc++-v3/src/c++11/ext11-inst.cc b/libstdc++-v3/src/c++11/ext11-inst.cc new file mode 100644 index 00000000000..5d4f95b6ef5 --- /dev/null +++ b/libstdc++-v3/src/c++11/ext11-inst.cc @@ -0,0 +1,40 @@ +// Explicit instantiation file. + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +#include <ext/stdio_filebuf.h> +#include <ext/stdio_sync_filebuf.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template class stdio_filebuf<char>; + template class stdio_sync_filebuf<char>; +#ifdef _GLIBCXX_USE_WCHAR_T + template class stdio_filebuf<wchar_t>; + template class stdio_sync_filebuf<wchar_t>; +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/src/c++98/ios-inst.cc b/libstdc++-v3/src/c++11/ios-inst.cc index 979c252d800..979c252d800 100644 --- a/libstdc++-v3/src/c++98/ios-inst.cc +++ b/libstdc++-v3/src/c++11/ios-inst.cc diff --git a/libstdc++-v3/src/c++98/ios.cc b/libstdc++-v3/src/c++11/ios.cc index b0fab28221d..b5124ec6a27 100644 --- a/libstdc++-v3/src/c++98/ios.cc +++ b/libstdc++-v3/src/c++11/ios.cc @@ -187,5 +187,73 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_callbacks = 0; } + void + ios_base::_M_move(ios_base& __rhs) noexcept + { + _M_precision = __rhs._M_precision; + _M_width = __rhs._M_width; + _M_flags = __rhs._M_flags; + _M_exception = __rhs._M_exception; + _M_streambuf_state = __rhs._M_streambuf_state; + _M_callbacks = std::__exchange(__rhs._M_callbacks, nullptr); + if (_M_word != _M_local_word) + delete[] _M_word; + if (__rhs._M_word == __rhs._M_local_word) + { + _M_word = _M_local_word; + _M_word_size = _S_local_word_size; + for (int __i = 0; __i < _S_local_word_size; __i++) + _M_word[__i] = std::__exchange(__rhs._M_word[__i], {}); + } + else + { + _M_word = std::__exchange(__rhs._M_word, __rhs._M_local_word); + _M_word_size + = std::__exchange(__rhs._M_word_size, _S_local_word_size); + } + _M_ios_locale = __rhs._M_ios_locale; + } + + void + ios_base::_M_swap(ios_base& __rhs) noexcept + { + std::swap(_M_precision, __rhs._M_precision); + std::swap(_M_width, __rhs._M_width); + std::swap(_M_flags, __rhs._M_flags); + std::swap(_M_exception, __rhs._M_exception); + std::swap(_M_streambuf_state, __rhs._M_streambuf_state); + std::swap(_M_callbacks, __rhs._M_callbacks); + const bool __lhs_local = _M_word == _M_local_word; + const bool __rhs_local = __rhs._M_word == __rhs._M_local_word; + if (__lhs_local && __rhs_local) + std::swap(_M_local_word, __rhs._M_local_word); // array swap + else + { + if (!__lhs_local && !__lhs_local) + std::swap(_M_word, __rhs._M_word); + else + { + ios_base* __local; + ios_base* __allocated; + if (__lhs_local) + { + __local = this; + __allocated = &__rhs; + } + else + { + __local = &__rhs; + __allocated= this; + } + for (int __i = 0; __i < _S_local_word_size; __i++) + __allocated->_M_local_word[__i] = __local->_M_local_word[__i]; + __local->_M_word = __allocated->_M_word; + __allocated->_M_word = __allocated->_M_local_word; + } + std::swap(_M_word_size, __rhs._M_word_size); + } + std::swap(_M_ios_locale, __rhs._M_ios_locale); + } + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/src/c++98/iostream-inst.cc b/libstdc++-v3/src/c++11/iostream-inst.cc index 149d9c23d67..149d9c23d67 100644 --- a/libstdc++-v3/src/c++98/iostream-inst.cc +++ b/libstdc++-v3/src/c++11/iostream-inst.cc diff --git a/libstdc++-v3/src/c++98/istream-inst.cc b/libstdc++-v3/src/c++11/istream-inst.cc index dc8832df851..dc8832df851 100644 --- a/libstdc++-v3/src/c++98/istream-inst.cc +++ b/libstdc++-v3/src/c++11/istream-inst.cc diff --git a/libstdc++-v3/src/c++98/ostream-inst.cc b/libstdc++-v3/src/c++11/ostream-inst.cc index 5e8eab14c48..5e8eab14c48 100644 --- a/libstdc++-v3/src/c++98/ostream-inst.cc +++ b/libstdc++-v3/src/c++11/ostream-inst.cc diff --git a/libstdc++-v3/src/c++98/sstream-inst.cc b/libstdc++-v3/src/c++11/sstream-inst.cc index 728946ef474..728946ef474 100644 --- a/libstdc++-v3/src/c++98/sstream-inst.cc +++ b/libstdc++-v3/src/c++11/sstream-inst.cc diff --git a/libstdc++-v3/src/c++98/streambuf-inst.cc b/libstdc++-v3/src/c++11/streambuf-inst.cc index e79d6271d5b..e79d6271d5b 100644 --- a/libstdc++-v3/src/c++98/streambuf-inst.cc +++ b/libstdc++-v3/src/c++11/streambuf-inst.cc diff --git a/libstdc++-v3/src/c++98/Makefile.am b/libstdc++-v3/src/c++98/Makefile.am index 9cebe1e7020..6da69f8ef2e 100644 --- a/libstdc++-v3/src/c++98/Makefile.am +++ b/libstdc++-v3/src/c++98/Makefile.am @@ -87,14 +87,8 @@ inst_sources = \ allocator-inst.cc \ concept-inst.cc \ ext-inst.cc \ - ios-inst.cc \ - iostream-inst.cc \ - istream-inst.cc \ locale-inst.cc \ misc-inst.cc \ - ostream-inst.cc \ - sstream-inst.cc \ - streambuf-inst.cc \ wlocale-inst.cc else # XTEMPLATE_FLAGS = @@ -114,7 +108,6 @@ sources = \ globals_io.cc \ hash_tr1.cc \ hashtable_tr1.cc \ - ios.cc \ ios_failure.cc \ ios_init.cc \ ios_locale.cc \ diff --git a/libstdc++-v3/src/c++98/Makefile.in b/libstdc++-v3/src/c++98/Makefile.in index cf9cda5f4d6..38f96ccc943 100644 --- a/libstdc++-v3/src/c++98/Makefile.in +++ b/libstdc++-v3/src/c++98/Makefile.in @@ -72,23 +72,19 @@ am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \ monetary_members.lo numeric_members.lo time_members.lo @ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = allocator-inst.lo \ @ENABLE_EXTERN_TEMPLATE_TRUE@ concept-inst.lo ext-inst.lo \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ ios-inst.lo iostream-inst.lo \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ istream-inst.lo locale-inst.lo \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ misc-inst.lo ostream-inst.lo \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ sstream-inst.lo streambuf-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ locale-inst.lo misc-inst.lo \ @ENABLE_EXTERN_TEMPLATE_TRUE@ wlocale-inst.lo am__objects_3 = parallel_settings.lo am__objects_4 = basic_file.lo c++locale.lo $(am__objects_2) \ $(am__objects_3) am__objects_5 = bitmap_allocator.lo pool_allocator.lo mt_allocator.lo \ codecvt.lo complex_io.lo ctype.lo globals_io.lo hash_tr1.lo \ - hashtable_tr1.lo ios.lo ios_failure.lo ios_init.lo \ - ios_locale.lo list.lo list-aux.lo list-aux-2.lo \ - list_associated.lo list_associated-2.lo locale.lo \ - locale_init.lo locale_facets.lo localename.lo \ - math_stubs_float.lo math_stubs_long_double.lo stdexcept.lo \ - strstream.lo tree.lo istream.lo streambuf.lo valarray.lo \ - $(am__objects_1) $(am__objects_4) + hashtable_tr1.lo ios_failure.lo ios_init.lo ios_locale.lo \ + list.lo list-aux.lo list-aux-2.lo list_associated.lo \ + list_associated-2.lo locale.lo locale_init.lo locale_facets.lo \ + localename.lo math_stubs_float.lo math_stubs_long_double.lo \ + stdexcept.lo strstream.lo tree.lo istream.lo streambuf.lo \ + valarray.lo $(am__objects_1) $(am__objects_4) am_libc__98convenience_la_OBJECTS = $(am__objects_5) libc__98convenience_la_OBJECTS = $(am_libc__98convenience_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) @@ -355,14 +351,8 @@ host_sources_extra = \ @ENABLE_EXTERN_TEMPLATE_TRUE@ allocator-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ concept-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ ext-inst.cc \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ ios-inst.cc \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ iostream-inst.cc \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ istream-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ locale-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ misc-inst.cc \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ ostream-inst.cc \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ sstream-inst.cc \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ streambuf-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ wlocale-inst.cc parallel_sources = parallel_settings.cc @@ -378,7 +368,6 @@ sources = \ globals_io.cc \ hash_tr1.cc \ hashtable_tr1.cc \ - ios.cc \ ios_failure.cc \ ios_init.cc \ ios_locale.cc \ diff --git a/libstdc++-v3/src/c++98/ext-inst.cc b/libstdc++-v3/src/c++98/ext-inst.cc index 0a782785899..f98f442cb97 100644 --- a/libstdc++-v3/src/c++98/ext-inst.cc +++ b/libstdc++-v3/src/c++98/ext-inst.cc @@ -27,7 +27,6 @@ // #include <ext/rope> -#include <ext/stdio_filebuf.h> namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) { @@ -47,8 +46,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION rope<char, std::allocator<char> >:: _S_fetch(_Rope_RopeRep<char, std::allocator<char> >*, size_type); - template class stdio_filebuf<char>; - #ifdef _GLIBCXX_USE_WCHAR_T template const unsigned long @@ -58,8 +55,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION wchar_t rope<wchar_t, std::allocator<wchar_t> >:: _S_fetch(_Rope_RopeRep<wchar_t, std::allocator<wchar_t> >*, size_type); - - template class stdio_filebuf<wchar_t>; #endif _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/src/c++98/misc-inst.cc b/libstdc++-v3/src/c++98/misc-inst.cc index 1c414fcaeff..540e76d468c 100644 --- a/libstdc++-v3/src/c++98/misc-inst.cc +++ b/libstdc++-v3/src/c++98/misc-inst.cc @@ -29,7 +29,6 @@ #include <string> #include <istream> #include <ostream> -#include <ext/stdio_sync_filebuf.h> namespace std _GLIBCXX_VISIBILITY(default) { @@ -65,17 +64,3 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION } // namespace - -namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) -{ -_GLIBCXX_BEGIN_NAMESPACE_VERSION - - template class stdio_sync_filebuf<char>; -#ifdef _GLIBCXX_USE_WCHAR_T - template class stdio_sync_filebuf<wchar_t>; -#endif - -_GLIBCXX_END_NAMESPACE_VERSION -} // namespace - - diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc new file mode 100644 index 00000000000..2080a9b60e2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <fstream> + +void test() +{ + std::filebuf f; + std::filebuf ff(f); // { dg-error "deleted function" } + ff = f; // { dg-error "deleted function" } +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/assign/1.cc new file mode 100644 index 00000000000..84947d0a7fd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/assign/1.cc @@ -0,0 +1,88 @@ +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.16 Assign and swap [fstream.assign] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +string const name = "fstream-assign.txt"; + +void +test01() +{ + string orig = "Let the whole outside world consist of a long paper tape."; + { + fstream f(name, ios::in|ios::out|ios::trunc); + VERIFY( f.is_open() ); + f << orig; + fstream f1; + f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1.seekg(0); + string result; + getline(f1, result); + VERIFY( result == orig ); + } + { + fstream f(name, ios::in); + VERIFY( f.is_open() ); + fstream f1; + f1.swap(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + string result; + getline(f1, result); + VERIFY( result == orig ); + } + { + fstream f(name, ios::in); + VERIFY( f.is_open() ); + fstream f1; + swap(f1, f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + string result; + getline(f1, result); + VERIFY( result == orig ); + } +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + wfstream f, f2; + f2 = std::move(f); + f2.swap(f); + swap(f2, f); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/move.cc new file mode 100644 index 00000000000..1805e52f67e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/move.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.15 basic_fstream constructors [fstream.cons] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +std::string const name = "fstream-move.txt"; + +void +test01() +{ + string orig = "Let the whole outside world consist of a long paper tape."; + fstream f(name, ios::in|ios::out|ios::trunc); + VERIFY( f.is_open() ); + f << orig; + fstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1.seekg(0); + string result; + getline(f1, result); + VERIFY( result == orig ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + wstring orig = L"Let the whole outside world consist of a long paper tape."; + wfstream f(name, ios::in|ios::out|ios::trunc); + VERIFY( f.is_open() ); + f << orig; + wfstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1.seekg(0); + wstring result; + getline(f1, result); + VERIFY( result == orig ); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc new file mode 100644 index 00000000000..e652d47b431 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc @@ -0,0 +1,85 @@ +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.8 Assign and swap [ifstream.assign] + +#include <fstream> +#include <sstream> +#include <testsuite_hooks.h> + +void +read(std::istream& in, std::ostream& out) +{ + std::string s; + for (int i=0; i < 10; ++i) + { + getline(in, s); + out << s << '\n'; + } +} + +void +test01() +{ + std::string const name = "thirty_years_among_the_dead_preproc.txt"; + std::ostringstream ss0; + { + std::ifstream f0(name); + read(f0, ss0); + } + { + std::ifstream f0(name); + std::ifstream f1; + f1 = std::move(f0); + VERIFY( !f0.is_open() ); + VERIFY( f1.is_open() ); + std::ostringstream ss1; + read(f1, ss1); + VERIFY( ss0.str() == ss1.str() ); + } + { + std::ifstream f0(name); + std::ifstream f1; + f1.swap(f0); + VERIFY( !f0.is_open() ); + VERIFY( f1.is_open() ); + std::ostringstream ss1; + read(f1, ss1); + VERIFY( ss0.str() == ss1.str() ); + } +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wifstream f, f2; + f2 = std::move(f); + f2.swap(f); + swap(f2, f); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc new file mode 100644 index 00000000000..afa2a62696a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.7 basic_ifstream constructors [ifstream.cons] + +#include <fstream> +#include <sstream> +#include <testsuite_hooks.h> + +void +read(std::istream& in, std::ostream& out) +{ + std::string s; + for (int i=0; i < 10; ++i) + { + getline(in, s); + out << s << '\n'; + } +} + +void +test01() +{ + std::string const name = "thirty_years_among_the_dead_preproc.txt"; + std::ostringstream ss0; + { + std::ifstream f0(name); + read(f0, ss0); + } + std::ifstream f0(name); + std::ifstream f1 = std::move(f0); + VERIFY( !f0.is_open() ); + VERIFY( f1.is_open() ); + std::ostringstream ss1; + read(f1, ss1); + VERIFY( ss0.str() == ss1.str() ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wifstream f0("thirty_years_among_the_dead_preproc.txt"); + std::wifstream f1 = std::move(f0); + VERIFY( f1.is_open() ); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/1.cc new file mode 100644 index 00000000000..a9ae2ae9eba --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/1.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.3.2 Assign and swap [istringstream.assign] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + std::istringstream s1("absence of a signal"); + std::string s; + s1 >> s; + + std::istringstream s2; + s2 = std::move(s1); + s2 >> s; + VERIFY(s == "of"); + + std::istringstream s3; + s3.swap(s2); + s3 >> s; + VERIFY(s == "a"); + + swap(s1, s3); + s1 >> s; + VERIFY(s == "signal"); + + s2.str("should never be used as a signal"); + s1 = std::move(s2); + getline(s1, s); + VERIFY(s == "should never be used as a signal"); + s3 = std::move(s1); + VERIFY(s3.eof()); +} + +void test02() +{ + std::istringstream s0{ " 1234.5 " }; + std::istringstream s; + s = std::move(s0); + char c{}; + s >> c; + VERIFY( c == '1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +} + +void test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wistringstream s0{ L" 1234.5 " }; + std::wistringstream s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); + wchar_t c{}; + s >> c; + VERIFY( c == L'1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/move.cc new file mode 100644 index 00000000000..77c1fbb2afe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/move.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.3.1 basic_istringstream constructors [istringstream.cons] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + std::istringstream s1("absence of a signal"); + std::string s; + s1 >> s; + + std::istringstream s2 = std::move(s1); + s2 >> s; + VERIFY(s == "of"); + + std::istringstream s3; + s3 = std::move(s2); + s3 >> s; + VERIFY(s == "a"); + + s1 = std::move(s3); + s1 >> s; + VERIFY(s == "signal"); + + s2.str("should never be used as a signal"); + s1 = std::move(s2); + getline(s1, s); + VERIFY(s == "should never be used as a signal"); + s3 = std::move(s1); + VERIFY(s3.eof()); +} + +void +test02() +{ + std::istringstream s0{ " 1234.5 " }; + std::istringstream s{ std::move(s0) }; + char c{}; + s >> c; + VERIFY( c == '1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +} + +void +test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wistringstream s0{ L" 1234.5 " }; + std::wistringstream s{ std::move(s0) }; + wchar_t c{}; + s >> c; + VERIFY( c == L'1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc new file mode 100644 index 00000000000..7092ebe64a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.12 Assign and swap [ostringstream.assign] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +string const name = "ofstream-assign.txt"; + +void +test01() +{ + string s1 = "Let the whole outside world"; + string s2 = " consist of a long paper tape."; + ofstream f(name, ios::trunc); + VERIFY( f.is_open() ); + f << s1; + { + ofstream f1; + f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1 << s2; + f1.swap(f); + VERIFY( !f1.is_open() ); + VERIFY( f.is_open() ); + f << s1; + swap(f1, f); + f1 << s2; + } + ifstream in(name); + string result; + getline(in, result); + VERIFY( result == (s1 + s2 + s1 + s2) ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wofstream s0, s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/move.cc new file mode 100644 index 00000000000..a6dca710132 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/move.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.11 basic_ofstream constructors [ofstream.cons] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +std::string const name = "ofstream-move.txt"; + +void +test01() +{ + string s1 = "Let the whole outside world"; + string s2 = " consist of a long paper tape."; + ofstream f(name, ios::trunc); + VERIFY( f.is_open() ); + f << s1; + { + ofstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1 << s2; + } + ifstream in(name); + string result; + getline(in, result); + VERIFY( result == (s1 + s2) ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + wstring s1 = L"Let the whole outside world"; + wstring s2 = L" consist of a long paper tape."; + wofstream f(name, ios::trunc); + VERIFY( f.is_open() ); + f << s1; + { + wofstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1 << s2; + } + wifstream in(name); + wstring result; + getline(in, result); + VERIFY( result == (s1 + s2) ); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/1.cc new file mode 100644 index 00000000000..01b92e9e3d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/1.cc @@ -0,0 +1,117 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.4.2 Assign and swap [ostringstream.assign] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +const std::string strings[] = { + "one could carry out the description of a machine, ", + "no matter how complicated, ", + "in characters which would be merely the letters of the alphabet, and so ", + "provide the mind with a method of knowing the machine and all its parts" +}; + +void +append(std::ostringstream& ss, std::string& s, const std::string& t) +{ + ss << t; + s += t; +} + +// assign +void +test01() +{ + std::string exp; + std::ostringstream s1; + append(s1, exp, strings[0]); + + std::ostringstream s2; + s2 = std::move(s1); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::ostringstream s3; + s3 = std::move(s2); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.setstate(std::ios::failbit); + s1 = std::move(s3); + VERIFY( s1.good() ); + VERIFY( s1.str() == exp ); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +// swap +void +test02() +{ + std::string exp; + std::ostringstream s1; + append(s1, exp, strings[0]); + + std::ostringstream s2; + s2.swap(s1); + VERIFY( s1.str().empty() ); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::ostringstream s3; + swap(s3, s2); + VERIFY( s2.str().empty() ); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.setstate(std::ios::failbit); + swap(s1, s3); + VERIFY( s1.good() ); + VERIFY( s3.fail() ); + VERIFY( s2.str().empty() ); + VERIFY( s1.str() == exp ); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +void +test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wistringstream s0, s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/move.cc new file mode 100644 index 00000000000..26ccf1a8bcc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/move.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.4.1 basic_ostringstream constructors [ostringstream.cons] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +const std::string strings[] = { + "one could carry out the description of a machine, ", + "no matter how complicated, ", + "in characters which would be merely the letters of the alphabet, and so ", + "provide the mind with a method of knowing the machine and all its parts" +}; + +void +append(std::ostringstream& ss, std::string& s, const std::string& t) +{ + ss << t; + s += t; +} + +void +test01() +{ + std::string exp; + std::ostringstream s1; + append(s1, exp, strings[0]); + + std::ostringstream s2 = std::move(s1); + VERIFY( s2.good() ); + VERIFY( s2.rdbuf() != nullptr ); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::ostringstream s3 = std::move(s2); + VERIFY( s3.good() ); + VERIFY( s3.rdbuf() != nullptr ); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.str(""); + s1.clear(); + exp.clear(); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wostringstream s1; + std::wostringstream s2 = std::move(s1); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc new file mode 100644 index 00000000000..0465461c7cb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc @@ -0,0 +1,100 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.5.2 Assign and swap [stringstream.assign] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + std::stringstream s1; + s1 << "absence of a signal"; + std::string s; + s1 >> s; + + std::stringstream s2; + s2 = std::move(s1); + s2 >> s; + VERIFY(s == "of"); + + std::stringstream s3; + s3.swap(s2); + s3 >> s; + VERIFY(s == "a"); + + swap(s1, s3); + s1 >> s; + VERIFY(s == "signal"); + + s2 << "should never be used as a signal"; + s1 = std::move(s2); + getline(s1, s); + VERIFY(s == "should never be used as a signal"); + s3 = std::move(s1); + VERIFY(s3.eof()); +} + +void test02() +{ + std::stringstream s0; + s0 << " 1234.5 "; + std::stringstream s; + s = std::move(s0); + char c{}; + s >> c; + VERIFY( c == '1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +} + +void test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wstringstream s0; + s0 << L" 1234.5 "; + std::wstringstream s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); + wchar_t c{}; + s >> c; + VERIFY( c == L'1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/move.cc new file mode 100644 index 00000000000..3991e7c72a0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/move.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.5.1 basic_stringstream constructors [stringstream.cons] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +const std::string strings[] = { + "one could carry out the description of a machine, ", + "no matter how complicated, ", + "in characters which would be merely the letters of the alphabet, and so ", + "provide the mind with a method of knowing the machine and all its parts" +}; + +void +append(std::stringstream& ss, std::string& s, const std::string& t) +{ + ss << t; + s += t; +} + +void +test01() +{ + std::string exp; + std::stringstream s1; + append(s1, exp, strings[0]); + + std::stringstream s2 = std::move(s1); + VERIFY( s2.good() ); + VERIFY( s2.rdbuf() != nullptr ); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::stringstream s3 = std::move(s2); + VERIFY( s3.good() ); + VERIFY( s3.rdbuf() != nullptr ); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.str(""); + s1.clear(); + exp.clear(); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wstringstream s1; + std::wstringstream s2 = std::move(s1); +#endif +} + +int +main() +{ + test01(); + test02(); +} |