This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Update Intel386, x86-64 and IA MCU psABIs for passing/returning empty struct

On 8 February 2016 at 22:40, H.J. Lu <> 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;

		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

	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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]