This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch/RFC] Implement the resolution of DR 409 [Ready]
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sun, 06 Mar 2005 20:33:30 +0100
- Subject: [Patch/RFC] Implement the resolution of DR 409 [Ready]
Hi,
this is a rather welcome resolution, in my opinion, answering one of the
most
frequently reported not-a-bug. The patch is straightforward, and should not
break most sensible user code, but I propose to have it also for 4.0 (i.e.,
not only mainline), since a non-trivial change of behavior seems more suited
for a major release.
Any objections? Otherwise, I will commit it soon...
Tested x86-linux.
Paolo.
/////////////
2005-03-07 Paolo Carlini <pcarlini@suse.de>
* 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.
diff -urN libstdc++-v3-orig/docs/html/ext/howto.html libstdc++-v3/docs/html/ext/howto.html
--- libstdc++-v3-orig/docs/html/ext/howto.html 2004-11-26 21:34:23.000000000 +0100
+++ libstdc++-v3/docs/html/ext/howto.html 2005-03-06 19:49:36.000000000 +0100
@@ -503,6 +503,12 @@
<dd>Replace "new" with "::new".
</dd>
+ <dt><a href="lwg-active.html#409">409</a>:
+ <em>Closing an fstream should clear the error state</em>
+ </dt>
+ <dd>Have <code>open</code> clear the error flags.
+ </dd>
+
<dt><a href="lwg-active.html#434">434</a>:
<em>bitset::to_string() hard to use</em>
</dt>
diff -urN libstdc++-v3-orig/docs/html/faq/index.html libstdc++-v3/docs/html/faq/index.html
--- libstdc++-v3-orig/docs/html/faq/index.html 2004-07-29 10:47:34.000000000 +0200
+++ libstdc++-v3/docs/html/faq/index.html 2005-03-06 20:07:34.000000000 +0100
@@ -721,6 +721,9 @@
DR #22</a> is to leave the flags unchanged. You must insert a call
to <code>fs.clear()</code> between the calls to close() and open(),
and then everything will work like we all expect it to work.
+ <strong>Update:</strong> for GCC 4.0 we implemented the resolution
+ of <a href="../ext/howto.html#5">DR #409</a> and open() now calls
+ <code>clear()</code> on success!
</p>
<p><a name="4_4_rel_ops"><strong>rel_ops</strong></a>
Another is the <code>rel_ops</code> namespace and the template
diff -urN libstdc++-v3-orig/include/std/std_fstream.h libstdc++-v3/include/std/std_fstream.h
--- libstdc++-v3-orig/include/std/std_fstream.h 2005-01-06 21:40:25.000000000 +0100
+++ libstdc++-v3/include/std/std_fstream.h 2005-03-06 18:51:33.000000000 +0100
@@ -496,6 +496,8 @@
{
if (!_M_filebuf.open(__s, __mode | ios_base::in))
this->setstate(ios_base::failbit);
+ else
+ this->clear();
}
/**
@@ -623,6 +625,8 @@
{
if (!_M_filebuf.open(__s, __mode | ios_base::out))
this->setstate(ios_base::failbit);
+ else
+ this->clear();
}
/**
@@ -749,6 +753,8 @@
{
if (!_M_filebuf.open(__s, __mode))
this->setstate(ios_base::failbit);
+ else
+ this->clear();
}
/**
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ifstream/open/char/1.cc libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ifstream/open/char/1.cc 2003-09-23 22:03:04.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc 2005-03-06 19:18:02.000000000 +0100
@@ -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 @@
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 -urN libstdc++-v3-orig/testsuite/27_io/basic_ofstream/open/char/1.cc libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ofstream/open/char/1.cc 2003-09-23 22:03:12.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc 2005-03-06 19:18:50.000000000 +0100
@@ -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 @@
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();
}