File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -18,3 +18,7 @@ module StructAsOptionSet {
1818module NoncopyableStructs {
1919 header "noncopyable-struct.h"
2020}
21+
22+ module ReturnForeignReference {
23+ header "return-foreign-reference.h"
24+ }
Original file line number Diff line number Diff line change 1+ #ifndef __RETURN_FOREIGN_REFERENCE_H
2+ #define __RETURN_FOREIGN_REFERENCE_H
3+
4+ struct
5+ __attribute__((swift_attr ("import_reference" )))
6+ __attribute__ ((swift_attr ("retain :FRTRetain ")))
7+ __attribute__((swift_attr ("release:FRTRelease" )))
8+ FRT {
9+ int value ;
10+ };
11+
12+ struct Value { int value ; };
13+
14+ void FRTRetain (struct FRT * x );
15+ void FRTRelease (struct FRT * x );
16+
17+ struct FRT * getFRTNoAnnotations (void ); // expected-note {{annotate}}
18+ struct FRT * getFRTRetained () __attribute__((swift_attr ("returns_retained" )));
19+ struct FRT * getFRTUnretained () __attribute__((swift_attr ("returns_unretained" )));
20+
21+ struct FRT * getFRTUnretained () __attribute__((swift_attr ("returns_unretained" )));
22+
23+ struct FRT * getFRTConflictingAnnotations ()
24+ __attribute__((swift_attr ("returns_retained" )))
25+ __attribute__((swift_attr ("returns_unretained" )));
26+ // expected-error@-3 {{cannot be annotated with both}}
27+
28+ struct Value * getValueRetained () __attribute__((swift_attr ("returns_retained" )));
29+ // expected-warning@-1 {{should not be annotated}}
30+ struct Value * getValueUnretained () __attribute__((swift_attr ("returns_unretained" )));
31+ // expected-warning@-1 {{should not be annotated}}
32+
33+ #endif /* __RETURN_FOREIGN_REFERENCE_H */
Original file line number Diff line number Diff line change 1+ // RUN: %target-typecheck-verify-swift -cxx-interoperability-mode=off \
2+ // RUN: -disable-availability-checking \
3+ // RUN: -I %S%{fs-sep}Inputs \
4+ // RUN: -verify-additional-file %S%{fs-sep}Inputs%{fs-sep}return-foreign-reference.h
5+
6+ import ReturnForeignReference
7+
8+ let _: FRT = getFRTNoAnnotations ( ) // expected-warning {{cannot infer ownership}}
9+ let _: FRT = getFRTRetained ( )
10+ let _: FRT = getFRTUnretained ( )
11+
12+
13+ // These calls to incorrectly annotated functions are necessary to force
14+ // diagnostics to appear in the header file.
15+ let _: FRT = getFRTConflictingAnnotations ( )
16+ let _ = getValueRetained ( )
17+ let _ = getValueUnretained ( )
You can’t perform that action at this time.
0 commit comments