vendredi 24 avril 2015

GCC rejects a simple declaration with an enum-base; clang accepts it — which is correct?

GCC 4.9.2 doesn't compile this snippet, but clang 3.5.0 does. Which one is correct?

enum F : int { x, y, z};
int F;
enum F:int f = F::x;

GCC output :

main.cpp:3:12: error: expected ';' or '{' before 'f'
 enum F:int f = F::x;
            ^
main.cpp:3:12: error: expected class-key before 'f'
main.cpp:3:14: error: invalid type in declaration before '=' token
 enum F:int f = F::x;
              ^
main.cpp:3:16: error: 'F' is not a class, namespace, or enumeration
 enum F:int f = F::x;
                ^

I believe GCC is correct, as a simple-declaration (containing the elaborated-type-specifier enum F) doesn't allow an enum-base (: int), but I'd like some confirmation on this.

Aucun commentaire:

Enregistrer un commentaire