This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
RE: [RFC] A QoI problem with filebuf and POD charT != char, wchar_t
- From: Pétur Runólfsson <peturr02 at ru dot is>
- To: "Paolo Carlini" <pcarlini at suse dot de>,"libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 19 May 2004 19:11:43 -0000
- Subject: RE: [RFC] A QoI problem with filebuf and POD charT != char, wchar_t
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