mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
(both C enums and Swift enums declared @objc), because of the "feature" in C of treating a value not declared as a case as a valid value of an enum. No more undefined behavior here! This bit can go in separately from all the work on exhaustive/frozen enums, which is still being discussed and will come later. rdar://problem/20420436
26 lines
659 B
C
26 lines
659 B
C
enum NonExhaustiveEnum {
|
|
NonExhaustiveEnumA = 0,
|
|
NonExhaustiveEnumB = 1,
|
|
NonExhaustiveEnumC = 2,
|
|
} __attribute__((enum_extensibility(open)));
|
|
|
|
enum NonExhaustiveEnum getExpectedValue(void) {
|
|
return NonExhaustiveEnumB;
|
|
}
|
|
enum NonExhaustiveEnum getUnexpectedValue(void) {
|
|
return (enum NonExhaustiveEnum)3;
|
|
}
|
|
|
|
enum LyingExhaustiveEnum {
|
|
LyingExhaustiveEnumA = 0,
|
|
LyingExhaustiveEnumB = 1,
|
|
LyingExhaustiveEnumC = 2,
|
|
} __attribute__((enum_extensibility(closed)));
|
|
|
|
enum LyingExhaustiveEnum getExpectedLiarValue(void) {
|
|
return LyingExhaustiveEnumB;
|
|
}
|
|
enum LyingExhaustiveEnum getUnexpectedLiarValue(void) {
|
|
return (enum LyingExhaustiveEnum)3;
|
|
}
|