Closed
Description
When specifying -fshort-enums
in the command line or marking an enum with __attribute__((packed))
, the size of the enum should be smaller than an int
if all the values in the enum fit in a short
or a char
, however the size of the enum is 4 bytes.
I'm facing this issue on the LLVM 17.0.3 Win32 builds.
Repro
main.c:
#include <assert.h>
enum __attribute__((packed)) BYTE_ENUM {
A = 0,
B = 1
};
static_assert(sizeof(enum BYTE_ENUM) == 1, "Size of BYTE_ENUM should be 1 byte.");
Command line: clang main.c -fshort-enums
(or clang main.c
since we are adding the attribute to the enum anyway)