Skip to content

Commit fd6a5a2

Browse files
committed
[cxx-interop] test accessing fields of a move-only C++ type
1 parent a913c4e commit fd6a5a2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ struct NonCopyable {
1717
x = y;
1818
return y;
1919
}
20-
private:
20+
2121
int x;
2222
};
2323

24+
struct NonCopyableDerived: public NonCopyable {
25+
NonCopyableDerived(int x) : NonCopyable(x) {}
26+
};
27+
28+
struct NonCopyableDerivedDerived: public NonCopyableDerived {
29+
NonCopyableDerivedDerived(int x) : NonCopyableDerived(x) {}
30+
};
31+
2432
struct NonCopyableHolder {
2533
inline NonCopyableHolder(int x) : x(x) {}
2634
inline NonCopyableHolder(const NonCopyableHolder &) = delete;

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@ var MoveOnlyCxxValueType = TestSuite("Move Only Value Types")
99

1010
MoveOnlyCxxValueType.test("Test move only type member access") {
1111
var c = NonCopyable(2)
12-
let k = c.method(-2)
12+
var k = c.method(-2)
1313
expectEqual(k, -4)
1414
expectEqual(c.method(1), 2)
15+
k = c.x
16+
expectEqual(k, 2)
17+
c.x = -3
18+
expectEqual(c.x, -3)
19+
k = c.mutMethod(72)
20+
expectEqual(k, 72)
1521
}
1622

17-
runAllTests()
23+
MoveOnlyCxxValueType.test("Test derived move only type member access") {
24+
var c = NonCopyableDerivedDerived(2)
25+
var k = c.method(-3)
26+
expectEqual(k, -6)
27+
expectEqual(c.method(1), 2)
28+
k = c.x
29+
expectEqual(k, 2)
30+
c.x = 11
31+
expectEqual(c.x, 11)
32+
k = c.mutMethod(-13)
33+
expectEqual(k, -13)
34+
}
1835

36+
runAllTests()

0 commit comments

Comments
 (0)