]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/9169 (filebuf output fails if codecvt<>::out returns noconv)
authorPaolo Carlini <pcarlini@unitus.it>
Mon, 17 Feb 2003 21:48:49 +0000 (22:48 +0100)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 17 Feb 2003 21:48:49 +0000 (21:48 +0000)
2003-02-17  Paolo Carlini  <pcarlini@unitus.it>

PR libstdc++/9169
* include/bits/fstream.tcc (_M_convert_to_external):
Deal correctly with noconv, as prescribed by 27.8.1.4,p8.
* testsuite/27_io/filebuf_virtuals.cc (test09): Add.

From-SVN: r63011

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc

index 5c6a9d743ead94b303d9fdd96fef60cb03ab0af1..12e8c605f314c2087d7caf98615e830bb97c49a7 100644 (file)
@@ -1,4 +1,11 @@
-003-02-07  Paolo Carlini  <pcarlini@unitus.it>
+2003-02-17  Paolo Carlini  <pcarlini@unitus.it>
+
+       PR libstdc++/9169
+       * include/bits/fstream.tcc (_M_convert_to_external):
+       Deal correctly with noconv, as prescribed by 27.8.1.4,p8.
+       * testsuite/27_io/filebuf_virtuals.cc (test09): Add.
+       
+2003-02-07  Paolo Carlini  <pcarlini@unitus.it>
 
        * testsuite/27_io/filebuf_virtuals.cc (test08): Fix for
        unsigned char platforms.
index e9919896914da97953376cb1e6d05ae5f9224d72..bbcde48e7985a74dba5cd84eabf461dc894f8a96 100644 (file)
@@ -275,9 +275,15 @@ namespace std
          const char_type* __iend;
          __res_type __r = __cvt.out(_M_state_cur, __ibuf, __ibuf + __ilen, 
                                     __iend, __buf, __buf + __blen, __bend);
-         // Result == ok, partial, noconv
-         if (__r != codecvt_base::error)
-           __blen = __bend - __buf;
+
+         if (__r == codecvt_base::ok || __r == codecvt_base::partial)
+            __blen = __bend - __buf;
+         // Similarly to the always_noconv case above.
+         else if (__r == codecvt_base::noconv)
+           {
+             __buf = reinterpret_cast<char*>(__ibuf);
+             __blen = __ilen;
+           }
          // Result == error
          else 
            __blen = 0;
index 8bfeb2eb1db2961fa2ae17262d339881ced31e3f..4e88e36b8831aa6aa23bd421f228100dbb94c7db 100644 (file)
@@ -570,6 +570,46 @@ void test08()
   mb.sputbackc('a');  
 }
 
+class Cvt_to_upper : public std::codecvt<char, char, mbstate_t>
+{
+  bool do_always_noconv() const throw()
+  {
+    return false;
+  }
+};
+
+// libstdc++/9169
+void test09()
+{
+  using namespace std;
+  bool test = true;
+
+  locale c_loc;
+  locale loc(c_loc, new Cvt_to_upper);
+
+  string str("abcdefghijklmnopqrstuvwxyz");
+  string tmp;
+
+  {
+    ofstream out;
+    out.imbue(loc);
+    out.open("filebuf_virtuals-4.txt");
+    copy(str.begin(), str.end(),
+        ostreambuf_iterator<char>(out));
+  }
+
+  {
+    ifstream in;
+    in.open("filebuf_virtuals-4.txt");
+    copy(istreambuf_iterator<char>(in),
+        istreambuf_iterator<char>(),
+        back_inserter(tmp));
+  }
+
+  VERIFY( tmp.size() == str.size() );
+  VERIFY( tmp == str );
+}
+
 main() 
 {
   test01();
@@ -582,5 +622,6 @@ main()
 
   test07();
   test08();
+  test09();
   return 0;
 }