Skip to content

Incorrect description of -Wenum-constexpr-conversion #58127

Open
@pogo59

Description

@pogo59

In https://discourse.llvm.org/t/clang-16-notice-of-potentially-breaking-changes/65562 @AaronBallman describes -Wenum-constexpr-conversion this way:

  • Clang will now correctly diagnose as ill-formed a constant expression where an enum without a fixed underlying type is set to a value outside the range of the enumeration’s values.
    enum E { Zero, One, Two, Three, Four };
    constexpr E Val1 = (E)3;  // Ok
    constexpr E Val2 = (E)7;  // Ok
    constexpr E Val3 = (E)8;  // Now diagnosed as out of the range [0, 7]
    constexpr E Val4 = (E)-1; // Now diagnosed as out of the range [0, 7]

I think the actual "range" of the enumeration is [0, 4] not [0, 7] and therefore clang should diagnose the second example (E)7.

Alternatively, the diagnostic should be described differently, in order to accurately specify the conditions that are being diagnosed. Perhaps instead of "outside the range of the enumeration's values" it should be "outside the range of the minimum-size bitfield needed to represent the range of the enumeration's values."

But I'd rather see this handled as a bug, and fixed accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions