Vladimir Panteleev Vladimir Panteleev - 3 months ago 70
C++ Question

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

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.


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.)