Skip to content

Commit f49c2f1

Browse files
authored
Merge pull request #61308 from hyp/eng/raw-enum-test
[interop][SwiftToCxx] NFC, add a test for raw representable enum
2 parents 3304744 + 717c299 commit f49c2f1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docs/CppInteroperability/CppInteroperabilityStatus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ This status table describes which of the following Swift language features have
163163
| Copy and destroy semantics | Yes |
164164
| Creation | Yes |
165165
| Enums with associated values | Partially: only support structs and enums |
166-
| Enums with raw values | No |
166+
| Enums with raw values | Yes |
167167
| Indirect enums | No |
168168

169169
**Class types**

test/Interop/SwiftToCxx/stdlib/optional/optional-execution.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public struct SmallStruct {
1919
public let x: Int16
2020
}
2121

22+
@_expose(Cxx)
23+
public enum RawEnum: Int16 {
24+
case first = 1
25+
case second = 3
26+
}
27+
2228
@_expose(Cxx)
2329
public class Klass {
2430
public let x: Int16
@@ -114,5 +120,14 @@ int main() {
114120
// CHECK-NEXT: Optional(UseOptional.Klass)
115121
// CHECK-NEXT: nil
116122
// CHECK-NEXT: deinit-Klass
123+
124+
{
125+
auto val = RawEnum::init(1);
126+
assert(val.isSome());
127+
assert(val.getUnsafelyUnwrapped() == RawEnum::first);
128+
assert(val.getUnsafelyUnwrapped().getRawValue() == 1);
129+
auto val2 = RawEnum::init(2);
130+
assert(val2.isNone());
131+
}
117132
return 0;
118133
}

0 commit comments

Comments
 (0)