Files
swift-mirror/test/Interpreter/Inputs/enum-nonexhaustivity.h
Jordan Rose 36eae9d4f6 [SILGen] Generate a trap for unexpected cases in all @objc enums
(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
2018-02-21 10:34:59 -08:00

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;
}