This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Passing empty "tag" structs
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: David Brown <david at westcontrol dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 7 Sep 2018 09:10:38 +0100
- Subject: Re: Passing empty "tag" structs
- References: <f4e2b606-b13e-3140-e6a7-9fbc6ab7a574@westcontrol.com>
On Fri, 7 Sep 2018 at 08:06, David Brown wrote:
>
> In C++ programming, it is sometimes helpful to have empty structs acting
> as tags. An example is "struct nothrow_t {}".
>
> When parameters of these types - such as "nothrow", are passed to
> functions the compiler passes them as a value 0. Since the type cannot
> hold any kind of value, surely it could be passed without any value at
> all being placed in the corresponding parameter register or stack slot?
> Or do the rules of C++ require a value here?
The ABI dictates it, and in GCC 8 it was fixed, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60336
> Going one step further, if a function takes empty tag parameters such as:
>
> foo(tag1_t, tag2_t, int x);
>
> the first two parameters take up valuable register (or stack) slots for
> no useful information. Could this function be mangled to be, in effect:
>
> foo__tag1_t__tag2_t(int x);
No, the ABI also dictates how to mangle functions.