http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56155

             Bug #: 56155
           Summary: [C++0X] enumeration with fixed underlying type - enum
                    literals have wrong type
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: mib.bugzi...@gmail.com


For an enumeration whose underlying type is fixed, the values of the
enumeration are the values of the underlying type. gcc appears to be ignoring
the underlying type, as the value of E_ in this example is 4

 gpp48 bug1.cpp -std=c++0x
bug1.cpp: In function âint main()â:
bug1.cpp:4:3: error: static assertion failed: E_ should be 1
   static_assert( E_ == 1, "E_ should be 1");
   ^

enum e_ : unsigned char { Z_, E_=sizeof(Z_) };
#include <stdio.h>
int main(void) {
  static_assert( E_ == 1, "E_ should be 1");
  printf("z is %d e is %d\n", Z_, E_ ); // prints 4
  printf("sizeof unsigned char is %d\n", sizeof(unsigned char)); // prints 1
  printf("sizeof e_ is %d\n", sizeof(e_)); // prints 1
  return 0;
}

Reply via email to