Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this (enum : char {}) a gcc bug?

Tags:

c++

enums

gcc

c++11

under gcc-4.5, it prints 0, under gcc-4.6, it prints 1.

#include <iostream>

enum VenueId: char {}; 
int
main (int argc, char ** argv)
{
  VenueId v = (VenueId)'P';
  std::cout << (v=='P') << std::endl;
  return 0;
}
like image 535
poordeveloper Avatar asked Oct 17 '13 10:10

poordeveloper


1 Answers

As per standard, VenuedId has char type as underlying type, so v should contain char 'P', v == 'P' should yield true.

§ 7.2 Enumeration declarations

Each enumeration defines a type that is different from all other types. Each enumeration also has an underlying type. The underlying type can be explicitly specified using enum-base; if not explicitly specified, the underlying type of a scoped enumeration type is int. In these cases, the underlying type is said to be fixed. Following the closing brace of an num-specifier, each enumerator has the type of its enumeration.

like image 88
billz Avatar answered Oct 05 '22 07:10

billz