summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_ofstream/assign
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-09-22 13:34:09 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-09-22 13:34:09 +0000
commit28f8cba268ceb976aa8ce17bd3177d990e8c85d2 (patch)
tree56471caae5e872ad7a27f4e39b5f246f4a5245c8 /libstdc++-v3/testsuite/27_io/basic_ofstream/assign
parent3979f78787bdc6db3e1679b6015a1a403bb097ba (diff)
downloadgcc-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/testsuite/27_io/basic_ofstream/assign')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc74
1 files changed, 74 insertions, 0 deletions
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();
+}