This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: Update Intel386, x86-64 and IA MCU psABIs for passing/returning empty struct
- From: Matthijs van Duin <matthijsvanduin at gmail dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Richard Smith <richard at metafoo dot co dot uk>, Jonathan Wakely <jwakely dot gcc at gmail dot com>, GCC Development <gcc at gcc dot gnu dot org>, cfe-commits <cfe-commits at lists dot llvm dot org>
- Date: Thu, 11 Feb 2016 11:47:29 +0100
- Subject: Re: RFC: Update Intel386, x86-64 and IA MCU psABIs for passing/returning empty struct
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOrsV-zohnj=31_DDYSxUDyRDYL0anTi_NJm5vqogF9URQ at mail dot gmail dot com> <CAH6eHdQtnzMO6gLLRsczDdvmx0exkqXxyY-WvZ6RjuM7a3=85A at mail dot gmail dot com> <CAH6eHdQQjpOwD2kNCZVjH+w6N0Wh=gbdaaCcjg21iEbaHaAE5A at mail dot gmail dot com> <CAMe9rOq5QL9J0F-isO1njJyDJcZ08gF4zUk4vXNONWSfUtSzwA at mail dot gmail dot com> <CAH6eHdR0vJkYuYeKU=zyhthOY0KT-m8C=m2AtZ5GfVeyPOA=jw at mail dot gmail dot com> <CAOfiQqmKnONCdEi=coKaAKO_0Ux5X1BdYZ5t98gCU+LN21xKvw at mail dot gmail dot com> <CAH6eHdTxMXA7BEEHB7y6c5dRG_Hur5=CmdrQWMRn3zRGHnGZuA at mail dot gmail dot com> <CAMe9rOr9CCDjVVdYq7SoCDewg6uLnegEvT3Rrf2jg05SSyM_GQ at mail dot gmail dot com> <CAOfiQqnK-MFNhjcnHPPBpFfcJxR5rkdj26x8HcfMOiibCtevXA at mail dot gmail dot com> <CAMe9rOpM5Cs4zthCTAyaBEx3TWAQ7QNKv=k9mrqNzvj-upGcUw at mail dot gmail dot com>
On 8 February 2016 at 22:40, H.J. Lu <hjl.tools@gmail.com> wrote:
> "empty type". An empty type is either an array of empty types or a
> class type where every member is of empty type.
Note that the term "empty type" is commonly used in type theory to
denote a (or the) type with no values. The closest thing C has would be
an empty enum when using -fstrict-enums. (Declaring it as return type
implies [[noreturn]] or undefined behaviour.)
A type with a unique value (such as void or an empty struct) is usually
known as a unit type.
BTW, being standard layout is not sufficient (nor required afaict) for
zero-register passing of a unit type. The requirement you need is
trivially-copyable. Example:
#include <map>
#include <iostream>
#include <type_traits>
using namespace std;
class EmptyInt {
static map< const EmptyInt *, int > values;
public:
EmptyInt() = default;
EmptyInt( int x ) { values[this] = x; }
~EmptyInt() { values.erase(this); }
operator int () const { return values[this]; }
};
typeof( EmptyInt::values ) EmptyInt::values;
EmptyInt foo() {
return 42;
}
int main() {
cout << is_standard_layout<EmptyInt>{} << endl;
cout << foo() << endl;
return 0;
}
This evil contraption satisfies all POD-requirements except for not
being trivially-copyable. On the other hand taking this example from
http://en.cppreference.com/w/cpp/concept/StandardLayoutType
struct Q {};
struct S : Q {};
struct T : Q {};
struct U : S, T {}; // not a standard-layout class
Even though U is not standard-layout, it is trivially-copyable and I see
no reason to allocate a register to pass it.
Matthijs van Duin