Skip to content

Commit bd3c302

Browse files
authored
Merge pull request #82625 from swiftlang/gaborh/nonescapable-noncopyable
[cxx-interop] Add test for move-only non-escapable types
2 parents 2113752 + 8af85a3 commit bd3c302

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/Interop/Cxx/class/nonescapable-lifetimebound.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ namespace NS {
115115
}
116116
}
117117

118+
struct SWIFT_NONCOPYABLE SWIFT_NONESCAPABLE MoveOnly {
119+
MoveOnly();
120+
MoveOnly(const MoveOnly& other) = delete;
121+
MoveOnly& operator=(const MoveOnly&) = delete;
122+
MoveOnly(MoveOnly&& other) = default;
123+
MoveOnly& operator=(MoveOnly&& other) = default;
124+
~MoveOnly();
125+
126+
private:
127+
int *i;
128+
};
129+
130+
MoveOnly moveOnlyId(const MoveOnly& p [[clang::lifetimebound]]);
131+
118132
// CHECK: sil [clang makeOwner] {{.*}}: $@convention(c) () -> Owner
119133
// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
120134
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
@@ -130,6 +144,7 @@ namespace NS {
130144
// CHECK: sil [clang CaptureView.captureView] {{.*}} : $@convention(cxx_method) (View, @lifetime(copy 0) @inout CaptureView) -> ()
131145
// CHECK: sil [clang CaptureView.handOut] {{.*}} : $@convention(cxx_method) (@lifetime(copy 1) @inout View, @in_guaranteed CaptureView) -> ()
132146
// CHECK: sil [clang NS.getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
147+
// CHECK: sil [clang moveOnlyId] {{.*}} : $@convention(c) (@in_guaranteed MoveOnly) -> @lifetime(borrow {{.*}}0) @out MoveOnly
133148

134149
//--- test.swift
135150

@@ -157,3 +172,7 @@ public func test() {
157172
public func test2(_ x: AggregateView) {
158173
let _ = AggregateView(member: x.member)
159174
}
175+
176+
func canImportMoveOnlyNonEscapable(_ x: borrowing MoveOnly) {
177+
let _ = moveOnlyId(x);
178+
}

0 commit comments

Comments
 (0)