Skip to content

Conversation

@fahadnayyar
Copy link

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 of SWIFT_SHARED_REFERENCE c++ types. Specifically, it marks all unannotated return values of this type as unretained (+0) by default, unless explicitly overridden at the API level using swift_attr("returns_retained") or swift_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.

- Name: RefCountedTypeWithDefaultConvention
  SwiftImportAs: reference
  SwiftDefaultOwnership: unretained

rdar://150764491

(cherry picked from commit 62a2f0f)

…vm#138699)

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 of `SWIFT_SHARED_REFERENCE` c++ types. Specifically, it
marks all unannotated return values of this type as `unretained` (`+0`)
by default, unless explicitly overridden at the API level using
`swift_attr("returns_retained")` or `swift_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.

```
- Name: RefCountedTypeWithDefaultConvention
  SwiftImportAs: reference
  SwiftDefaultOwnership: unretained

```
rdar://150764491
@fahadnayyar fahadnayyar requested a review from a team as a code owner May 8, 2025 02:19
@fahadnayyar
Copy link
Author

@swift-ci please test

@fahadnayyar fahadnayyar requested a review from DougGregor May 8, 2025 02:23
@fahadnayyar
Copy link
Author

@swift-ci please test windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant