typedef'ing forward declaration of enum

97 views
Skip to first unread message

Thiago Macieira

unread,
Jun 18, 2014, 11:22:49 PM6/18/14
to std-dis...@isocpp.org
Hello

The following is valid:

===
typedef enum Forward Forward;
===

And this is valid too:
===
enum Forward : int;
typedef enum Forward Forward;
===

Should this be valid?

===
typedef enum Forward : int Forward;
===

Both GCC 4.9 and ICC 14.0/15.0 say it's invalid, but Clang 3.4 accepts it.

This is notable in Apple's own CoreFoundation headers, which uses the macro
CF_ENUM in typedefs like this:

typedef CF_ENUM(long, EnumName) { ... };

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358

David Krauss

unread,
Jun 18, 2014, 11:35:39 PM6/18/14
to std-dis...@isocpp.org
On 2014–06–19, at 11:22 AM, Thiago Macieira <thi...@macieira.org> wrote:

Both GCC 4.9 and ICC 14.0/15.0 say it's invalid, but Clang 3.4 accepts it.

Clang is incorrect as far as C++ goes. It is applying the opaque-enum-declaration grammar production in a type-specifier context. “enum Forward” alone is an elaborated-type-specifier, which is a type-specifier and hence may appear in general declarations including those modified by typedef, but adding the : int disqualifies it.

This is notable in Apple's own CoreFoundation headers, which uses the macro 
CF_ENUM in typedefs like this:

typedef CF_ENUM(long, EnumName) { ... };

This is likely a use of the independently-evolved underlying type syntax of Objective-C.

Reply all
Reply to author
Forward
0 new messages