[clang] [NFC] [API Notes] [Documentation] Add documentation for SwiftReturnOwnership (PR #143545)
Egor Zhdan via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 10 08:07:56 PDT 2025
================
@@ -195,6 +195,52 @@ declaration kind), all of which are optional:
SwiftReleaseOp: immortal
SwiftRetainOp: immortal
+:SwiftReturnOwnership:
+
+ Specifies the ownership convention of a function or method returning a C++ type
+ that has been imported as a Swift reference type using ``SwiftImportAs: reference``.
+ This allows Swift to correctly manage the retain and release operations at the
+ language boundary.
+
+ The possible values are:
+
+ - ``retained`` — Indicates that the function or method returns a +1 reference.
+ Swift will take ownership and is responsible for releasing it.
+ Equivalent to ``SWIFT_RETURNS_RETAINED``.
+ - ``unretained`` — Indicates that the function or method returns a +0 reference.
+ The caller must ensure the returned object remains alive.
+ Equivalent to ``SWIFT_RETURNS_UNRETAINED``.
+
+ This attribute can be applied to:
+
+ - **C++ functions**
+ - **C++ instance or static methods**
+ - **Objective-C / Objective-C++ methods or functions that return a C++ reference type**
----------------
egorzhdan wrote:
Minor: I'd say let's not highlight this in bold. Since we don't use bold highlighting elsewhere in this document, this would attract too much attention.
https://github.com/llvm/llvm-project/pull/143545
More information about the cfe-commits
mailing list