🍒 [6.2] [APINotes] Add support for SWIFT_RETURED_AS_UNRETAINED_BY_DEFAULT #10640
+43
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch adds support in APINotes for annotating C++ user-defined types with:
swift_attr("returned_as_unretained_by_default")
This attribute allows to specify a default ownership convention for return values ofSWIFT_SHARED_REFERENCE
c++ types. Specifically, it marks all unannotated return values of this type asunretained
(+0
) by default, unless explicitly overridden at the API level usingswift_attr("returns_retained")
orswift_attr("returns_unretained")
.The corresponding Swift compiler support for this annotation enables developers to suppress warnings about unannotated return ownership in large codebases while maintaining safe and predictable ownership semantics. By enabling this in APINotes, library authors can define this behavior externally without needing to modify C++ source headers directly.
rdar://150764491
(cherry picked from commit 62a2f0f)