From: Tom de Vries Date: Thu, 17 Aug 2023 08:41:34 +0000 (+0200) Subject: [gdb/build, c++20] Fix Wdeprecated-enum-enum-conversion X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=24a601dd70a53fc87f33196774f8d883be31d2fe;p=binutils-gdb.git [gdb/build, c++20] Fix Wdeprecated-enum-enum-conversion When building gdb with clang 15 and -std=c++20, I run into: ... gdbsupport/common-exceptions.h:203:32: error: arithmetic between different \ enumeration types ('const enum return_reason' and 'const enum errors') is \ deprecated [-Werror,-Wdeprecated-enum-enum-conversion] size_t result = exc.reason + exc.error; ~~~~~~~~~~ ^ ~~~~~~~~~ ... Fix this by using to_underlying. Likewise in a few other places. Tested on x86_64-linux. --- diff --git a/gdb/remote.c b/gdb/remote.c index 6fefabac0ce..e01da795ec8 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -10850,7 +10850,8 @@ remote_target::insert_watchpoint (CORE_ADDR addr, int len, char *p; enum Z_packet_type packet = watchpoint_to_Z_packet (type); - if (m_features.packet_support (PACKET_Z0 + packet) == PACKET_DISABLE) + if (m_features.packet_support ((to_underlying (PACKET_Z0) + + to_underlying (packet))) == PACKET_DISABLE) return 1; /* Make sure the remote is pointing at the right process, if @@ -10867,7 +10868,8 @@ remote_target::insert_watchpoint (CORE_ADDR addr, int len, putpkt (rs->buf); getpkt (&rs->buf, 0); - switch (m_features.packet_ok (rs->buf, PACKET_Z0 + packet)) + switch (m_features.packet_ok (rs->buf, (to_underlying (PACKET_Z0) + + to_underlying (packet)))) { case PACKET_ERROR: return -1; @@ -10898,7 +10900,8 @@ remote_target::remove_watchpoint (CORE_ADDR addr, int len, char *p; enum Z_packet_type packet = watchpoint_to_Z_packet (type); - if (m_features.packet_support (PACKET_Z0 + packet) == PACKET_DISABLE) + if (m_features.packet_support ((to_underlying (PACKET_Z0) + + to_underlying (packet))) == PACKET_DISABLE) return -1; /* Make sure the remote is pointing at the right process, if @@ -10914,7 +10917,8 @@ remote_target::remove_watchpoint (CORE_ADDR addr, int len, putpkt (rs->buf); getpkt (&rs->buf, 0); - switch (m_features.packet_ok (rs->buf, PACKET_Z0 + packet)) + switch (m_features.packet_ok (rs->buf, (to_underlying (PACKET_Z0) + + to_underlying (packet)))) { case PACKET_ERROR: case PACKET_UNKNOWN: diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index ff83743da36..71390513ad2 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -2495,7 +2495,8 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno) /* Hide the upper halves of the cvs0~cvs31 registers. */ if (PPC_CVSR0_UPPER_REGNUM <= regno - && regno < PPC_CVSR0_UPPER_REGNUM + ppc_num_gprs) + && regno < (to_underlying (PPC_CVSR0_UPPER_REGNUM) + + to_underlying (ppc_num_gprs))) return ""; /* Check if the SPE pseudo registers are available. */ diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h index f9b59ece736..e4750211448 100644 --- a/gdbsupport/common-exceptions.h +++ b/gdbsupport/common-exceptions.h @@ -26,6 +26,8 @@ #include #include +#include "gdbsupport/underlying.h" + /* Reasons for calling throw_exceptions(). NOTE: all reason values must be different from zero. enum value 0 is reserved for internal use as the return value from an initial setjmp(). */ @@ -200,7 +202,7 @@ struct hash { size_t operator() (const gdb_exception &exc) const { - size_t result = exc.reason + exc.error; + size_t result = to_underlying (exc.reason) + to_underlying (exc.error); if (exc.message != nullptr) result += std::hash {} (*exc.message); return result;