Consider ``` #include <stdint.h> enum Op : uint8_t { Op_A = 1, Op_B = 127, Op_C = 128 }; int main() { Op a = Op::Op_A; Op b = Op::Op_B; Op c = Op::Op_C; return (a == b) || (b == c); } ``` (gdb) p Op_A $1 = Op_A (gdb) p Op_C $1 = -128 (gdb) p (Op)128 $1 = -128 If `uint8_t` is replaced with `unsigned char`, then it will work as intended.
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9e7c9a03eefafae549dafa8bec13232a780804ef commit 9e7c9a03eefafae549dafa8bec13232a780804ef Author: Hannes Domani <ssbssa@yahoo.de> Date: Fri Apr 3 21:38:31 2020 +0200 Fix attributes of typed enums of typedefs For this enum: typedef unsigned char byte; enum byte_enum : byte { byte_val = 128 }; The unsigned attribute is not set: (gdb) p byte_val $1 = -128 That's because it uses the attributes of the 'byte' typedef for the enum. So this changes it to use the attributes of the underlying 'unsigned char' instead. gdb/ChangeLog: 2020-04-03 Hannes Domani <ssbssa@yahoo.de> PR gdb/25325 * dwarf2/read.c (read_enumeration_type): Fix typed enum attributes. gdb/testsuite/ChangeLog: 2020-04-03 Hannes Domani <ssbssa@yahoo.de> PR gdb/25325 * gdb.cp/typed-enum.cc: New test. * gdb.cp/typed-enum.exp: New file.
Fixed.