File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
test/Interop/Cxx/foreign-reference Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ __attribute__((swift_attr("release:immortal"))) IntPair {
4747 int test () const { return b - a ; }
4848 int testMutable () { return b - a ; }
4949
50+ IntPair & instancePassThroughByRef (IntPair & ref ) { return ref ; }
51+ static IntPair & staticPassThroughByRef (IntPair & ref ) { return ref ; }
5052 static IntPair * create () { return new (malloc (sizeof (IntPair ))) IntPair (); }
5153};
5254
@@ -55,6 +57,7 @@ void mutateIt(IntPair &x) {
5557 x .b = 4 ;
5658}
5759IntPair passThroughByValue (IntPair x ) { return x ; }
60+ IntPair & passThroughByRef (IntPair & x ) { return x ; }
5861
5962struct __attribute__((swift_attr ("import_reference" )))
6063__attribute__ ((swift_attr ("retain :immortal ")))
@@ -118,6 +121,17 @@ struct ValueHoldingPair {
118121 }
119122};
120123
124+ struct ValueHoldingPairRef {
125+ IntPair & pair = * IntPair ::create ();
126+
127+ int sub (const IntPair & other ) const {
128+ return pair .test () - other .test ();
129+ };
130+ const IntPair & max (const IntPair & other ) const {
131+ return pair .test () > other .test () ? pair : other ;
132+ };
133+ };
134+
121135struct __attribute__((swift_attr ("import_reference" )))
122136__attribute__ ((swift_attr ("retain :immortal ")))
123137__attribute__((swift_attr ("release:immortal" ))) BigType {
Original file line number Diff line number Diff line change 2424// CHECK-NOT: init
2525// CHECK: func test() -> Int32
2626// CHECK: func testMutable() -> Int32
27+ // CHECK: func instancePassThroughByRef(_ ref: IntPair) -> IntPair
28+ // CHECK: class func staticPassThroughByRef(_ ref: IntPair) -> IntPair
2729// CHECK: class func create() -> IntPair
2830// CHECK: var a: Int32
2931// CHECK: var b: Int32
3032// CHECK: }
3133// CHECK: func mutateIt(_ x: IntPair)
3234// CHECK-NOT: func passThroughByValue(_ x: IntPair) -> IntPair
35+ // CHECK: func passThroughByRef(_ x: IntPair) -> IntPair
3336
3437// CHECK: class RefHoldingPair {
3538// CHECK-NOT: init
6871// CHECK: var otherValue: Int32
6972// CHECK: }
7073
74+ // CHECK: struct ValueHoldingPairRef {
75+ // CHECK-NOT: pair
76+ // CHECK: init()
77+ // CHECK: func sub(_ other: IntPair) -> Int32
78+ // CHECK: func max(_ other: IntPair) -> IntPair
79+ // CHECK: }
80+
7181// CHECK: class BigType {
7282// CHECK-NOT: init
7383// CHECK: func test() -> Int32
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ PODTestSuite.test("RefHoldingPairPtr") {
114114 expectEqual ( x. test ( ) , 41 )
115115}
116116
117+ PODTestSuite . test ( " ValueHoldingPairRef " ) {
118+ let x = ValueHoldingPairRef ( )
119+ expectEqual ( x. pair. test ( ) , 1 )
120+
121+ let pair2 = IntPair . create ( )
122+ pair2. b = 123
123+ expectEqual ( x. sub ( pair2) , - 121 )
124+ expectEqual ( x. max ( pair2) . test ( ) , pair2. test ( ) )
125+ }
126+
117127PODTestSuite . test ( " StructHoldingPair " ) {
118128 var x = StructHoldingPair ( pair: IntPair . create ( ) )
119129 expectEqual ( x. pair. test ( ) , 1 )
You can’t perform that action at this time.
0 commit comments