Skip to content

[cxx-interop] Re-enable warnings for unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types under an experimental feature flag #82488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

fahadnayyar
Copy link
Contributor

@fahadnayyar fahadnayyar commented Jun 25, 2025

This patch re-enables diagnostics for unannotated C++ functions or methods returning SWIFT_SHARED_REFERENCE types. These warnings now fire only once per source location, even in the presence of multiple template instantiations. This avoids diagnostic duplication that was a key source of noise in the compilation of larger codebases.

These warnings were previously disabled starting in Swift 6.2 via PR-#81411 due to concerns around false positives and excessive duplication in projects adopting C++ interop. This patch addresses the duplication issue by adding source-location-based caching, which ensures that a warning is emitted only once per source location, even across template instantiations with different types.

However, the false positive issue remains to be investigated and will be addressed in a follow-up patch. Until that happens, the warnings are gated behind a new experimental feature flag: WarnUnannotatedReturnOfCxxFrt. This feature will be enabled by default only after thorough qualification and testing on large C++ codebases.

rdar://154261051

@fahadnayyar
Copy link
Contributor Author

@swift-ci please smoke test

@fahadnayyar fahadnayyar changed the title Re-enable warnings for unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types under an experimental feature flag [cxx-interop] Re-enable warnings for unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types under an experimental feature flag Jun 25, 2025
@fahadnayyar fahadnayyar self-assigned this Jun 25, 2025
@fahadnayyar fahadnayyar added the c++ interop Feature: Interoperability with C++ label Jun 25, 2025
Copy link
Contributor

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any known problems with these diagnostics or does this solve all of the problems? If the false positive fixes are coming in a follow-up patch, I wonder if the flag should be inverted and the warnings should be off by default.

@fahadnayyar
Copy link
Contributor Author

Do we have any known problems with these diagnostics or does this solve all of the problems?

False positives on large codebases still needs to be addressed: rdar://150800115
I plan to solve that problem on a follow up patch.

If the false positive fixes are coming in a follow-up patch, I wonder if the flag should be inverted and the warnings should be off by default.

The warnings are off by default in this patch. WDYM by inverting the flag?

@Xazax-hun
Copy link
Contributor

The warnings are off by default in this patch. WDYM by inverting the flag?

My bad! I misunderstood something.

@fahadnayyar
Copy link
Contributor Author

@swift-ci please smoke test

@fahadnayyar fahadnayyar merged commit a4eeae2 into swiftlang:main Jul 15, 2025
3 checks passed
susmonteiro pushed a commit to susmonteiro/swift that referenced this pull request Jul 17, 2025
…WIFT_SHARED_REFERENCE types under an experimental feature flag (swiftlang#82488)

This patch re-enables diagnostics for unannotated C++ functions or
methods returning `SWIFT_SHARED_REFERENCE` types. These warnings now
fire only **once per source location**, even in the presence of multiple
template instantiations. This avoids diagnostic duplication that was a
key source of noise in the compilation of larger codebases.

These warnings were previously disabled starting in **Swift 6.2** via
[PR-swiftlang#81411](swiftlang#81411) due to
concerns around false positives and excessive duplication in projects
adopting C++ interop. This patch addresses the duplication issue by
adding source-location-based caching, which ensures that a warning is
emitted only once per source location, even across template
instantiations with different types.

However, the false positive issue remains to be investigated and will be
addressed in a follow-up patch. Until that happens, the warnings are
gated behind a new experimental feature flag:
`WarnUnannotatedReturnOfCxxFrt`. This feature will be enabled by default
only after thorough qualification and testing on large C++ codebases.

rdar://154261051
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.

2 participants