Skip to content

Commit 99dc964

Browse files
authored
[cxx-interop] Document new macros from <swift/bridging> header
This adds `SWIFT_MUTATING`, `SWIFT_NONCOPYABLE` to the list of supported customization macros.
1 parent 892613a commit 99dc964

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

documentation/cxx-interop/index.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ constructor, Swift will use it when a value of such type is copied in
315315
Swift. And if the C++ type has a destructor, Swift will call the destructor when
316316
a Swift value of such type is destroyed.
317317

318-
C++ structures and classes with a deleted copy constructor are represented as non-copyable Swift types (`~Copyable`).
318+
C++ structures and classes with a deleted copy constructor are represented as
319+
non-copyable Swift types (`~Copyable`). If a C++ type has a valid copy
320+
constructor, it is still possible to make it non-copyable in Swift by annotating
321+
it with a `SWIFT_NONCOPYABLE` macro.
319322

320323
Some C++ types are always passed around using a pointer or a reference in C++.
321324
As such it might not make sense to map them to value types in Swift. These
@@ -418,12 +421,9 @@ of better API usability Swift still assumes that such functions do not
418421
mutate the object. You should avoid calling constant member functions
419422
that mutate `mutable` fields from Swift, unless they're explicitly annotated with a `SWIFT_MUTATING` macro.
420423

421-
> Swift 5.9 will ship with a `SWIFT_MUTATING` customization macro. However, it's not
422-
> yet available in a downloadable Swift 5.9 toolchain. This macro will
423-
> allow you to explicitly annotate constant member functions that do mutate the
424-
> object. Such functions with then become `mutating` methods in Swift. The
425-
> following [GitHub issue](https://github.com/swiftlang/swift/issues/66322)
426-
> tracks the status of `SWIFT_MUTATING` support in Swift.
424+
The `SWIFT_MUTATING` macro allows you to explicitly annotate constant member
425+
functions that do mutate the object. Such functions then become `mutating`
426+
methods in Swift.
427427

428428
#### Member Functions Returning References Are Unsafe by Default
429429

@@ -1969,12 +1969,26 @@ that are outlined in the documentation above.
19691969
| `SWIFT_SHARED_REFERENCE` | [Shared Reference Types](#shared-reference-types) |
19701970
| `SWIFT_UNSAFE_REFERENCE` | [Unsafe Reference Types](#unsafe-reference-types) |
19711971
| `SWIFT_RETURNS_INDEPENDENT_VALUE` | [Annotating Methods Returning Independent References or Views](#annotating-methods-returning-independent-references-or-views) |
1972+
| `SWIFT_MUTATING` | [Constant Member Functions Must Not Mutate the Object](#constant-member-functions-must-not-mutate-the-object) |
1973+
| `SWIFT_NONCOPYABLE` | [C++ Structures and Classes are Value Types by Default](#c-structures-and-classes-are-value-types-by-default) |
19721974
| `SWIFT_SELF_CONTAINED` | [Annotating C++ Structures or Classes as Self Contained](#annotating-c-structures-or-classes-as-self-contained) |
19731975

19741976
## Document Revision History
19751977

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

1980+
**2024-08-12**
1981+
1982+
- Added several customization macros from `<swift/bridging>` to the list.
1983+
1984+
**2024-06-11**
1985+
1986+
- Non-copyable C++ types are now available in Swift.
1987+
1988+
**2024-03-26**
1989+
1990+
- Updated the status of C++ templated operator support in Swift.
1991+
19781992
**2023-06-05**
19791993

19801994
- Published the initial version of the guide that describes how to mix Swift and C++.

0 commit comments

Comments
 (0)