Bug 25325 - enum class inherited from typedef of unsigned type does not handle values with high bit set
Summary: enum class inherited from typedef of unsigned type does not handle values wit...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.2
: P2 normal
Target Milestone: 10.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-30 22:07 UTC by Steve Fink
Modified: 2020-04-03 20:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Fink 2019-12-30 22:07:37 UTC
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.
Comment 1 Sourceware Commits 2020-04-03 20:13:39 UTC
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.
Comment 2 Hannes Domani 2020-04-03 20:15:59 UTC
Fixed.