Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions documentation/cxx-interop/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ because they return a reference that points into the `Forest` object.

#### Virtual Member Functions

Currently virtual member functions are not available in Swift.
Virtual methods of C++ value types cannot be called from Swift. This is similar
to C++, where you can only call virtual methods on a pointer or a reference.

#### Static Member Functions

Expand Down Expand Up @@ -1254,6 +1255,14 @@ object.doSomething()
// `object` will be released here.
```

### Inheritance and Virtual Member Functions

Similar to value types, casting an instance of a derived reference type to a
base reference type, or vice versa, is not yet supported by Swift.

If a reference type has virtual methods, you can call those methods from Swift.
This includes pure virtual methods.

#### Exposing C++ Shared Reference Types back from Swift

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,
Expand All @@ -1276,11 +1285,6 @@ The C++ caller of this function is responsible for releasing the object.
The `SWIFT_UNSAFE_REFERENCE` annotation macro has the same effect as `SWIFT_IMMORTAL_REFERENCE`
annotation macro. However, it communicates different semantics: the type is intended to be used unsafely, rather than living for the duration of the program.

### Unique Reference Types

Unique reference types, such as types passed around by `std::unique_ptr` are
not yet supported by Swift.

## Using C++ Standard Library from Swift

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

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

**2025-04-07**

- C++ virtual methods of reference types are now available in Swift.
- `std::unique_ptr` is now supported in Swift.

**2024-08-12**

- Added several customization macros from `<swift/bridging>` to the list.
Expand Down
16 changes: 7 additions & 9 deletions documentation/cxx-interop/status/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ The following C++ standard library types are supported in Swift:
- Specializations of `std::set`, `std::multiset` and `std::unordered_set`
- Specializations of `std::optional`
- Specializations of `std::shared_ptr`
- Specializations of `std::unique_ptr`
- Specializations of `std::array`

Other standard library types, like `std::unique_ptr`, `std::function` and
`std::variant` are not yet supported in Swift.
Other standard library types, like `std::function` and `std::variant`, are not
yet supported in Swift.

### Other C++ Features Handled by Swift

Expand Down Expand Up @@ -229,16 +230,14 @@ header.

### Swift Structures Supported by C++

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

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

Swift currently does not expose nested structures to C++.

### Swift Classes and Actors Supported by C++

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

- Generic classes and actors

Swift currently does not expose nested classes and actors to C++.

### Swift Enumerations Supported by C++

Swift can generate C++ representation for most top-level Swift enumerations
Expand Down Expand Up @@ -351,6 +348,7 @@ standard library that can be represented in C++:
| `CBool` | `bool` |
| `CChar` | `char` |
| `CWideChar` | `wchar_t` |
| `CChar8` | `char8_t` |
| `CChar16` | `char16_t` |
| `CChar32` | `char32_t` |
| `CSignedChar` | `signed char` |
Expand All @@ -369,7 +367,7 @@ standard library that can be represented in C++:
## Constraints and Limitations

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

### Swift Package Manager Constraints

Expand Down