Skip to content

Conversation

fahadnayyar
Copy link
Contributor

@fahadnayyar fahadnayyar commented Sep 24, 2025

Type-level ownership annotations (SWIFT_RETURNED_AS_UNRETAINED_BY_DEFAULT) were not suppressing warning for C++ functions (which are not annotated with SWIFT_RETURNS_(UN)RETAIND) returning references (&) to foreign reference types. The annotation only worked for pointer returns (*), forcing developers to manually annotate every function returning a reference.
This PR fixes this problem by changing the logic of matchSwiftAttrOnRecordPtr to consider ReferenceType also along with PointerType.

This PR also adds comprehensive lit tests for ownership conventions and diagnostics related to C++ functions that return references to foreign reference types. These tests were previously not covered by our lit tests.

rdar://161226212

@fahadnayyar fahadnayyar self-assigned this Sep 24, 2025
@fahadnayyar fahadnayyar added the c++ interop Feature: Interoperability with C++ label Sep 24, 2025
…ning reference to frt

Type-level ownership annotation `SWIFT_RETURNED_AS_UNRETAINED_BY_DEFAULT`
was not suppressing warnings on C++ functions returning references to foreign
reference types. The `matchSwiftAttrOnRecordPtr` function
only checked for `PointerType`, missing `ReferenceType`.

This fix updates `matchSwiftAttrOnRecordPtr` to handle both pointer and
reference types, ensuring consistent ownership semantics regardless of
whether a function returns `FRT*` or `FRT&`.

rdar://161226212
@fahadnayyar fahadnayyar force-pushed the fnayyar/radar-161226212 branch from 2c66da5 to c0a673f Compare September 24, 2025 17:11
@fahadnayyar
Copy link
Contributor Author

@swift-ci please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant