Skip to content

[c23] typeof(type-name) in enumeration fixed underlying type is broken #146351

@MisterDA

Description

@MisterDA

Setting a typeof(type-name) in an enumeration fixed underlying type is broken: an error is raised explaining that the identifiers are not declared, but we're in the process of declaring them. The bug is present in clang 20.1.0. GCC 15.1 doesn't have this bug.

See C23 6.7.3.6.p4 Typeof specifiers

If the typeof operators are applied to an expression, they yield the type of their operand. Otherwise, they designate the same type as the type name with any nested typeof specifier evaluated.

Interestingly, typeof(expression) isn't broken!

https://gcc.godbolt.org/z/TGWYdhndo

enum e : int {
    E = 0,
};

enum f : typeof(int) {
    F = 0, /* error: use of undeclared identifier 'F' */
};

int g = 0;

enum g : typeof(g) {
    G = 0,
};

int main() {}
<source>:6:5: error: use of undeclared identifier 'F'
    6 |     F = 0,
      |     ^
1 error generated.
Compiler returned: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions