This is the mail archive of the libstdc++@sources.redhat.com 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]

Re: SEGV fault when using wchar_t streams


Did anybody else try this out?  Is this the correct group to post bugs to?
 
I now have a temporary fix for this.  If I add a line before (5):
    5      std::wcout.width(1);
 
setting the width to 1 prior to outputing the wchar_t fixes the problem.
 
I stumbled on the width fix by stepping through the code with gdb.  I was surprised
to see that a line in bits/ostream.tcc initialising __w was not executed (the debugger jumped over it).  Why would this be?
 
 template<typename _CharT, typename _Traits>
    basic_ostream<_CharT, _Traits>&
    operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
    {
      typedef basic_ostream<_CharT, _Traits> __ostream_type;
      __ostream_type::sentry __cerb(__out);
      if (__cerb)
     {
       try {
         streamsize __w = __out.width();              <<<<--- debugger jumps over this line
         _CharT __pads[__w];
         __pads[0] = __c;
         streamsize __len = 1;
         if (__w > __len)
           {
      _S_pad_char(__out, __pads, &__c, __w, __len);
      __len = __w;
           }
         __out.write(__pads, __len);
         __out.width(0);
       }
       catch(exception& __fail){
         // 27.6.1.2.1 Common requirements.
         // Turn this on without causing an ios::failure to be thrown.
         __out.setstate(ios_base::badbit);
         if ((__out.exceptions() & ios_base::badbit) != 0)
           throw;
       }
     }
      return __out;
    }
 
 
 
>I compile the following program with ./g++ -fhonor-std
>
>      1 #include <iostream>
>      2 int main(int argc, char* argv[])
>      3 {
>      4     std::wcout << L"H";
>      5     std::wcout << L'i' << std::ends << std::endl;    // This appears to be the problem line
>      6     std::wcout << L"This is going to die - bye" << std::endl;
>      7 }
 

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