From 7a59efae86cfa74ed45a0a78139082e8443873b1 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 7 Mar 2005 16:58:43 +0000 Subject: [PATCH] std_fstream.h (basic_fstream<>::open, [...]): Implement the resolution of DR 409 [Ready], call clear() on success. 2005-03-07 Paolo Carlini * include/std/std_fstream.h (basic_fstream<>::open, basic_ifstream<>::open, basic_ofstream<>::open): Implement the resolution of DR 409 [Ready], call clear() on success. * docs/html/ext/howto.html: Add an entry for DR 409. * docs/html/faq/index.html (4_4): Clarify the new behavior. * testsuite/27_io/basic_ifstream/open/char/1.cc: Adjust. * testsuite/27_io/basic_ofstream/open/char/1.cc: Likewise. From-SVN: r96030 --- libstdc++-v3/ChangeLog | 10 ++++++++++ libstdc++-v3/docs/html/ext/howto.html | 6 ++++++ libstdc++-v3/docs/html/faq/index.html | 3 +++ libstdc++-v3/include/std/std_fstream.h | 12 ++++++++++++ .../testsuite/27_io/basic_ifstream/open/char/1.cc | 9 +++++---- .../testsuite/27_io/basic_ofstream/open/char/1.cc | 9 +++++---- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index caab5483d77..a11e34f5387 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2005-03-07 Paolo Carlini + + * include/std/std_fstream.h (basic_fstream<>::open, + basic_ifstream<>::open, basic_ofstream<>::open): Implement the + resolution of DR 409 [Ready], call clear() on success. + * docs/html/ext/howto.html: Add an entry for DR 409. + * docs/html/faq/index.html (4_4): Clarify the new behavior. + * testsuite/27_io/basic_ifstream/open/char/1.cc: Adjust. + * testsuite/27_io/basic_ofstream/open/char/1.cc: Likewise. + 2005-03-05 Joseph S. Myers * testsuite/22_locale/collate/compare/wchar_t/2.cc, diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index fff775e165a..72317f83c5d 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -503,6 +503,12 @@
Replace "new" with "::new".
+
409: + Closing an fstream should clear the error state +
+
Have open clear the error flags. +
+
434: bitset::to_string() hard to use
diff --git a/libstdc++-v3/docs/html/faq/index.html b/libstdc++-v3/docs/html/faq/index.html index abd6ff3d13f..a0315981b1c 100644 --- a/libstdc++-v3/docs/html/faq/index.html +++ b/libstdc++-v3/docs/html/faq/index.html @@ -721,6 +721,9 @@ which is no longer available, thanks deja...--> DR #22 is to leave the flags unchanged. You must insert a call to fs.clear() between the calls to close() and open(), and then everything will work like we all expect it to work. + Update: for GCC 4.0 we implemented the resolution + of DR #409 and open() now calls + clear() on success!

rel_ops Another is the rel_ops namespace and the template diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h index ed119d4c8ea..fb042ae2fec 100644 --- a/libstdc++-v3/include/std/std_fstream.h +++ b/libstdc++-v3/include/std/std_fstream.h @@ -496,6 +496,10 @@ namespace std { 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(); } /** @@ -623,6 +627,10 @@ namespace std { 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(); } /** @@ -749,6 +757,10 @@ namespace std { 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(); } /** diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc index dcb89a6dfa2..cbc4c7ac109 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc. +// Copyright (C) 2000, 2001, 2003, 2005 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 @@ -40,9 +40,10 @@ void test01() ifs1.open(name_01); VERIFY( ifs1.is_open() ); - // fail bit still true - VERIFY( !(ifs1) ); - VERIFY( ifs1.rdstate() == std::ios_base::failbit ); + + // As per the resolution of DR 409. + VERIFY( (ifs1) ); + VERIFY( ifs1.rdstate() == std::ios_base::goodbit ); ifs1.close(); } diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc index 5bb02d4eb3c..64b9e342c38 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc. +// Copyright (C) 2000, 2001, 2003, 2005 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 @@ -41,9 +41,10 @@ void test01() ofs1.open(name_02); VERIFY( ofs1.is_open() ); - // fail bit still true - VERIFY( !(ofs1) ); - VERIFY( ofs1.rdstate() == std::ios_base::failbit ); + + // As per the resolution of DR 409. + VERIFY( (ofs1) ); + VERIFY( ofs1.rdstate() == std::ios_base::goodbit ); ofs1.close(); }