- gdbsupport: ignore -Wenum-constexpr-conversion in enum-flags.h
-
- When building with clang 16, we get:
-
- CXX gdb.o
- In file included from /home/smarchi/src/binutils-gdb/gdb/gdb.c:19:
- In file included from /home/smarchi/src/binutils-gdb/gdb/defs.h:65:
- /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/enum-flags.h:95:52: error: integer value -1 is outside the valid range of values [0, 15] for this enumeration type [-Wenum-constexpr-conversion]
- integer_for_size<sizeof (T), static_cast<bool>(T (-1) < T (0))>::type
- ^
-
- The error message does not make it clear in the context of which enum
- flag this fails (i.e. what is T in this context), but it doesn't really
- matter, we have similar warning/errors for many of them, if we let the
- build go through.
-
- clang is right that the value -1 is invalid for the enum type we cast -1
- to. However, we do need this expression in order to select an integer
- type with the appropriate signedness. That is, with the same signedness
- as the underlying type of the enum.
-
- I first wondered if that was really needed, if we couldn't use
- std::underlying_type for that. It turns out that the comment just above
- says:
-
- /* Note that std::underlying_type<enum_type> is not what we want here,
- since that returns unsigned int even when the enum decays to signed
- int. */
-
- I was surprised, because std::is_signed<std::underlying_type<enum_type>>
- returns the right thing. So I tried replacing all this with
- std::underlying_type, see if that would work. Doing so causes some
- build failures in unittests/enum-flags-selftests.c:
-
- CXX unittests/enum-flags-selftests.o
- /home/smarchi/src/binutils-gdb/gdb/unittests/enum-flags-selftests.c:254:1: error: static assertion failed due to requirement 'gdb::is_same<selftests::enum_flags_tests::check_valid_expr254::archetype<enum_flags<s