[RFC] A QoI problem with filebuf and POD charT != char, wchar_t
Pétur Runólfsson
peturr02@ru.is
Wed May 19 19:11:00 GMT 2004
Paolo Carlini wrote:
> std::basic_ofstream<int, std::char_traits<int> > out;
[...]
> out.write(&i, 1);
[...]
> In particular both the 'write' and the 'close' fail. Why?
>
> Basically, because of this kind of check
>
> __check_facet(_M_codecvt).always_noconv()
>
> present both in xsputn and in _M_convert_to_external (and in underflow):
> _M_codecvt is a NULL pointer for charT == int and __check_facet throws.
The standard says that codecvt must be obtained "as if" by:
codecvt<charT,char,typename traits::state_type> a_codecvt =
use_facet<codecvt<charT,char,typename traits::state_type> >(getloc());
This fragment will cause bad_cast to be thrown if getloc() doesn't
contain the correct codecvt, so it seems that the current behaviour is
required by the standard.
Petur
More information about the Libstdc++
mailing list