You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/cxx-interop/index.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1257,20 +1257,22 @@ object.doSomething()
1257
1257
1258
1258
### Calling conventions when passing Shared Reference Types from Swift to C++
1259
1259
1260
-
If a C++ shared reference type is passed as an argument to a C++ API from Swift, the Swift compiler guarantees that the passed value would be alive, and retains the ownership of the value.
1260
+
If a C++ shared reference type is passed as an argument to a C++ API from Swift, the Swift compiler guarantees that the passed value would be alive.
1261
+
Swift also retains the ownership of the value.
1261
1262
In other words, the argument is passed at `+0` and there is no transfer of ownership.
1262
-
The C++ function is responsible for ensuring that the value pointed to by the parameter is alive during and at the end of the call.
1263
-
The C++ function should not assume it has ownership of the value and should do necessary retain operations if it is needs to take ownership.
1263
+
The C++ function should not assume that it has the ownership of the value and should do necessary retain operations if it is needs to take ownership.
1264
+
The C++ function is responsible for ensuring that the value pointed to by the parameter is alive during and at the end of the function call.
1265
+
1264
1266
1265
1267
```swift
1266
1268
var obj = SharedObject.create()
1267
-
receiveSharedObject(obj) // Swift guarantees that obj is alive
1269
+
receiveSharedObject(obj) // Swift guarantees that obj is alive and it is passed at +0
1268
1270
```
1269
1271
1270
1272
```c++
1271
1273
voidreceiveSharedObject(SharedObject *sobj) {
1272
1274
...
1273
-
// Swift assumes that sobj is valid, non-null object at the end of this function
1275
+
// Swift assumes that sobj is a valid, non-null object at the end of this function
0 commit comments