[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc
Subject:    Re: RFC: Update Intel386, x86-64 and IA MCU psABIs for passing/returning empty struct
From:       "H.J. Lu" <hjl.tools () gmail ! com>
Date:       2016-02-20 19:34:16
Message-ID: CAMe9rOoUL8qjONwjFoqKP3a2bVX0--0Z414oYDoggs=iOEwPyg () mail ! gmail ! com
[Download RAW message or body]

On Sat, Feb 20, 2016 at 10:50 AM, Matthijs van Duin
<matthijsvanduin@gmail.com> wrote:
> On 20 February 2016 at 18:55, H.J. Lu <hjl.tools@gmail.com> wrote:
>> struct dummy0
>> {
>> };
>>
>> struct dummy
>> {
>>   dummy0 d[20];
>>
>>   dummy0 * foo (int i);
>> };
>>
>> dummy0 *
>> dummy::foo (int i)
>> {
>>   return &d[i];
>> }
>>
>> dummy0 *
>> bar (dummy d, int i)
>> {
>>   return d.foo (i);
>> }
>
> 1. This has undefined behaviour due to returning a pointer to a local variable
> 2. There's still no need for the reference to the original argument
> since copying it is a nop.

Given:

An empty type is a type where it and all of its subobjects (recursively)
are of class, structure, union, or array type.  No memory slot nor register
should be used to pass or return an object of empty type.

Footnote: Array of empty type can only passed by reference in C and C++.

Is there a class, which meets the above definition,  with a member function
which can't be passed without a memory slot or a register?

-- 
H.J.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic