Subject: Re: [boost] [locale] review
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-04-16 18:38:56


AMDG

On 04/16/2011 03:02 PM, Phil Endecott wrote:
> I note that a union is being used in what I believe is an undefined way:
>
> union {
> char first;
> uint16_t u16;
> uint32_t u32;
> } v;
>
> v.u16 = 1;
> if(v.first == 1) {
> return "UTF-16LE";
> }
> else {
> return "UTF-16BE";
> }
>

char is a special case (3.10):

If a program attempts to access the stored value of an
object through an lvalue of other than one of the
following types the behavior is undefined:

-- the dynamic type of an object
...
-- a char or unsigned char type

> There seems to be some use of reinterpret_cast which I think should be a
> static_cast via void*:
>
> virtual std::string convert(char_type const *ubegin,char_type const
> *uend)
> {
> ....
> char const *begin = reinterpret_cast<char const *>(ubegin);
>

Under the new standard reinterpret_cast is correct.
Under the current standard it's implementation defined,
and correct for all existing implementations.

In Christ,
Steven Watanabe