[Boost-bugs] [Boost C++ Libraries] #5644: tellg returns different results for gnu libstd++ and others standard libraries for codecvt_null

Subject: [Boost-bugs] [Boost C++ Libraries] #5644: tellg returns different results for gnu libstd++ and others standard libraries for codecvt_null
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-06-27 11:04:14


#5644: tellg returns different results for gnu libstd++ and others standard
libraries for codecvt_null
----------------------------------+-----------------------------------------
 Reporter: Michael.Kv@… | Owner: ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
  Version: Boost 1.46.1 | Severity: Problem
 Keywords: |
----------------------------------+-----------------------------------------
 I believe the tellg funtion below shall return the stream position 2 after
 reading single wide character and it does so for non-gnu standard library.
 But it returs 1 instead for gnu libstd++ (mingw 4.5.2) though as you may
 see the wifstream::read call reads two bytes indeed. You may also see that
 subsequent read operations will be incorrect -- you will get 5bff instead
 of 005b.

 You may also want to take
 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49269 into consideration.

 --

 Michael Kochetkov
 {{{
 #include <fstream>
 #include <iostream>
 #include <stdexcept>
 #include <boost/archive/codecvt_null.hpp>

 int
 main() {
         try {
                 std::wifstream is;
                 is.imbue(std::locale(std::locale::classic(), new
 boost::archive::codecvt_null<wchar_t>()));
                 is.exceptions(std::ios::badbit);
                 // Samples.txt shall look in hex like this:
                 // FEFF 005B 0030 0020 ¦ 0020 0020 0031 005D | ?[0 1]
                 is.open("samples.txt",std::ios::in | std::ios::binary);
                 unsigned int bom = 0;
                 is.read(reinterpret_cast<wchar_t*>(&bom),1);
                 const unsigned short bomLE = 0xFEFF;
                 if (bom != bomLE) {
                         throw std::runtime_error("Invalid BOM. Only LE is
 supported");
                 }
                 std::cout << "Current position: " << is.tellg() <<
 std::endl;
         }
         catch(const std::exception& e) {
                 std::cout << e.what() << std::endl;
         }
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5644>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC