Skip to content

Commit a4eeae2

Browse files
authored
[cxx-interop] Re-enable warnings for unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types under an experimental feature flag (#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-#81411](#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
1 parent eb122aa commit a4eeae2

11 files changed

+119
-40
lines changed

include/swift/Basic/Features.def

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,15 @@ EXPERIMENTAL_FEATURE(AssumeResilientCxxTypes, true)
478478
/// Import inherited non-public members when importing C++ classes.
479479
EXPERIMENTAL_FEATURE(ImportNonPublicCxxMembers, true)
480480

481-
/// Synthesize static factory methods for C++ foreign reference types and import
482-
/// them as Swift initializers.
481+
/// Suppress the synthesis of static factory methods for C++ foreign reference
482+
/// types and importing them as Swift initializers.
483483
EXPERIMENTAL_FEATURE(SuppressCXXForeignReferenceTypeInitializers, true)
484484

485+
/// Emit a warning when a C++ API returns a SWIFT_SHARED_REFERENCE type
486+
/// without being explicitly annotated with either SWIFT_RETURNS_RETAINED
487+
/// or SWIFT_RETURNS_UNRETAINED.
488+
EXPERIMENTAL_FEATURE(WarnUnannotatedReturnOfCxxFrt, true)
489+
485490
// Isolated deinit
486491
SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedDeinit, 371, "isolated deinit")
487492

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ UNINTERESTING_FEATURE(SafeInteropWrappers)
497497
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
498498
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
499499
UNINTERESTING_FEATURE(SuppressCXXForeignReferenceTypeInitializers)
500+
UNINTERESTING_FEATURE(WarnUnannotatedReturnOfCxxFrt)
500501
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
501502
UNINTERESTING_FEATURE(AllowRuntimeSymbolDeclarations)
502503

lib/ClangImporter/ClangImporter.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4985,11 +4985,26 @@ bool ClangImporter::Implementation::emitDiagnosticsForTarget(
49854985
ImportDiagnosticTarget target, clang::SourceLocation fallbackLoc) {
49864986
for (auto it = ImportDiagnostics[target].rbegin();
49874987
it != ImportDiagnostics[target].rend(); ++it) {
4988-
HeaderLoc loc = HeaderLoc(it->loc.isValid() ? it->loc : fallbackLoc);
4988+
clang::SourceLocation loc = it->loc.isValid() ? it->loc : fallbackLoc;
4989+
HeaderLoc hdrLoc(loc);
4990+
if (const auto *declTarget = target.dyn_cast<const clang::Decl *>()) {
4991+
if (const auto *func = llvm::dyn_cast<clang::FunctionDecl>(declTarget)) {
4992+
if (func->isTemplateInstantiation()) {
4993+
if (const auto *pattern = func->getTemplateInstantiationPattern()) {
4994+
std::pair<const clang::FunctionDecl *, DiagID> key = {
4995+
pattern, it->diag.getID()};
4996+
if (!DiagnosedTemplateDiagnostics.insert(key).second)
4997+
continue;
4998+
hdrLoc = HeaderLoc(pattern->getLocation());
4999+
}
5000+
}
5001+
}
5002+
}
5003+
49895004
if (it->diag.getID() == diag::record_not_automatically_importable.ID) {
4990-
diagnoseForeignReferenceTypeFixit(*this, loc, it->diag);
5005+
diagnoseForeignReferenceTypeFixit(*this, hdrLoc, it->diag);
49915006
} else {
4992-
diagnose(loc, it->diag);
5007+
diagnose(hdrLoc, it->diag);
49935008
}
49945009
}
49955010
return ImportDiagnostics[target].size();

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,11 +3634,13 @@ namespace {
36343634
unannotatedAPIWarningNeeded = false;
36353635
}
36363636

3637-
unannotatedAPIWarningNeeded = false;
3638-
if (unannotatedAPIWarningNeeded) {
3639-
HeaderLoc loc(decl->getLocation());
3640-
Impl.diagnose(loc, diag::no_returns_retained_returns_unretained,
3641-
decl);
3637+
if (unannotatedAPIWarningNeeded &&
3638+
Impl.SwiftContext.LangOpts.hasFeature(
3639+
Feature::WarnUnannotatedReturnOfCxxFrt)) {
3640+
Impl.addImportDiagnostic(
3641+
decl,
3642+
Diagnostic(diag::no_returns_retained_returns_unretained, decl),
3643+
decl->getLocation());
36423644
}
36433645
} else if (const auto *methodDecl =
36443646
dyn_cast<clang::CXXMethodDecl>(decl)) {

lib/ClangImporter/ImporterImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
472472
// emitted due to failed SWIFT_SHARED_REFERENCE inference.
473473
std::unordered_set<const clang::RecordDecl *> DiagnosedCxxRefDecls;
474474

475+
// Tracks which function templates have already had a diagnostic emitted,
476+
// to avoid duplicate diagnostics across instantiations.
477+
llvm::DenseSet<std::pair<const clang::FunctionDecl *, DiagID>>
478+
DiagnosedTemplateDiagnostics;
479+
475480
const bool ImportForwardDeclarations;
476481
const bool DisableSwiftBridgeAttr;
477482
const bool BridgingHeaderExplicitlyRequested;

test/Interop/Cxx/foreign-reference/Inputs/cxx-functions-and-methods-returning-frt.h

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// FRT or SWIFT_SHARED_REFERENCE type
66
struct FRTStruct {
77
// Friend function declarations
8-
friend FRTStruct *returnInstanceOfFRTStruct(int v);
9-
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsRetained(int v);
10-
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsUnretained(int v);
8+
friend FRTStruct *returnInstanceOfFRTStruct(int v); // expected-warning {{'returnInstanceOfFRTStruct' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
9+
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsRetained(int v); // expected-warning {{'returnInstanceOfFRTStructWithAttrReturnsRetained' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
10+
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsUnretained(int v); // expected-warning {{'returnInstanceOfFRTStructWithAttrReturnsUnretained' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
1111
} __attribute__((swift_attr("import_reference")))
1212
__attribute__((swift_attr("retain:retainFRTStruct")))
1313
__attribute__((swift_attr("release:releaseFRTStruct")));
@@ -179,12 +179,12 @@ __attribute__((swift_attr("unsafe")));
179179

180180
// C++ APIs returning cxx frts (for testing diagnostics)
181181
struct StructWithAPIsReturningCxxFrt {
182-
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt();
182+
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt(); // expected-warning {{'StaticMethodReturningCxxFrt' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
183183
static FRTStruct *_Nonnull StaticMethodReturningCxxFrtWithAnnotation()
184184
__attribute__((swift_attr("returns_retained")));
185185
};
186186

187-
FRTStruct *_Nonnull global_function_returning_cxx_frt();
187+
FRTStruct *_Nonnull global_function_returning_cxx_frt(); // expected-warning {{'global_function_returning_cxx_frt' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
188188
FRTStruct *_Nonnull global_function_returning_cxx_frt_with_annotations()
189189
__attribute__((swift_attr("returns_retained")));
190190

@@ -303,7 +303,7 @@ __attribute__((swift_attr(
303303
operator-(const FRTOverloadedOperators &other);
304304
};
305305

306-
FRTOverloadedOperators *_Nonnull returnFRTOverloadedOperators();
306+
FRTOverloadedOperators *_Nonnull returnFRTOverloadedOperators(); // expected-warning {{'returnFRTOverloadedOperators' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
307307

308308
void retain_FRTOverloadedOperators(FRTOverloadedOperators *_Nonnull v);
309309
void release_FRTOverloadedOperators(FRTOverloadedOperators *_Nonnull v);
@@ -371,7 +371,7 @@ struct __attribute__((swift_attr("import_reference")))
371371
__attribute__((swift_attr("retain:rretain")))
372372
__attribute__((swift_attr("release:rrelease"))) RefType {};
373373

374-
RefType *returnRefType() { return new RefType(); }
374+
RefType *returnRefType() { return new RefType(); } // expected-warning {{'returnRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
375375

376376
struct __attribute__((swift_attr("import_reference")))
377377
__attribute__((swift_attr("retain:dretain")))
@@ -420,10 +420,10 @@ __attribute__((swift_attr("retain:dRetain")))
420420
__attribute__((swift_attr("release:dRelease"))) DerivedTypeNonDefault
421421
: public BaseTypeNonDefault {};
422422

423-
BaseTypeNonDefault *createBaseTypeNonDefault() {
423+
BaseTypeNonDefault *createBaseTypeNonDefault() { // expected-warning {{'createBaseTypeNonDefault' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
424424
return new BaseTypeNonDefault();
425425
}
426-
DerivedTypeNonDefault *createDerivedTypeNonDefault() {
426+
DerivedTypeNonDefault *createDerivedTypeNonDefault() { // expected-warning {{'createDerivedTypeNonDefault' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
427427
return new DerivedTypeNonDefault();
428428
}
429429

@@ -449,4 +449,34 @@ void bRelease(DefaultOwnershipInheritance::BaseTypeNonDefault *v) {};
449449
void dRetain(DefaultOwnershipInheritance::DerivedTypeNonDefault *v) {};
450450
void dRelease(DefaultOwnershipInheritance::DerivedTypeNonDefault *v) {};
451451

452+
namespace SourceLocationCaching {
453+
454+
struct __attribute__((swift_attr("import_reference")))
455+
__attribute__((swift_attr("retain:retain_SourceLocCacheA")))
456+
__attribute__((swift_attr("release:release_SourceLocCacheA"))) TypeA {};
457+
458+
459+
460+
struct __attribute__((swift_attr("import_reference")))
461+
__attribute__((swift_attr("retain:retain_SourceLocCacheB")))
462+
__attribute__((swift_attr("release:release_SourceLocCacheB"))) TypeB {};
463+
464+
465+
template <typename T>
466+
struct Factory {
467+
static T *make() { return new T(); } // expected-warning {{'make' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
468+
};
469+
470+
using FactoryA = Factory<TypeA>;
471+
using FactoryB = Factory<TypeB>;
472+
473+
} // namespace SourceLocationCaching
474+
475+
void retain_SourceLocCacheA(SourceLocationCaching::TypeA *) {}
476+
void release_SourceLocCacheA(SourceLocationCaching::TypeA *) {}
477+
478+
void retain_SourceLocCacheB(SourceLocationCaching::TypeB *) {}
479+
void release_SourceLocCacheB(SourceLocationCaching::TypeB *) {}
480+
481+
452482
SWIFT_END_NULLABILITY_ANNOTATIONS

test/Interop/Cxx/foreign-reference/Inputs/inheritance.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ __attribute__((swift_attr("release:immortal"))) ImmortalRefType {};
109109
ImmortalRefType *returnImmortalRefType() { return new ImmortalRefType(); };
110110

111111
struct DerivedFromImmortalRefType : ImmortalRefType {};
112-
DerivedFromImmortalRefType *returnDerivedFromImmortalRefType() {
113-
return new DerivedFromImmortalRefType();
112+
DerivedFromImmortalRefType *returnDerivedFromImmortalRefType() { // expected-warning {{'returnDerivedFromImmortalRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
113+
return new DerivedFromImmortalRefType();
114114
};
115115

116116
} // namespace ImmortalRefereceExample
@@ -122,7 +122,7 @@ ValueType *returnValueType() { return new ValueType(); }
122122
struct __attribute__((swift_attr("import_reference")))
123123
__attribute__((swift_attr("retain:ret1")))
124124
__attribute__((swift_attr("release:rel1"))) RefType {};
125-
RefType *returnRefType() { return new RefType(); }
125+
RefType *returnRefType() { return new RefType(); } // expected-warning {{'returnRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
126126

127127
struct DerivedFromValueType : ValueType {};
128128
DerivedFromValueType *returnDerivedFromValueType() {
@@ -133,21 +133,21 @@ struct __attribute__((swift_attr("import_reference")))
133133
__attribute__((swift_attr("retain:ret2")))
134134
__attribute__((swift_attr("release:rel2"))) DerivedFromValueTypeAndAnnotated
135135
: ValueType {};
136-
DerivedFromValueTypeAndAnnotated *returnDerivedFromValueTypeAndAnnotated() {
137-
return new DerivedFromValueTypeAndAnnotated();
136+
DerivedFromValueTypeAndAnnotated *returnDerivedFromValueTypeAndAnnotated() { // expected-warning {{'returnDerivedFromValueTypeAndAnnotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
137+
return new DerivedFromValueTypeAndAnnotated();
138138
}
139139

140140
struct DerivedFromRefType final : RefType {};
141-
DerivedFromRefType *returnDerivedFromRefType() {
142-
return new DerivedFromRefType();
141+
DerivedFromRefType *returnDerivedFromRefType() { // expected-warning {{'returnDerivedFromRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
142+
return new DerivedFromRefType();
143143
}
144144

145145
struct __attribute__((swift_attr("import_reference")))
146146
__attribute__((swift_attr("retain:ret3")))
147147
__attribute__((swift_attr("release:rel3"))) DerivedFromRefTypeAndAnnotated
148148
: RefType {};
149-
DerivedFromRefTypeAndAnnotated *returnDerivedFromRefTypeAndAnnotated() {
150-
return new DerivedFromRefTypeAndAnnotated();
149+
DerivedFromRefTypeAndAnnotated *returnDerivedFromRefTypeAndAnnotated() { // expected-warning {{'returnDerivedFromRefTypeAndAnnotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
150+
return new DerivedFromRefTypeAndAnnotated();
151151
}
152152
} // namespace ExplicitAnnotationHasPrecedence1
153153

@@ -184,8 +184,8 @@ __attribute__((swift_attr("retain:retain_C")))
184184
__attribute__((swift_attr("release:release_C"))) DerivedFromRefTypeAAndBAnnotated
185185
: RefTypeA,
186186
RefTypeB {};
187-
DerivedFromRefTypeAAndBAnnotated *returnDerivedFromRefTypeAAndBAnnotated() {
188-
return new DerivedFromRefTypeAAndBAnnotated();
187+
DerivedFromRefTypeAAndBAnnotated *returnDerivedFromRefTypeAAndBAnnotated() { // expected-warning {{'returnDerivedFromRefTypeAAndBAnnotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
188+
return new DerivedFromRefTypeAAndBAnnotated();
189189
}
190190
} // namespace ExplicitAnnotationHasPrecedence2
191191

@@ -206,10 +206,10 @@ struct __attribute__((swift_attr("import_reference")))
206206
__attribute__((swift_attr("retain:RCRetain")))
207207
__attribute__((swift_attr("release:RCRelease"))) RefType {};
208208

209-
RefType *returnRefType() { return new RefType(); };
209+
RefType *returnRefType() { return new RefType(); }; // expected-warning {{'returnRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENC}}
210210

211211
struct DerivedFromRefType final : RefType {};
212-
DerivedFromRefType *returnDerivedFromRefType() {
212+
DerivedFromRefType *returnDerivedFromRefType() { // expected-warning {{'returnDerivedFromRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
213213
return new DerivedFromRefType();
214214
};
215215
} // namespace BasicInheritanceExample
@@ -236,7 +236,7 @@ DerivedFromBaseRef1AndBaseRef2 *returnDerivedFromBaseRef1AndBaseRef2() {
236236
};
237237

238238
struct DerivedFromBaseRef3 : BaseRef3 {};
239-
DerivedFromBaseRef3 *returnDerivedFromBaseRef3() {
239+
DerivedFromBaseRef3 *returnDerivedFromBaseRef3() { // expected-warning {{'returnDerivedFromBaseRef3' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
240240
return new DerivedFromBaseRef3();
241241
};
242242
} // namespace MultipleInheritanceExample1
@@ -312,7 +312,7 @@ __attribute__((swift_attr("release:samerelease"))) B2 {}; // expected-error {{m
312312

313313
struct D : B1, B2 {}; // expected-error {{multiple functions 'sameretain' found; there must be exactly one retain function for reference type 'D'}}
314314
// expected-error@-1 {{multiple functions 'samerelease' found; there must be exactly one release function for reference type 'D'}}
315-
D *returnD() { return new D(); };
315+
D *returnD() { return new D(); }; // expected-warning {{'returnD' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
316316
} // namespace OverloadedRetainRelease
317317

318318
void sameretain(OverloadedRetainRelease::B1 *v) {}
@@ -339,7 +339,7 @@ struct BVirtual : virtual A {};
339339
struct CVirtual : virtual A {};
340340

341341
struct VirtualDiamond : BVirtual, CVirtual {};
342-
VirtualDiamond *returnVirtualDiamond() { return new VirtualDiamond(); };
342+
VirtualDiamond *returnVirtualDiamond() { return new VirtualDiamond(); }; // expected-warning {{'returnVirtualDiamond' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
343343
} // namespace RefTypeDiamondInheritance
344344

345345
void retainA(RefTypeDiamondInheritance::A *a) {};
@@ -355,7 +355,7 @@ __attribute__((swift_attr("release:releaseB"))) B : A {};
355355
struct C : A {};
356356

357357
struct Diamond : B, C {};
358-
Diamond *returnDiamond() { return new Diamond(); };
358+
Diamond *returnDiamond() { return new Diamond(); }; // expected-warning {{'returnDiamond' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
359359

360360
} // namespace NonRefTypeDiamondInheritance
361361

@@ -384,7 +384,7 @@ __attribute__((swift_attr("retain:forestRetain"))) __attribute__((
384384
};
385385

386386
class Forest : public IntrusiveRefCountedTemplate<Forest> {};
387-
Forest *returnForest() { return new Forest(); };
387+
Forest *returnForest() { return new Forest(); }; // expected-warning {{'returnForest' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
388388
} // namespace InheritingTemplatedRefType
389389

390390
void forestRetain(InheritingTemplatedRefType::IntrusiveRefCountedTemplate<

test/Interop/Cxx/foreign-reference/frt-retained-unretained-attributes-error.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// RUN: rm -rf %t
2-
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs %s -cxx-interoperability-mode=upcoming-swift -verify-additional-file %S/Inputs/cxx-functions-and-methods-returning-frt.h -Xcc -Wno-return-type -Xcc -Wno-nullability-completeness
2+
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs %s -cxx-interoperability-mode=upcoming-swift -enable-experimental-feature WarnUnannotatedReturnOfCxxFrt -verify-additional-file %S/Inputs/cxx-functions-and-methods-returning-frt.h -Xcc -Wno-return-type -Xcc -Wno-nullability-completeness
33

44
// XFAIL: OS=windows-msvc
55
// TODO: Enable this on windows when -verify-additional-file issue on Windows Swift CI is resolved
66

7+
// REQUIRES: swift_feature_WarnUnannotatedReturnOfCxxFrt
8+
79
import FunctionsAndMethodsReturningFRT
810
import CxxStdlib
911

@@ -43,3 +45,5 @@ let _ = DefaultOwnershipInheritance.createDerivedType2()
4345
let _ = DefaultOwnershipInheritance.createBaseTypeNonDefault()
4446
let _ = DefaultOwnershipInheritance.createDerivedTypeNonDefault()
4547
let _ = DefaultOwnershipInheritance.createDerivedTypeNonDefaultUnretained()
48+
let _ = SourceLocationCaching.FactoryA.make()
49+
let _ = SourceLocationCaching.FactoryB.make()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs -cxx-interoperability-mode=default -enable-experimental-feature WarnUnannotatedReturnOfCxxFrt -disable-availability-checking -Xcc -fdiagnostics-show-note-include-stack -diagnostic-style llvm %s 2>&1 | %FileCheck %s
2+
3+
// REQUIRES: swift_feature_WarnUnannotatedReturnOfCxxFrt
4+
5+
import FunctionsAndMethodsReturningFRT
6+
7+
func testCaching() {
8+
_ = SourceLocationCaching.FactoryA.make()
9+
_ = SourceLocationCaching.FactoryB.make()
10+
}
11+
12+
// CHECK: warning: '{{.*}}make{{.*}}' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE
13+
// CHECK-NOT: warning: '{{.*}}make{{.*}}' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE

test/Interop/Cxx/foreign-reference/inheritance-diagnostics.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: rm -rf %t
2-
// RUN: %target-swift-frontend -typecheck -verify -I %S%{fs-sep}Inputs %s -cxx-interoperability-mode=upcoming-swift -verify-additional-file %S%{fs-sep}Inputs%{fs-sep}inheritance.h -Xcc -Wno-return-type -Xcc -Wno-inaccessible-base
2+
// 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
3+
4+
// REQUIRES: swift_feature_WarnUnannotatedReturnOfCxxFrt
35

46
import Inheritance
57

0 commit comments

Comments
 (0)