Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISO C++ forbids forward references to 'enum' types

Tags:

c++

clang

Given the program:

enum E : int {     A, B, C }; 

g++ -c test.cpp works just fine. However, clang++ -c test.cpp gives the following errors:

test.cpp:1:6: error: ISO C++ forbids forward references to 'enum' types enum E : int      ^ test.cpp:1:8: error: expected unqualified-id enum E : int        ^ 2 errors generated. 

These error messages don't make any sense to me. I don't see any forward references here.

like image 807
Vladimir Panteleev Avatar asked Aug 04 '16 21:08

Vladimir Panteleev


1 Answers

Specifying the underlying type for an enum is a C++11 language feature. To get the code to compile, you must add the switch -std=c++11. This works for both GCC and Clang.

For enums in C++03, the underlying integral type is implementation-defined, unless the values of the enumerator cannot fit in an int or unsigned int. (However, Microsoft's compiler has allowed specifying the underlying type of an enum as a proprietary extension since VS 2005.)

like image 181
Vladimir Panteleev Avatar answered Sep 19 '22 14:09

Vladimir Panteleev