mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
When importing C++ template classes like`Ref<T>` that have methods returning `T*`, we face the following situation when `T` is a `SWIFT_SHARED_REFERENCE` type: 1. Without `SWIFT_RETURNS_(UN)RETAINED` annotation: Swift compiler would emit a warning (currently under experimental-feature flag `WarnUnannotatedReturnOfCxxFrt`) _"cannot infer the ownership of the returned value" when T is a SWIFT_SHARED_REFERENCE type_ 2. With annotation: Compiler rejects it with this error: _"cannot be annotated... not returning a SWIFT_SHARED_REFERENCE type"_ This affects WebGPU's smart pointer types (`WTF::Ref<T>, WTF::RefPtr<T>`) and similar patterns in other C++ codebases. In this patch I am fixing the logic for diagnostic `returns_retained_or_returns_unretained_for_non_cxx_frt_values`. I'm also making it a warning instead of an error to minimize the risk, as this diagnostic has been a hindrance to the adoption of these annotations in real codebases when templated functions and types are involved. (Refer to [PR-78968](https://github.com/swiftlang/swift/pull/78968)) rdar://160862498
438 KiB
438 KiB