https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120009

--- Comment #2 from H. Peter Anvin <hpa at zytor dot com> ---
Very interesting indeed... I just tried it as such:

struct empty_t { }  __attribute__((unused));
typedef struct empty_t empty_t __attribute__((unused));

int foo(empty_t a, int b, int c, empty_t d, int e, int f, int g, int h)
{
    return b+c+e+f+g+h;
}

int bar(int b, int c, int e, int f, int g, int h)
{
    empty_t a, d;
    return foo(a,b,c,d,e,f,g,h);
}

int empty_size(void)
{
    return sizeof(empty_t);
}

empty_t *empty_ptr(void)
{
    static empty_t dummy;
    return &dummy;
}

void set_empty(empty_t *ptr, empty_t x)
{
    *ptr = x;
}

The only issues that I ran into are:

1. &dummy in the case above ends up pointing to a random location in .bss; it
probably would be better to be NULL.
2. __attribute__((unused)) doesn't work as advertised in this case
(__attribute__((unused)) on a type is supposed to quiet the unused warnings for
a "variable", but doesn't seem to do so in the case.

Otherwise it seems to work beautifully. I presume that the above would be minor
tweaks, and don't even prevent using on legacy compilers.

I will file a bug for __attribute__((unused)).

Beautiful!

Reply via email to