PR 3983, basic_istringstream<unsigned char> fails
Craig Rodrigues
rodrigc@attbi.com
Sun Feb 24 09:37:00 GMT 2002
Hi,
I was looking at PR 3983:
http://gcc.gnu.org/ml/gcc-prs/2001-08/msg00154.html
I modified the testcase, and it fails under gcc 3.1:
================================================================
#include <sstream>
#include <iostream>
#include <exception>
using namespace std;
int
main ()
{
int v;
unsigned char s[2];
s[0] = '1';
s[1] = 0;
try
{
basic_istringstream < unsigned char,
std::char_traits < unsigned char >,
std::allocator < unsigned char > >strm (s);
cout << "---" << endl;
strm >> v;
cerr << "result: " << v << endl;
}
catch (exception & e)
{
cout << e.what () << endl;
}
return 0;
}
================================================================
% ./a.out
St8bad_cast
If I trace the stack:
#0 0x40132811 in __kill () from /lib/libc.so.6
#1 0x4013258d in raise (sig=6) at ../sysdeps/posix/raise.c:27
#2 0x40133bf8 in abort () at ../sysdeps/generic/abort.c:88
#3 0x400626e4 in __cxxabiv1::__terminate(void (*)()) (
handler=0x40133a5c <abort>) at eh_terminate.cc:47
#4 0x40062722 in std::terminate() () at eh_terminate.cc:57
#5 0x400628b5 in __cxa_throw () at eh_throw.cc:77
#6 0x40059003 in std::__throw_bad_cast() () at functexcept.cc:49
#7 0x0804a517 in std::basic_ios<unsigned char, std::char_traits<unsigned char> >::_M_check_facet(std::locale::facet const*) const (
this=0xbffff688, __f=0x0) at basic_ios.h:195
#8 0x0804a967 in std::basic_ios<unsigned char, std::char_traits<unsigned char> >::widen(char) const (this=0xbffff688, __c=32 ' ')
at basic_ios.tcc:120
#9 0x0804a314 in std::basic_ios<unsigned char, std::char_traits<unsigned char> >::init(std::basic_streambuf<unsigned char, std::char_traits<unsigned char> >*) (this=0xbffff688, __sb=0x0) at basic_ios.tcc:157
#10 0x0804a0f2 in basic_istream (this=0xbffff630,
__vtt_parm=0x804ea50, __sb=0x0) at istream:78
#11 0x08049bc1 in basic_istringstream (this=0xbffff630,
__str=@0xbffff620, __mode=8) at sstream:233
#12 0x08049733 in main () at a.cpp:19
The problem seems to be caused by line 157 of basic_ios.tcc:
_M_fill = this->widen(' ');
What is this line doing? Why are we calling widen(char) if
we are using a CharT of unsigned char?
--
Craig Rodrigues
http://www.gis.net/~craigr
rodrigc@attbi.com
More information about the Libstdc++
mailing list