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

            Bug ID: 87578
           Summary: attribute transparent_union silently accepted but
                    ignored on typedef
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC (in C mode) silently accepts but discards attribute transparent_union on a
typedef.  The attribute handler is never invoked on the typedef (attributes is
null in decl_attributes when the typedef definition is being processed,
suggesting this is a general problem).

G++ diagnoses the typedef definition with -Wattributes.  Clang diagnoses it in
both C and C++ modes as well, although with -Wignored-attributes:

x.c:13:31: warning: transparent_union attribute can only be applied to a union
definition; attribute ignored [-Wignored-attributes]

$ cat x.c && gcc -S -Wall -Wextra x.c
union __attribute__ ((transparent_union)) A
{
  int *ip;
  double *dp;
};

union B
{
  int *ip;
  double *dp;
};

typedef union __attribute__ ((transparent_union)) B TB;   // silently accepted

void f (union A);
void g (TB);

void h (void)
{
  f ((int*)0);      // okay
  f ((double*)0);   // okay

  g ((int*)0);      // error
  g ((double*)0);   // error
}
x.c: In function ‘h’:
x.c:23:6: error: incompatible type for argument 1 of ‘g’
23 |   g ((int*)0);      // error
   |      ^~~~~~~
   |      |
   |      int *
x.c:16:9: note: expected ‘TB’ {aka ‘union B’} but argument is of type ‘int *’
16 | void g (TB);
   |         ^~
x.c:24:6: error: incompatible type for argument 1 of ‘g’
24 |   g ((double*)0);   // error
   |      ^~~~~~~~~~
   |      |
   |      double *
x.c:16:9: note: expected ‘TB’ {aka ‘union B’} but argument is of type ‘double
*’
16 | void g (TB);
   |         ^~

Reply via email to