binutils-gdb/include
Simon Marchi ae61525fcf 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
    elftests::enum_flags_tests::RE>, selftests::enum_flags_tests::RE, enum_flags<selftests::enum_flags_tests::RE2>, selftests::enum_flags_tests::RE2, enum_flags<selftests::enum_flags_tests::URE>, selftests::enum_fla
    gs_tests::URE, int>, selftests::enum_flags_tests::check_valid_expr254::archetype<enum_flags<selftests::enum_flags_tests::RE>, selftests::enum_flags_tests::RE, enum_flags<selftests::enum_flags_tests::RE2>, selfte
    sts::enum_flags_tests::RE2, enum_flags<selftests::enum_flags_tests::URE>, selftests::enum_flags_tests::URE, unsigned int>>::value == true':
    CHECK_VALID (true,  int,  true ? EF () : EF2 ())
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/unittests/enum-flags-selftests.c:91:3: note: expanded from macro 'CHECK_VALID'
      CHECK_VALID_EXPR_6 (EF, RE, EF2, RE2, UEF, URE, VALID, EXPR_TYPE, EXPR)
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/valid-expr.h:105:3: note: expanded from macro 'CHECK_VALID_EXPR_6'
      CHECK_VALID_EXPR_INT (ESC_PARENS (typename T1, typename T2,           \
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/valid-expr.h:66:3: note: expanded from macro 'CHECK_VALID_EXPR_INT'
      static_assert (gdb::is_detected_exact<archetype<TYPES, EXPR_TYPE>,    \
      ^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is a bit hard to decode, but basically enumerations have the
following funny property that they decay into a signed int, even if
their implicit underlying type is unsigned.  This code:

    enum A {};
    enum B {};

    int main() {
      std::cout << std::is_signed<std::underlying_type<A>::type>::value
                << std::endl;
      std::cout << std::is_signed<std::underlying_type<B>::type>::value
                << std::endl;
      auto result = true ? A() : B();
      std::cout << std::is_signed<decltype(result)>::value << std::endl;
    }

produces:

    0
    0
    1

So, the "CHECK_VALID" above checks that this property works for enum flags the
same way as it would if you were using their underlying enum types.  And
somehow, changing integer_for_size to use std::underlying_type breaks that.

Since the current code does what we want, and I don't see any way of doing it
differently, ignore -Wenum-constexpr-conversion around it.

Change-Id: Ibc82ae7bbdb812102ae3f1dd099fc859dc6f3cc2
2023-03-06 21:00:52 -05:00
..
aout Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
cgen Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
coff Fix size of external_reloc for pe-aarch64 2023-01-10 23:30:42 +00:00
elf bfd: use "stack trace" instead of "unwind" for SFrame 2023-02-02 00:49:29 -08:00
gdb Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
mach-o Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
opcode bpf: fix error conversion from long unsigned int to unsigned int [-Werror=overflow] 2023-02-03 11:18:50 -06:00
sim sim: info: convert verbose field to a bool 2023-01-18 20:47:55 -05:00
som Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
vms Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
alloca-conf.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
ansidecl.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
bfdlink.h ppc32 and "LOAD segment with RWX permissions" 2023-02-06 23:06:44 +10:30
binary-io.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
bout.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
ChangeLog Add new NT_ARM_ZA and NT_ARM_SSVE register set constants. 2023-01-03 11:15:26 +00:00
ChangeLog-0415 binutils ChangeLog rotation 2016-01-01 22:59:17 +10:30
ChangeLog-2016 ChangeLog rotation 2017-01-02 13:55:05 +10:30
ChangeLog-2017 ChangeLog rotation 2018-01-03 17:49:42 +10:30
ChangeLog-2018 ChangeLog rotation 2019-01-01 21:25:40 +10:30
ChangeLog-2019 ChangeLog rotation 2020-01-01 18:12:08 +10:30
ChangeLog-2020 ChangeLog rotation 2021-01-01 10:31:02 +10:30
ChangeLog-9103 Add copyright notices 2012-12-10 12:48:03 +00:00
collectorAPI.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
COPYING
COPYING3
ctf-api.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
ctf.h ctf: fix various dreadful typos in the ctf_archive format comments 2023-01-12 14:40:47 +00:00
demangle.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
diagnostics.h gdbsupport: ignore -Wenum-constexpr-conversion in enum-flags.h 2023-03-06 21:00:52 -05:00
dis-asm.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
dwarf2.def Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
dwarf2.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
dyn-string.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
environ.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
fibheap.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
filenames.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
floatformat.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
fnmatch.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
fopen-bin.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
fopen-same.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
fopen-vms.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
gcc-c-fe.def Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
gcc-c-interface.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
gcc-cp-fe.def Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
gcc-cp-interface.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
gcc-interface.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
getopt.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
hashtab.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
hp-symtab.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
leb128.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
libcollector.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
libfcollector.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
libiberty.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
longlong.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
lto-symtab.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
MAINTAINERS Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
md5.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
oasys.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
objalloc.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
obstack.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
os9k.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
partition.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
plugin-api.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
safe-ctype.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
sframe-api.h sframe: fix the defined SFRAME_FRE_TYPE_*_LIMIT constants 2023-01-06 09:30:56 -08:00
sframe.h sframe: use "stack trace" instead of "unwind" for SFrame 2023-02-02 00:47:38 -08:00
sha1.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
simple-object.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
sort.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
splay-tree.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
symcat.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
timeval-utils.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
vtv-change-permission.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
xregex2.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
xregex.h merge from gcc 2011-07-25 17:11:48 +00:00
xtensa-config.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
xtensa-dynconfig.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
xtensa-isa-internal.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
xtensa-isa.h Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30