Skip to content

[clang] Range of empty enumeration without fixed underlying type is incorrect. #106815

@keinflue

Description

@keinflue

The following currently compiles without diagnostic for C++11 and later:

enum E {};
constexpr auto x = static_cast<E>(1);

This should be ill-formed, clearly in C++17 and earlier, and also intended in C++20 and later.

According to [dcl.enum]/8 the set of values of E is only {0} and therefore the cast has undefined behavior.

In C++20 the wording of [dcl.enum]/8 changed and now isn't clear any more, but presumably there was no intent to change the behavior. See cplusplus/CWG#604.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidclang:frontendLanguage frontend issues, e.g. anything involving "Sema"cwg-issueAn issue that was filed to the Core Working Group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions