[cfe-dev] Using a enum type for a bitfield

Hordijk, Michael via cfe-dev cfe-dev at lists.llvm.org
Mon Aug 24 13:29:24 PDT 2015


The short question:

Does clang support using an enum as a type for a bit-field?

C11 (6.7.2.1 P 5):

A bit-field shall have a type that is a qualified or unqualified version
of _Bool, signed int, unsigned int, or some other implementation-defined
type.

GCC (at least the latest) supports it:

https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/Structures-unions-enumeratio=>
ns-and-bit-fields-implementation.html

So I'm curious as to whether clang supports it.  I did find this on
bugzilla:

https://llvm.org/bugs/show_bug.cgi?id=3D11272

I'm not sure how hard the documentation system is, but is it time to
create a section in the manual to answer questions like this as they pop
up?

In the absence of documentation, I need to assume that the
implementation does not support it, which would make it undefined
behavior (and then I get to drive that out of the code base).

If the implementation does (or will) support it, then it drops down on
my priority list (I've got much more egregious undefined behaviors to
worry about). :)

- michael




More information about the cfe-dev mailing list