Skip to content

Commit 51d0e84

Browse files
committed
[cxx-interop] add a test to cover accessing non-copyable field
1 parent fd6a5a2 commit 51d0e84

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

test/Interop/Cxx/class/move-only/Inputs/move-only-cxx-value-type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct NonCopyableHolder {
3737
inline NonCopyable &returnMutNonCopyableRef() { return x; }
3838

3939
inline const NonCopyable &returnNonCopyableRef() const { return x; }
40-
private:
40+
4141
NonCopyable x;
4242
};
4343

test/Interop/Cxx/class/move-only/move-only-cxx-value-type.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,21 @@ MoveOnlyCxxValueType.test("Test derived move only type member access") {
3333
expectEqual(k, -13)
3434
}
3535

36+
func borrowNC(_ x: borrowing NonCopyable) -> CInt {
37+
return x.method(3)
38+
}
39+
40+
func inoutNC(_ x: inout NonCopyable, _ y: CInt) -> CInt {
41+
return x.mutMethod(y)
42+
}
43+
44+
MoveOnlyCxxValueType.test("Test move only field access in holder") {
45+
var c = NonCopyableHolder(11)
46+
var k = borrowNC(c.x)
47+
expectEqual(k, 33)
48+
k = inoutNC(&c.x, 7)
49+
expectEqual(k, 7)
50+
expectEqual(c.x.x, 7)
51+
}
52+
3653
runAllTests()

0 commit comments

Comments
 (0)