mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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](https://github.com/swiftlang/swift/pull/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
40 lines
1.7 KiB
Swift
40 lines
1.7 KiB
Swift
// RUN: rm -rf %t
|
|
// RUN: %target-swift-frontend -typecheck -verify -I %S%{fs-sep}Inputs %s -cxx-interoperability-mode=upcoming-swift -enable-experimental-feature WarnUnannotatedReturnOfCxxFrt -verify-additional-file %S%{fs-sep}Inputs%{fs-sep}inheritance.h -Xcc -Wno-return-type -Xcc -Wno-inaccessible-base
|
|
|
|
// REQUIRES: swift_feature_WarnUnannotatedReturnOfCxxFrt
|
|
|
|
import Inheritance
|
|
|
|
let _ = ImmortalRefereceExample.returnImmortalRefType()
|
|
let _ = ImmortalRefereceExample.returnDerivedFromImmortalRefType()
|
|
|
|
let _ = ExplicitAnnotationHasPrecedence1.returnValueType()
|
|
let _ = ExplicitAnnotationHasPrecedence1.returnRefType()
|
|
let _ = ExplicitAnnotationHasPrecedence1.returnDerivedFromValueType()
|
|
let _ = ExplicitAnnotationHasPrecedence1.returnDerivedFromValueTypeAndAnnotated()
|
|
let _ = ExplicitAnnotationHasPrecedence1.returnDerivedFromRefType()
|
|
let _ = ExplicitAnnotationHasPrecedence1.returnDerivedFromRefTypeAndAnnotated()
|
|
|
|
let _ = ExplicitAnnotationHasPrecedence2.returnDerivedFromRefTypeAAndB()
|
|
let _ = ExplicitAnnotationHasPrecedence2.returnDerivedFromRefTypeAAndBAnnotated()
|
|
|
|
let _ = BasicInheritanceExample.returnValueType()
|
|
let _ = BasicInheritanceExample.returnRefType()
|
|
let _ = BasicInheritanceExample.returnDerivedFromRefType()
|
|
|
|
let _ = MultipleInheritanceExample1.returnDerivedFromBaseRef1AndBaseRef2()
|
|
let _ = MultipleInheritanceExample1.returnDerivedFromBaseRef3()
|
|
|
|
let _ = MultipleInheritanceExample2.returnD()
|
|
|
|
let _ = MultipleInheritanceExample3.returnD()
|
|
|
|
let _ = OverloadedRetainRelease.returnD()
|
|
|
|
let _ = RefTypeDiamondInheritance.returnDiamond()
|
|
let _ = RefTypeDiamondInheritance.returnVirtualDiamond()
|
|
|
|
let _ = NonRefTypeDiamondInheritance.returnDiamond()
|
|
|
|
let _ = InheritingTemplatedRefType.returnForest()
|