Skip to content

Commit 9815d8c

Browse files
authored
[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
1 parent 5986822 commit 9815d8c

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

documentation/cxx-interop/index.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ because they return a reference that points into the `Forest` object.
492492

493493
#### Virtual Member Functions
494494

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.
496497

497498
#### Static Member Functions
498499

@@ -1254,6 +1255,14 @@ object.doSomething()
12541255
// `object` will be released here.
12551256
```
12561257

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+
12571266
#### Exposing C++ Shared Reference Types back from Swift
12581267

12591268
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.
12761285
The `SWIFT_UNSAFE_REFERENCE` annotation macro has the same effect as `SWIFT_IMMORTAL_REFERENCE`
12771286
annotation macro. However, it communicates different semantics: the type is intended to be used unsafely, rather than living for the duration of the program.
12781287

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-
12841288
## Using C++ Standard Library from Swift
12851289

12861290
This section describes how to import the C++ standard library, and how
@@ -1982,6 +1986,11 @@ that are outlined in the documentation above.
19821986

19831987
This section lists the recent changes made to this reference guide.
19841988

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+
19851994
**2024-08-12**
19861995

19871996
- Added several customization macros from `<swift/bridging>` to the list.

documentation/cxx-interop/status/index.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,11 @@ The following C++ standard library types are supported in Swift:
196196
- Specializations of `std::set`, `std::multiset` and `std::unordered_set`
197197
- Specializations of `std::optional`
198198
- Specializations of `std::shared_ptr`
199+
- Specializations of `std::unique_ptr`
199200
- Specializations of `std::array`
200201

201-
Other standard library types, like `std::unique_ptr`, `std::function` and
202-
`std::variant` are not yet supported in Swift.
202+
Other standard library types, like `std::function` and `std::variant`, are not
203+
yet supported in Swift.
203204

204205
### Other C++ Features Handled by Swift
205206

@@ -229,16 +230,14 @@ header.
229230

230231
### Swift Structures Supported by C++
231232

232-
Swift can generate C++ representation for most top-level Swift structures. The
233-
following Swift structures are not yet supported:
233+
Swift can generate C++ representation for most Swift structures. The following
234+
Swift structures are not yet supported:
234235

235236
- Zero-sized structures that don't have any stored properties
236237
- Non-copyable structures
237238
- Generic structures with generic constraints, or with more than three generic
238239
parameters, or that have variadic generics
239240

240-
Swift currently does not expose nested structures to C++.
241-
242241
### Swift Classes and Actors Supported by C++
243242

244243
Swift can generate C++ representation for most top-level Swift classes and
@@ -247,8 +246,6 @@ following Swift classes are not yet supported:
247246

248247
- Generic classes and actors
249248

250-
Swift currently does not expose nested classes and actors to C++.
251-
252249
### Swift Enumerations Supported by C++
253250

254251
Swift can generate C++ representation for most top-level Swift enumerations
@@ -351,6 +348,7 @@ standard library that can be represented in C++:
351348
| `CBool` | `bool` |
352349
| `CChar` | `char` |
353350
| `CWideChar` | `wchar_t` |
351+
| `CChar8` | `char8_t` |
354352
| `CChar16` | `char16_t` |
355353
| `CChar32` | `char32_t` |
356354
| `CSignedChar` | `signed char` |
@@ -369,7 +367,7 @@ standard library that can be represented in C++:
369367
## Constraints and Limitations
370368

371369
Swift has some known limitations related to C++ interoperability support.
372-
They're currently [listed on GitHub](https://github.com/swiftlang/swift/issues/66159).
370+
They are currently [tracked on GitHub](https://github.com/swiftlang/swift/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22c%2B%2B%20interop%22).
373371

374372
### Swift Package Manager Constraints
375373

0 commit comments

Comments
 (0)