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

            Bug ID: 122909
           Summary: Error while type encoding bit-field of _Bool type
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: objc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kaloian at doganov dot org
                CC: iains at gcc dot gnu.org
  Target Milestone: ---

When the type encoder encounters a type containing a _Bool bit-field, it errors
out with the "trying to encode non-integer type as a bit-field".

Minimal reproduction case:

$ cat > foo.m <<EOF
typedef struct {
  _Bool b: 1;
} Body;

int
main (void)
{
  @encode (Body);
  return 0;
}
EOF

$ make LDLIBS=-lobjc foo
cc     foo.m  -lobjc -o foo
foo.m: In function ‘main’:
foo.m:8:3: error: trying to encode non-integer type as a bit-field
    8 |   @encode (Body);
      |   ^
make: *** [<builtin>: foo] Error 1

I am using a recent GCC 16 from trunk:

$ gcc -v
Using built-in specs.
COLLECT_GCC=/home/kaloian/opt/gcc-objc-encode-baseline/bin/gcc
COLLECT_LTO_WRAPPER=/home/kaloian/opt/gcc-objc-encode-baseline/libexec/gcc/aarch64-unknown-linux-gnu/16.0.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: ../../gcc/configure --enable-languages=c,c++,objc,obj-c++,lto
--prefix=/home/kaloian/opt/gcc-objc-encode-baseline
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20251127 (experimental) (GCC)

The same problem is reproducible also with GCC 14 and likely exists in even
earlier versions.

Perhaps since I don't know any better, I don't see a good reason why _Bool
bit-fields shouldn't be encoded. So I'll propose a patch soon.

Reply via email to