Skip to content

accept ill-formed typedef with not fully defined enum #38774

@Dushistov

Description

@Dushistov
Bugzilla Link 39426
Version 7.0
OS All
CC @DougGregor

Extended Description

clang version 7.0.0 (tags/RELEASE_700/final) compiles such code without
any error:

$ cat > test.cpp
typedef enum FooEnum : int FooEnum;
enum FooEnum : int { A = 1, B };
$ clang++ -c -pedantic -std=c++11 test.cpp
$

while gcc (8.2.1) rejects it.

according to https://stackoverflow.com/questions/52971159/strong-enum-typedef-clang-bug-or-c11-standard-uncertainty/52973516#52973516

[dcl.typedef]/1

The typedef specifier shall not be combined in a decl-specifier-seq with any other kind of specifier except a defining-type-specifier,[...]

[dcl.type]/1

defining-type-specifier:

    type-specifier

    class-specifier

    enum-specifier

[dcl.enum]/1

enum-specifier:

    enum-head { enumerator-listopt }

    enum-head { enumerator-list , }

So the code bellow is legal c++:

typedef enum FooEnum : int { A = 1, B } FooEnum;

but this one is not legal c++:

typedef enum FooEnum : int FooEnum;

Because enum FooEnum:int is not a defining-type-specifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidbugzillaIssues migrated from bugzillac++11clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions