[PATCH] linux: Fix integer overflow warnings when including <sys/mount.h> [BZ #32708]
Collin Funk
collin.funk1@gmail.com
Tue Mar 25 19:42:06 GMT 2025
Florian Weimer <fweimer@redhat.com> writes:
> I believe unsigned enum types are still a GNU extension, but maybe
> <sys/mount.h> isn't expected to be processed with compilers without such
> extensions.
I don't think that unsigned enums are a GNU extension. In C99 section
6.7.2.2 [1]:
Each enumerated type shall be compatible with char, a signed integer
type, or an unsigned integer type. The choice of type is
implementation-defined, 110) but shall be capable of representing the
values of all the members of the enumeration. The enumerated type is
incomplete until after the } that terminates the list of enumerator
declarations.
And subscript 110:
An implementation may delay the choice of which integer type until
all enumeration constants have been seen.
This definition taken from Gnulib is a good demonstration of this:
typedef enum
{
_Bool_must_promote_to_int = -1,
false = 0,
true = 1
} _Bool;
Without _Bool_must_promote_to_int the compiler is free to chose
'unsigned int' as the type for the enum, which is unwanted in this case.
Collin
[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
More information about the Libc-alpha
mailing list