diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 023e463753b32..cd2f3a9f4f6e0 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -3660,6 +3660,7 @@ namespace { unannotatedAPIWarningNeeded = false; } + unannotatedAPIWarningNeeded = false; if (unannotatedAPIWarningNeeded) { HeaderLoc loc(decl->getLocation()); Impl.diagnose(loc, diag::no_returns_retained_returns_unretained, diff --git a/test/Interop/Cxx/foreign-reference/Inputs/cxx-functions-and-methods-returning-frt.h b/test/Interop/Cxx/foreign-reference/Inputs/cxx-functions-and-methods-returning-frt.h index d77ce3b866c47..b40e3adfbf0fa 100644 --- a/test/Interop/Cxx/foreign-reference/Inputs/cxx-functions-and-methods-returning-frt.h +++ b/test/Interop/Cxx/foreign-reference/Inputs/cxx-functions-and-methods-returning-frt.h @@ -5,9 +5,9 @@ // FRT or SWIFT_SHARED_REFERENCE type struct FRTStruct { // Friend function declarations - 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}} - 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}} - 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}} + friend FRTStruct *returnInstanceOfFRTStruct(int v); + friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsRetained(int v); + friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsUnretained(int v); } __attribute__((swift_attr("import_reference"))) __attribute__((swift_attr("retain:retainFRTStruct"))) __attribute__((swift_attr("release:releaseFRTStruct"))); @@ -179,12 +179,12 @@ __attribute__((swift_attr("unsafe"))); // C++ APIs returning cxx frts (for testing diagnostics) struct StructWithAPIsReturningCxxFrt { - 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}} + static FRTStruct *_Nonnull StaticMethodReturningCxxFrt(); static FRTStruct *_Nonnull StaticMethodReturningCxxFrtWithAnnotation() __attribute__((swift_attr("returns_retained"))); }; -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}} +FRTStruct *_Nonnull global_function_returning_cxx_frt(); FRTStruct *_Nonnull global_function_returning_cxx_frt_with_annotations() __attribute__((swift_attr("returns_retained"))); @@ -303,7 +303,7 @@ __attribute__((swift_attr( operator-(const FRTOverloadedOperators &other); }; -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}} +FRTOverloadedOperators *_Nonnull returnFRTOverloadedOperators(); void retain_FRTOverloadedOperators(FRTOverloadedOperators *_Nonnull v); void release_FRTOverloadedOperators(FRTOverloadedOperators *_Nonnull v); @@ -371,7 +371,7 @@ struct __attribute__((swift_attr("import_reference"))) __attribute__((swift_attr("retain:rretain"))) __attribute__((swift_attr("release:rrelease"))) RefType {}; -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}} +RefType *returnRefType() { return new RefType(); } struct __attribute__((swift_attr("import_reference"))) __attribute__((swift_attr("retain:dretain"))) @@ -420,10 +420,10 @@ __attribute__((swift_attr("retain:dRetain"))) __attribute__((swift_attr("release:dRelease"))) DerivedTypeNonDefault : public BaseTypeNonDefault {}; -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}} +BaseTypeNonDefault *createBaseTypeNonDefault() { return new BaseTypeNonDefault(); } -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}} +DerivedTypeNonDefault *createDerivedTypeNonDefault() { return new DerivedTypeNonDefault(); } diff --git a/test/Interop/Cxx/foreign-reference/Inputs/inheritance.h b/test/Interop/Cxx/foreign-reference/Inputs/inheritance.h index 91db728a6e498..e973baa019946 100644 --- a/test/Interop/Cxx/foreign-reference/Inputs/inheritance.h +++ b/test/Interop/Cxx/foreign-reference/Inputs/inheritance.h @@ -109,8 +109,8 @@ __attribute__((swift_attr("release:immortal"))) ImmortalRefType {}; ImmortalRefType *returnImmortalRefType() { return new ImmortalRefType(); }; struct DerivedFromImmortalRefType : ImmortalRefType {}; -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}} - return new DerivedFromImmortalRefType(); +DerivedFromImmortalRefType *returnDerivedFromImmortalRefType() { + return new DerivedFromImmortalRefType(); }; } // namespace ImmortalRefereceExample @@ -122,7 +122,7 @@ ValueType *returnValueType() { return new ValueType(); } struct __attribute__((swift_attr("import_reference"))) __attribute__((swift_attr("retain:ret1"))) __attribute__((swift_attr("release:rel1"))) RefType {}; -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}} +RefType *returnRefType() { return new RefType(); } struct DerivedFromValueType : ValueType {}; DerivedFromValueType *returnDerivedFromValueType() { @@ -133,21 +133,21 @@ struct __attribute__((swift_attr("import_reference"))) __attribute__((swift_attr("retain:ret2"))) __attribute__((swift_attr("release:rel2"))) DerivedFromValueTypeAndAnnotated : ValueType {}; -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}} - return new DerivedFromValueTypeAndAnnotated(); +DerivedFromValueTypeAndAnnotated *returnDerivedFromValueTypeAndAnnotated() { + return new DerivedFromValueTypeAndAnnotated(); } struct DerivedFromRefType final : RefType {}; -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}} - return new DerivedFromRefType(); +DerivedFromRefType *returnDerivedFromRefType() { + return new DerivedFromRefType(); } struct __attribute__((swift_attr("import_reference"))) __attribute__((swift_attr("retain:ret3"))) __attribute__((swift_attr("release:rel3"))) DerivedFromRefTypeAndAnnotated : RefType {}; -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}} - return new DerivedFromRefTypeAndAnnotated(); +DerivedFromRefTypeAndAnnotated *returnDerivedFromRefTypeAndAnnotated() { + return new DerivedFromRefTypeAndAnnotated(); } } // namespace ExplicitAnnotationHasPrecedence1 @@ -184,8 +184,8 @@ __attribute__((swift_attr("retain:retain_C"))) __attribute__((swift_attr("release:release_C"))) DerivedFromRefTypeAAndBAnnotated : RefTypeA, RefTypeB {}; -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}} - return new DerivedFromRefTypeAAndBAnnotated(); +DerivedFromRefTypeAAndBAnnotated *returnDerivedFromRefTypeAAndBAnnotated() { + return new DerivedFromRefTypeAAndBAnnotated(); } } // namespace ExplicitAnnotationHasPrecedence2 @@ -206,10 +206,10 @@ struct __attribute__((swift_attr("import_reference"))) __attribute__((swift_attr("retain:RCRetain"))) __attribute__((swift_attr("release:RCRelease"))) RefType {}; -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}} +RefType *returnRefType() { return new RefType(); }; struct DerivedFromRefType final : RefType {}; -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}} +DerivedFromRefType *returnDerivedFromRefType() { return new DerivedFromRefType(); }; } // namespace BasicInheritanceExample @@ -236,7 +236,7 @@ DerivedFromBaseRef1AndBaseRef2 *returnDerivedFromBaseRef1AndBaseRef2() { }; struct DerivedFromBaseRef3 : BaseRef3 {}; -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}} +DerivedFromBaseRef3 *returnDerivedFromBaseRef3() { return new DerivedFromBaseRef3(); }; } // namespace MultipleInheritanceExample1 @@ -312,7 +312,7 @@ __attribute__((swift_attr("release:samerelease"))) B2 {}; // expected-error {{m struct D : B1, B2 {}; // expected-error {{multiple functions 'sameretain' found; there must be exactly one retain function for reference type 'D'}} // expected-error@-1 {{multiple functions 'samerelease' found; there must be exactly one release function for reference type 'D'}} -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}} +D *returnD() { return new D(); }; } // namespace OverloadedRetainRelease void sameretain(OverloadedRetainRelease::B1 *v) {} @@ -339,7 +339,7 @@ struct BVirtual : virtual A {}; struct CVirtual : virtual A {}; struct VirtualDiamond : BVirtual, CVirtual {}; -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}} +VirtualDiamond *returnVirtualDiamond() { return new VirtualDiamond(); }; } // namespace RefTypeDiamondInheritance void retainA(RefTypeDiamondInheritance::A *a) {}; @@ -355,7 +355,7 @@ __attribute__((swift_attr("release:releaseB"))) B : A {}; struct C : A {}; struct Diamond : B, C {}; -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}} +Diamond *returnDiamond() { return new Diamond(); }; } // namespace NonRefTypeDiamondInheritance @@ -384,7 +384,7 @@ __attribute__((swift_attr("retain:forestRetain"))) __attribute__(( }; class Forest : public IntrusiveRefCountedTemplate {}; -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}} +Forest *returnForest() { return new Forest(); }; } // namespace InheritingTemplatedRefType void forestRetain(InheritingTemplatedRefType::IntrusiveRefCountedTemplate< diff --git a/test/Interop/Cxx/objc-correctness/Inputs/cxx-frt.h b/test/Interop/Cxx/objc-correctness/Inputs/cxx-frt.h index e4d03ada7ea47..5fd617ffefbb4 100644 --- a/test/Interop/Cxx/objc-correctness/Inputs/cxx-frt.h +++ b/test/Interop/Cxx/objc-correctness/Inputs/cxx-frt.h @@ -16,7 +16,7 @@ void releaseCxxRefType(CxxRefType *_Nonnull b) {} @interface Bridge : NSObject -+ (struct CxxRefType *)objCMethodReturningFRTUnannotated; // expected-warning {{'objCMethodReturningFRTUnannotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}} ++ (struct CxxRefType *)objCMethodReturningFRTUnannotated; + (struct CxxRefType *)objCMethodReturningFRTUnowned __attribute__((swift_attr("returns_unretained"))); + (struct CxxRefType *)objCMethodReturningFRTOwned