This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Incorrect char extraction code
- To: Jason Merrill <jason at redhat dot com>
- Subject: Re: Incorrect char extraction code
- From: Phil Edwards <pedwards at disaster dot jaj dot com>
- Date: Mon, 5 Feb 2001 14:48:16 -0500
- Cc: "Rosen, Hyman" <Hyman dot Rosen at kbcfp dot com>, "'libstdc++ at gcc dot gnu dot org'" <libstdc++ at gcc dot gnu dot org>
- References: <415C10091CFFD21193A50060083606C601AE3526@msny2.nyc.kbcfp.com> <u9hf2igvqn.fsf@casey.cambridge.redhat.com>
On Tue, Jan 30, 2001 at 09:22:48AM +0000, Jason Merrill wrote:
> >>>>> "Rosen," == Rosen, Hyman <Hyman.Rosen@kbcfp.com> writes:
>
> > std_istream.h has the following pair of templates:
> > template<class _Traits>
> > basic_istream<char, _Traits>&
> operator> (basic_istream<char, _Traits>& __in, unsigned char& __c)
> > { return (__in >> static_cast<char>(__c)); }
>
> > template<class _Traits>
> > basic_istream<char, _Traits>&
> operator> (basic_istream<char, _Traits>& __in, signed char& __c)
> > { return (__in >> static_cast<char>(__c)); }
>
> > These are clearly wrong; the result of a static_cast<char> is not an
> > lvalue, so code that tries an extraction into a signed or unsigned char
> > shouldn't even compile. Those casts need to be reinterpret_cast<char &>,
>
> Yes.
Before I make that change... why *does* the code compile? I can successfully
perform extractions into a signed or unsigned char presently. (Which is
wrong, as you say; I just want to know why we're allowing it.)
Phil
--
pedwards at disaster dot jaj dot com | pme at sources dot redhat dot com
devphil at several other less interesting addresses in various dot domains
The gods do not protect fools. Fools are protected by more capable fools.