[llvm-dev] GCC 5 and -Wstrict-aliasing in JSON.h

Kim Gräsman via llvm-dev llvm-dev at lists.llvm.org
Fri Aug 10 14:30:37 PDT 2018


On Fri, Aug 10, 2018 at 6:08 PM, Sam McCall <sam.mccall at gmail.com> wrote:
> json::Value in JSON.h is a discriminated union.
> The storage is a char array of appropriate type and alignment. The storage
> holds one object at a time, it's initialized (and for nontrivial types,
> destroyed) at the right times to ensure this. The cast is only to the type
> of object that's already there, there's no magic here.
>
>
> On Fri, Aug 10, 2018, 17:52 Andrew Haley <aph at redhat.com> wrote:
>>
>> Not exactly.  You can cast a pointer to a pointer to some character
>> type or the type of the object stored in memory.  It does not matter
>> whether you use an intermediate type or not.  Having not seen the test
>> case, I can't tell whether this rule is followed.

Yes, if Andrew's explanation agrees with the standard, then this code
should be benign (if it breaks any of these rules, that's a bug in and
of itself).

So maybe we're back to figuring out how to silence GCC's warning machinery :)

- Kim


More information about the llvm-dev mailing list