Skip to content

repr(C, align) is unsound on enums #82101

Open
@mahkoh

Description

@mahkoh

repr(align) on enums is implemented as described in the reference:

The align modifier can also be applied on an enum. When it is, the effect on the enum's alignment is the same as if the enum was wrapped in a newtype struct with the same align modifier.

But this is not how aligned enums work in Clang, GCC, and MSVC

  • GCC ignores alignment requests on enums.
  • Clang sets the alignment to the requested alignment even if this decreases the alignment. The size is unaffected.
  • MSVC increases the alignment to the requested alignment. The size is unaffected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-alignArea: alignment control (`repr(align(N))` and so on)A-enumArea: Enums (discriminated unions, or more generally ADTs (algebraic data types))A-reprArea: the `#[repr(stuff)]` attributeC-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions