This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std::string overloads for xfstream


Hi,

This little tidbit provides the C++-0X std::string overloads for fstream and friends. This makes it so you don't need name_string.c_str() to open a file.

There is another piece to this involving the C++-0X rework of ios_base::failure but that issue is deeper and will follow in another patch when I can get it working. It would also benefit from completion of std::system_error from which it now derives.

We generally know about the big bits of C++-0X and are making rapid progress. But there are probably lots of crumbs like this one that are not captured in the status pages. (e.g. I know that valarray needs the rvalue swap method and namespace swap functions and rvalue ctors and assigns). I'll work from the bottom up compiling a list of these tidbits. If anyone else has noticed missing things or knows of a fine-grained diff w.r.t. 2003 that would be really helpful.

Ed Smith-Rowland

Attachment: CL_fstream_string
Description: Binary data

Index: include/std/fstream
===================================================================
--- include/std/fstream	(revision 144888)
+++ include/std/fstream	(working copy)
@@ -47,6 +47,9 @@
 #include <bits/codecvt.h>
 #include <cstdio>             // For BUFSIZ     
 #include <bits/basic_file.h>  // For __basic_file, __c_lock
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#include <string>             // For std::string overloads.
+#endif
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
@@ -266,6 +269,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       __filebuf_type*
       open(const char* __s, ios_base::openmode __mode);
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *  @return  @c this on success, NULL on failure
+       */
+      __filebuf_type*
+      open(const std::string& __s, ios_base::openmode __mode)
+      { return open(__s.c_str(), __mode); }
+#endif
+
       /**
        *  @brief  Closes the currently associated file.
        *  @return  @c this on success, NULL on failure
@@ -448,6 +463,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an input file stream.
+       *  @param  s  std::string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       *
+       *  @c ios_base::in is automatically included in @a mode.
+      */
+      explicit
+      basic_ifstream(const std::string& __s,
+		     ios_base::openmode __mode = ios_base::in)
+      : __istream_type(), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -504,6 +537,27 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode|in).  If that function
+       *  fails, @c failbit is set in the stream's error state.
+      */
+      void
+      open(const std::string& __s, ios_base::openmode __mode = ios_base::in)
+      {
+	if (!_M_filebuf.open(__s, __mode | ios_base::in))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
@@ -579,6 +633,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an output file stream.
+       *  @param  s  std::string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       *
+       *  @c ios_base::out|ios_base::trunc is automatically included in
+       *  @a mode.
+      */
+      explicit
+      basic_ofstream(const std::string& __s,
+		     ios_base::openmode __mode = ios_base::out|ios_base::trunc)
+      : __ostream_type(), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -636,6 +709,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode|out|trunc).  If that
+       *  function fails, @c failbit is set in the stream's error state.
+      */
+      void
+      open(const std::string& __s,
+	   ios_base::openmode __mode = ios_base::out | ios_base::trunc)
+      {
+	if (!_M_filebuf.open(__s, __mode | ios_base::out))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
@@ -710,6 +805,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an input/output file stream.
+       *  @param  s  Null terminated string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       */
+      explicit
+      basic_fstream(const std::string& __s,
+		    ios_base::openmode __mode = ios_base::in | ios_base::out)
+      : __iostream_type(NULL), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -767,6 +878,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode).  If that
+       *  function fails, @c failbit is set in the stream's error state.
+       */
+      void
+      open(const std::string& __s,
+	   ios_base::openmode __mode = ios_base::in | ios_base::out)
+      {
+	if (!_M_filebuf.open(__s, __mode))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
Index: testsuite/27_io/basic_ofstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_ofstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ofstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,62 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.13 ofstream member functions
+// @require@ %-*.tst
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <ostream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "ofstream_members-1.tst";
+const std::string name_02 = "ofstream_members-1.txt";
+
+// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00136.html
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::ofstream ofs1;
+  ofs1.close();
+  
+  // false as expected:
+  VERIFY( !ofs1.is_open() );
+   // this is now true:
+  VERIFY( !(ofs1) );
+  
+  ofs1.open(name_02);
+  VERIFY( ofs1.is_open() );
+
+  // As per the resolution of DR 409.
+  VERIFY( (ofs1) );
+  VERIFY( ofs1.rdstate() == std::ios_base::goodbit );
+
+  ofs1.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ofstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_ofstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ofstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.11 ofstream constructors
+// @require@ %-*.tst
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <ostream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_02 = "ofstream_members-1.txt";
+
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+  const int more_than_max_open_files = 8200;
+  
+  for(int i = 0; ++i < more_than_max_open_files;)
+    {
+      std::ofstream ofs(name_02);
+      VERIFY( static_cast<bool>(ofs) );
+    }
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_fstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_fstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_fstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,59 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.17 fstream member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "fstream_members-1.txt";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::fstream fs1;
+  fs1.close();
+  
+  // false as expected:
+  VERIFY( !fs1.is_open() );
+   // this is now true:
+  VERIFY( !(fs1) );
+  
+  fs1.open(name_01);
+  VERIFY( fs1.is_open() );
+
+  // As per the resolution of DR 409.
+  VERIFY( (fs1) );
+  VERIFY( fs1.rdstate() == std::ios_base::goodbit );
+
+  fs1.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_fstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_fstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_fstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,50 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.15 fstream constructors
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "fstream_members-1.txt";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  const int more_than_max_open_files = 8200;
+  
+  for (int i = 0; ++i < more_than_max_open_files;)
+    {
+      std::fstream fs(name_01);
+      VERIFY( static_cast<bool>(fs) );
+    }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ifstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_ifstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ifstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.9 ifstream member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <istream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "ifstream_members-1.tst";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::ifstream ifs1;
+  ifs1.close();
+  
+  // false as expected:
+  VERIFY( !ifs1.is_open() );
+   // this is now true:
+  VERIFY( !(ifs1) );
+  
+  ifs1.open(name_01);
+  VERIFY( ifs1.is_open() );
+
+  // As per the resolution of DR 409.
+  VERIFY( (ifs1) );
+  VERIFY( ifs1.rdstate() == std::ios_base::goodbit );
+
+  ifs1.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ifstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_ifstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ifstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.7 ifstream constructors
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <istream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "ifstream_members-1.tst";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  const int more_than_max_open_files = 8200;
+  
+  for (int i = 0; ++i < more_than_max_open_files;)
+    {
+      std::ifstream ifs(name_01);
+      VERIFY( static_cast<bool>(ifs) );
+    }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_filebuf/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_filebuf/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_filebuf/open/string/1.cc	(revision 0)
@@ -0,0 +1,75 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.3 filebuf member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// various tests for filebuf::open() and filebuf::close() including
+// the non-portable functionality in the libstdc++-v3 IO library
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "filebuf_members-1.tst";
+const std::string name_02 = "filebuf_members-1.txt";
+
+// Test member functions.
+void test_01() 
+{
+  bool test __attribute__((unused)) = true;
+  const std::string name_03 = "filebuf_members-3"; // empty file, need to create
+
+  std::filebuf fb_01; // in 
+  std::filebuf fb_02; // out
+  std::filebuf fb_03; // in | out
+
+  // bool is_open()
+  VERIFY( !fb_01.is_open() );
+  VERIFY( !fb_02.is_open() );
+  VERIFY( !fb_03.is_open() );
+
+  fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
+  VERIFY( fb_01.is_open() );
+
+  // Try to open two different files without closing the first:
+  // Should keep the old file attached, and disregard attempt to overthrow.
+  std::filebuf* f = fb_02.open(name_02, std::ios_base::in | std::ios_base::out 
+			       | std::ios_base::trunc);
+  VERIFY( f != NULL );
+  VERIFY( fb_02.is_open() );
+
+  f = fb_02.open(name_03, std::ios_base::in | std::ios_base::out);
+  VERIFY( f == NULL );
+  VERIFY( fb_02.is_open() );
+
+  fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc);
+  VERIFY( fb_03.is_open() );
+}
+
+int
+main()
+{
+  test_01();
+  return 0;
+}
+
+
Index: testsuite/27_io/basic_filebuf/open/string/3.cc
===================================================================
--- testsuite/27_io/basic_filebuf/open/string/3.cc	(revision 0)
+++ testsuite/27_io/basic_filebuf/open/string/3.cc	(revision 0)
@@ -0,0 +1,56 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.3 filebuf member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// various tests for filebuf::open() and filebuf::close() including
+// the non-portable functionality in the libstdc++-v3 IO library
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// Charles Leggett <CGLeggett@lbl.gov>
+void test_05()
+{
+  bool test __attribute__((unused)) = true;
+  const std::string name = "tmp_file5";
+
+  std::fstream scratch_file;
+
+  scratch_file.open(name, std::ios::out);
+  scratch_file.close();
+
+  scratch_file.open(name, std::ios::in);
+  if (!scratch_file)
+    VERIFY( false );
+  scratch_file.close();
+}
+
+int
+main()
+{
+  test_05();
+  return 0;
+}
+
+
Index: testsuite/27_io/basic_filebuf/open/string/4.cc
===================================================================
--- testsuite/27_io/basic_filebuf/open/string/4.cc	(revision 0)
+++ testsuite/27_io/basic_filebuf/open/string/4.cc	(revision 0)
@@ -0,0 +1,72 @@
+// Copyright (C) 2009 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// DR 596.
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  const std::string name = "tmp_file4";
+
+  std::fstream scratch_file;
+
+  scratch_file.open(name, std::ios_base::app);
+  VERIFY( scratch_file );
+  VERIFY( scratch_file.is_open() );
+  scratch_file.close();
+
+  scratch_file.open(name, std::ios_base::in | std::ios_base::out
+		    | std::ios_base::app);
+  VERIFY( scratch_file );
+  VERIFY( scratch_file.is_open() );
+  scratch_file.close();
+
+  scratch_file.open(name, std::ios_base::in | std::ios_base::app);
+  VERIFY( scratch_file );
+  VERIFY( scratch_file.is_open() );
+  scratch_file.close();
+
+  scratch_file.open(name, std::ios_base::app | std::ios_base::binary);
+  VERIFY( scratch_file );
+  VERIFY( scratch_file.is_open() );
+  scratch_file.close();
+
+  scratch_file.open(name, std::ios_base::in | std::ios_base::out
+		    | std::ios_base::app | std::ios_base::binary);
+  VERIFY( scratch_file );
+  VERIFY( scratch_file.is_open() );  
+  scratch_file.close();
+
+  scratch_file.open(name, std::ios_base::in | std::ios_base::app
+		    | std::ios_base::binary);
+  VERIFY( scratch_file );
+  VERIFY( scratch_file.is_open() );  
+  scratch_file.close();
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
Index: testsuite/data/fstream_members-1.txt
===================================================================

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]