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

            Bug ID: 116302
           Summary: transparent union does not work with {integral type,
                    bitfield struct}
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hpa at zytor dot com
  Target Milestone: ---

Created attachment 58879
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58879&action=edit
Reproducer (C source)

Bitfields are not portable, and some compilers generate truly awful code when
using them. Furthermore, it is fairly common to want to be able to do bit
operations that cross bitfields.

However, because bitfields are not portable in general, using a union type for
this is not safe.

As such, for both debugging and portability, it is desirable to be able to
treat an integer type of some kind as a union with a bitfield on gcc, while
letting inferior compilers define the type as a simple integral type.

Unfortunately, this does not appear to work, even when the "union cannot be
made transparent" error does not appear:

transp.c:30:22: warning: missing braces around initializer [-Wmissing-braces]
   30 | opflags_t hello[2] = {
      |                      ^
transp.c: In function ‘antiop’:
transp.c:37:12: error: wrong type argument to bit-complement
   37 |     return ~op;
      |            ^
transp.c:38:1: warning: control reaches end of non-void function
[-Wreturn-type]
   38 | }
      | ^

Reproducer included.

Tested on gcc 14.2.1, Fedora 40, x86-64:

gcc version 14.2.1 20240801 (Red Hat 14.2.1-1) (GCC)
gcc-14.2.1-1.fc40.x86_64

Reply via email to