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
[cxx-interop] Document features that shipped in 6.1 and earlier
* [cxx-interop] Document virtual method support
* [cxx-interop] Document `std::unique_ptr` support
* [cxx-interop] Update stale link to known issues
* [cxx-interop] Document `char8_t` support
* [cxx-interop] Document nested struct support
* [cxx-interop] Update revision history
Copy file name to clipboardExpand all lines: documentation/cxx-interop/index.md
+15-6Lines changed: 15 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -492,7 +492,8 @@ because they return a reference that points into the `Forest` object.
492
492
493
493
#### Virtual Member Functions
494
494
495
-
Currently virtual member functions are not available in Swift.
495
+
Virtual methods of C++ value types cannot be called from Swift. This is similar
496
+
to C++, where you can only call virtual methods on a pointer or a reference.
496
497
497
498
#### Static Member Functions
498
499
@@ -1254,6 +1255,14 @@ object.doSomething()
1254
1255
// `object` will be released here.
1255
1256
```
1256
1257
1258
+
### Inheritance and Virtual Member Functions
1259
+
1260
+
Similar to value types, casting an instance of a derived reference type to a
1261
+
base reference type, or vice versa, is not yet supported by Swift.
1262
+
1263
+
If a reference type has virtual methods, you can call those methods from Swift.
1264
+
This includes pure virtual methods.
1265
+
1257
1266
#### Exposing C++ Shared Reference Types back from Swift
1258
1267
1259
1268
C++ can call into Swift APIs that take or return C++ Shared Reference Types. Objects of these types are always created on the C++ side,
@@ -1276,11 +1285,6 @@ The C++ caller of this function is responsible for releasing the object.
1276
1285
The `SWIFT_UNSAFE_REFERENCE` annotation macro has the same effect as `SWIFT_IMMORTAL_REFERENCE`
1277
1286
annotation macro. However, it communicates different semantics: the type is intended to be used unsafely, rather than living for the duration of the program.
1278
1287
1279
-
### Unique Reference Types
1280
-
1281
-
Unique reference types, such as types passed around by `std::unique_ptr` are
1282
-
not yet supported by Swift.
1283
-
1284
1288
## Using C++ Standard Library from Swift
1285
1289
1286
1290
This section describes how to import the C++ standard library, and how
@@ -1982,6 +1986,11 @@ that are outlined in the documentation above.
1982
1986
1983
1987
This section lists the recent changes made to this reference guide.
1984
1988
1989
+
**2025-04-07**
1990
+
1991
+
- C++ virtual methods of reference types are now available in Swift.
1992
+
-`std::unique_ptr` is now supported in Swift.
1993
+
1985
1994
**2024-08-12**
1986
1995
1987
1996
- Added several customization macros from `<swift/bridging>` to the list.
0 commit comments