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: Tue, 21 Jan 2020 02:03:09 -0800
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <86r1ztjfdu.fsf@linuxsc.com>
References: <490dd5d6-fb8a-482b-a88d-550b8a4defd0@googlegroups.com> <86d0bq2fmi.fsf@linuxsc.com> <140b2e3a-cc88-45f9-a292-efd471e3c789@googlegroups.com> <86r203guiq.fsf@linuxsc.com> <2e087cbf-8a15-4109-b199-f200487745f6@googlegroups.com> <86a76qgin8.fsf@linuxsc.com> <21725e19-05c0-4267-be45-a9aa249ce436@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="d01dc2e4789bccc98e4eaed72337c14b"; logging-data="26349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Fz+Ylej+bzH1TyAKoldmWussMUE60074="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:qzXKgX1a9zxopqWwHt8hZsSoKx8= sha1:3hJV9sOI1ner827P0DuHY3hCS00=
Xref: csiph.com comp.lang.c++:71480
Tiib writes:
> On Tuesday, 14 January 2020 17:30:46 UTC+2, Tim Rentsch wrote:
>
>> Tiib writes:
>>
>>> On Monday, 13 January 2020 19:02:00 UTC+2, Tim Rentsch wrote:
>>
>> [context: this code
>>
>> struct base {
>> int p0;
>> };
>>
>> struct object_0 {
>> base b;
>> int p0;
>> };
>>
>> ]
>>
>>>> The first member of struct base is of type 'int'. The first member of
>>>> struct object_0 is of type 'base'. The two types, 'int' and 'base',
>>>> are not layout compatible. Do you agree or disagree?
>>>
>>> I disagree. The address of base is required to be address of int as
>>> well as first element of base so these are layout compatible.
>>
>> In N4659, section 6.9 paragraph 11 defines the term 'layout
>> compatible'. The definition says (leaving out the cv's) that two
>> types T1 and T2 are layout compatible if
>>
>> (a) T1 and T2 are the same type,
>>
>> (b) T1 and T2 are layout-compatible enumerations, or
>>
>> (c) T1 and T2 are layout-compatible standard-layout class types.
>>
>> When T1 is 'int' and T2 is 'base' (aka 'struct base'), which of these
>> categories do you think applies?
>
> T1 is also 'base' so (a) applies.
No, it isn't. It appears that either you haven't been listening
or you aren't thinking clearly.