Is this a valid enum declaration?

100 views
Skip to first unread message

chub...@gmail.com

unread,
Nov 26, 2012, 1:07:07 AM11/26/12
to std-dis...@isocpp.org
enum {T1, T2, T3} MYTYPE1;

My interpretation is that this should be ill-formed as the well-formed declaration is 

enum MYTYPE2 {T1, T2, T3};

Both G++4.6 and VS2010 accept the above declaration. However both don't allow the type MYTYPE1 to be used in the type-specifier.

If it is indeed allowed, what is the likely use of it.

Richard Smith

unread,
Nov 26, 2012, 1:21:37 AM11/26/12
to std-dis...@isocpp.org
The general form of a simple-declaration is:

attribute-specifier-seq decl-specifier-seq init-declarator-list ;

The 'enum {T1, T2, T3}' is the decl-specifier-seq here, and the init-declarator-list is a list of additional entities being defined based on that type (in this case, 'MYTYPE1' is a variable of the enumeration type). The behavior is just like you'd written:

enum {T1, T2, T3};
decltype(T1) MYTYPE1;

Vicente J. Botet Escriba

unread,
Nov 26, 2012, 1:20:09 AM11/26/12
to std-dis...@isocpp.org
Le 26/11/12 07:07, chub...@gmail.com a �crit :
> enum {T1, T2, T3} MYTYPE1;
Note that this is the declaration of variable MYTYPE1 of type enum {...}.

Vicente

ajay kumar

unread,
Oct 4, 2015, 7:15:49 AM10/4/15
to ISO C++ Standard - Discussion, chub...@gmail.com

David Krauss

unread,
Oct 4, 2015, 1:59:05 PM10/4/15
to std-dis...@isocpp.org
Please do not spam the list.
Reply all
Reply to author
Forward
0 new messages