Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: Union type punning in C++ Date: Mon, 13 Jan 2020 08:37:32 -0800 Organization: A noiseless patient Spider Lines: 24 Message-ID: <86zhergvn7.fsf@linuxsc.com> References: <868sme2err.fsf@linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="3f3153150e66f3eb10123de9932e6704"; logging-data="9004"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DnqTYpM0r7RPZEhbgyLzlyRUqqG7CMXo=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:QabQDIqv12EjlQ47okEYlMqXsB8= sha1:RpXz5AjyMnmYALFmjYhaC+TigGY= Xref: csiph.com comp.lang.c++:71305 "Chris M. Thomasson" writes: > On 1/11/2020 7:28 AM, Tim Rentsch wrote: > >> "Chris M. Thomasson" writes: >> >>> Is there some cryptic hidden thing in the standard that just might >>> "allow" for the following code to run without ub? >>> >>> [example removed] >> >> I believe this runs afoul of the rules for common initial >> sequences, because type 'base' has as its first member a type >> that is not layout compatible with the type of the first members >> of object_0 and object_1. > > Everything boils down to an int. Therefore, the common initial > sequence is an int. It should work. Its all POD, everything has that > common int, even in struct base. Afaict, The first int, in base, or > anything in union object has the same address. union object::b has the > same address as union object::o1::base. Its all POD. I see you have gotten some further guidance on this matter. I will respond further to your posting downstream.