Fixed all clang -Wsigned-enum-bitfield warnings (#2882)

Made enums involved in bitfields unsigned by specifying their underlying type as unsigned char.

Due to a bug, when specifying an underlying type, gcc < 9.3 warns about bitfields not being big enough to hold the enum, even though they are. So keep the plain enum for old gcc.

An example of the bug is here:

https://godbolt.org/z/58aEv8zEq
This commit is contained in:
Sean McBride 2022-05-09 14:03:51 -04:00 committed by GitHub
parent 7e4ad40171
commit f63afd161f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2029,14 +2029,23 @@ template <typename Context> class basic_format_args {
// between clang and gcc on ARM (#1919). // between clang and gcc on ARM (#1919).
using format_args = basic_format_args<format_context>; using format_args = basic_format_args<format_context>;
// We cannot use enum classes as bit fields because of a gcc bug // We cannot use enum classes as bit fields because of a gcc bug,
// so we put them in namespaces instead.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414.
// Additionally, if an underlying type is specified, older gcc incorrectly warns
// that the type is too small for all the enum values.
// Both these bugs are fixed as of gcc 9.3.
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 903
# define FMT_ENUM_UNDERLYING_TYPE(type)
#else
# define FMT_ENUM_UNDERLYING_TYPE(type) : type
#endif
namespace align { namespace align {
enum type { none, left, right, center, numeric }; enum type FMT_ENUM_UNDERLYING_TYPE(unsigned char) { none, left, right, center, numeric };
} }
using align_t = align::type; using align_t = align::type;
namespace sign { namespace sign {
enum type { none, minus, plus, space }; enum type FMT_ENUM_UNDERLYING_TYPE(unsigned char) { none, minus, plus, space };
} }
using sign_t = sign::type; using sign_t = sign::type;