Boost logo

Boost Users :

Subject: Re: [Boost-users] [Spirit] dereferencing type-punned pointer will break strict-aliasing rules
From: Emil Dotchevski (emil_at_[hidden])
Date: 2010-08-12 18:53:11

On Thu, Aug 12, 2010 at 11:37 AM, Frank Mori Hess <frank.hess_at_[hidden]> wrote:
> Hash: SHA1
> On Thursday 12 August 2010, Emil Dotchevski wrote:
>> 2)
>> strict aliasing rules should not apply to char pointers (as far as I
>> can tell, is of char type specifically to deal with
>> this issue.)
> It's safe to cast to a char pointer and use the char pointer, but in this case
> you are casting away from a char pointer.  Bouncing a non-char pointer
> through a char pointer doesn't give any relief from the usual strict aliasing
> rules.

The object is not accessed through a char pointer, the char pointer is
only used to define a memory location. The char object itself is used
only to take its address.

Even if the warning was valid, it just means that *if* you access the
same object through different types (which the code never does), you'd
be in trouble; however section 6.5, paragraph 7 of the C standard says
that any object may be aliased by an object of type char, so the
warning seems invalid.

Emil Dotchevski
Reverge Studios, Inc.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at