Skip to content

repr(C) enums with a variant that overflows the native enum type should warn #108069

Open
@ChrisDenton

Description

@ChrisDenton

Consider this:

#[repr(C)]
enum Bar {
    A = 0x1_FFFF_FFFF,
}

Assume that the targets native enum size is 4 bytes. Obviously 0x1_FFFF_FFFF will overflow. This is accepted by the compiler, without warning. Instead it will silently use a larger underlying type.

I think this should be a future incompatibility warning with an eye to making it a hard error in a future edition. Being explicit with, say, repr(u64) is better than doing so silently (especially with it being incompatible with MSVC). However, any warning would be good if others disagree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Rejected/Not lang

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions