This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PING^1: [PATCH] Add TYPE_EMPTY_RECORD for C++ empty class
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Joseph Myers <joseph at codesourcery dot com>, Ulrich Weigand <uweigand at de dot ibm dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Jakub Jelinek <jakub at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, Markus Trippelsdorf <markus at trippelsdorf dot de>
- Date: Wed, 16 Mar 2016 07:48:15 -0700
- Subject: Re: PING^1: [PATCH] Add TYPE_EMPTY_RECORD for C++ empty class
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOrx2TKEnBsSzCkB6eB33FjsaFoyKqx68D=jgNzxjhNHng at mail dot gmail dot com> <20160302162538 dot 66068C88E at oc7340732750 dot ibm dot com> <CAMe9rOqF-B-he1JWaxq5++1a75vKtpECRAgcMDd+EbjdxQzLdQ at mail dot gmail dot com> <56E82BC4 dot 7070401 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1603152138570 dot 17533 at digraph dot polyomino dot org dot uk> <CAMe9rOq-EmEDSOvo-ycJ2PkZZyupcLVbTpEumKMAfQos2=8TKw at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1603152233290 dot 17533 at digraph dot polyomino dot org dot uk> <CAMe9rOoVmuEZC8tK7Bqg5gMdsCxXxJqsjNc6WZ1fvrxogSSvyg at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1603160024540 dot 17533 at digraph dot polyomino dot org dot uk> <56E8CA16 dot 2040206 at redhat dot com> <CAMe9rOr=0w5t_qda-E9SXy0cMVSrynU1gp3g6PuLNevihiu=KQ at mail dot gmail dot com> <56E96EAB dot 8040603 at redhat dot com>
On Wed, Mar 16, 2016 at 7:33 AM, Jason Merrill <jason@redhat.com> wrote:
> On 03/16/2016 07:55 AM, H.J. Lu wrote:
>>
>> On Tue, Mar 15, 2016 at 7:51 PM, Jason Merrill <jason@redhat.com> wrote:
>>>
>>> On 03/15/2016 08:25 PM, Joseph Myers wrote:
>>>>
>>>>
>>>> On Tue, 15 Mar 2016, H.J. Lu wrote:
>>>>
>>>>> On Tue, Mar 15, 2016 at 3:34 PM, Joseph Myers <joseph@codesourcery.com>
>>>>> wrote:
>>>>>>
>>>>>>
>>>>>> On Tue, 15 Mar 2016, H.J. Lu wrote:
>>>>>>
>>>>>>> On Tue, Mar 15, 2016 at 2:39 PM, Joseph Myers
>>>>>>> <joseph@codesourcery.com>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> I'm not sure if the zero-size arrays (a GNU extension) are
>>>>>>>> considered
>>>>>>>> to
>>>>>>>> make a struct non-empty, but in any case I think the tests should
>>>>>>>> cover
>>>>>>>> such arrays as elements of structs.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> There are couple tests for structs with members of array
>>>>>>> of empty types. testsuite/g++.dg/abi/empty14.h has
>>>>>>
>>>>>>
>>>>>>
>>>>>> My concern is the other way round - structs with elements such as
>>>>>> "int a[0];", an array [0] of a nonempty type. My reading of the
>>>>>> subobject
>>>>>> definition is that such an array should not cause the struct to be
>>>>>> considered nonempty (it doesn't result in any int subobjects).
>>>>>
>>>>>
>>>>>
>>>>> This is a test for struct with zero-size array, which isn't treated
>>>>> as empty type. C++ and C are compatible in its passing.
>>>>
>>>>
>>>>
>>>> Where is the current definition of empty types you're proposing for use
>>>> in
>>>> GCC? Is the behavior of this case clear from that definition?
>>>
>>>
>>>
>>> "An empty type is a type where it and all of its subobjects (recursively)
>>> are of structure, union, or array type. No memory slot nor register
>>> should
>>> be used to pass or return an object of empty type."
>>>
>>> It seems to me that such a struct should be considered an empty type
>>> under
>>> this definition, since a zero-length array has no subobjects.
>>
>>
>> Since zero-size array is GCC extension, we can change it. Do we
>> want to change its passing for C?
>
>
> I would think so; it seems to follow clearly from this definition. I have
> trouble imagining that anyone would ever pass an object containing a
> zero-length array by value, so it shouldn't matter much either way, but I
> consistency is good.
>
This requires change in both C and C++ frontends.
--
H.J.