Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

design: enumの網羅性 #247

Open
KisaragiEffective opened this issue Oct 1, 2023 · 0 comments
Open

design: enumの網羅性 #247

KisaragiEffective opened this issue Oct 1, 2023 · 0 comments

Comments

@KisaragiEffective
Copy link
Owner

KisaragiEffective commented Oct 1, 2023

まず、enumは閉じているか閉じていないかの2択がある。

  • Java, Kotlin, Scala 2, Scala 3, Rust, C++1, Swift: 閉じている
  • C, C#2, SmileBASIC 4: 閉じていない

ここで、「閉じている」とは「基底となる表現の型のインスタンスがenumの有効な要素であるとは限らない」という意味である。

例えば、以下の例を考える。

#[repr(u8)]
enum X {
Y = 1
}

fn main() {
    let b = 2;
    // 2 is not valid discriminator; UB!
    let x: X = unsafe { core::mem::transmute(b) };
}

Footnotes

  1. enum classenum struct

  2. https://stackoverflow.com/a/63316213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant