Is this (enumeration: char {}) a gcc error?

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; } 
+6
source share
1 answer

According to the standard, VenuedId has a char type as the base type , so v must contain char 'P' , v == 'P' must give true.

ยง 7.2 Listing declarations

Each enumeration defines a type different from all other types. Each enumeration also has a base type. The main type can be explicitly specified using enum-base ; if not explicitly specified, the base type of the type of the region listed is int. In these cases, the main type is called fixed. Following the closing bracket of the num qualifier, each enumerator has the type of its enumeration.

+5
source

Source: https://habr.com/ru/post/956154/


All Articles