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 {
47
47
int test () const { return b - a ; }
48
48
int testMutable () { return b - a ; }
49
49
50
+ IntPair & instancePassThroughByRef (IntPair & ref ) { return ref ; }
51
+ static IntPair & staticPassThroughByRef (IntPair & ref ) { return ref ; }
50
52
static IntPair * create () { return new (malloc (sizeof (IntPair ))) IntPair (); }
51
53
};
52
54
@@ -55,6 +57,7 @@ void mutateIt(IntPair &x) {
55
57
x .b = 4 ;
56
58
}
57
59
IntPair passThroughByValue (IntPair x ) { return x ; }
60
+ IntPair & passThroughByRef (IntPair & x ) { return x ; }
58
61
59
62
struct __attribute__((swift_attr ("import_reference" )))
60
63
__attribute__ ((swift_attr ("retain :immortal ")))
@@ -118,6 +121,17 @@ struct ValueHoldingPair {
118
121
}
119
122
};
120
123
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
+
121
135
struct __attribute__((swift_attr ("import_reference" )))
122
136
__attribute__ ((swift_attr ("retain :immortal ")))
123
137
__attribute__((swift_attr ("release:immortal" ))) BigType {
Original file line number Diff line number Diff line change 24
24
// CHECK-NOT: init
25
25
// CHECK: func test() -> Int32
26
26
// CHECK: func testMutable() -> Int32
27
+ // CHECK: func instancePassThroughByRef(_ ref: IntPair) -> IntPair
28
+ // CHECK: class func staticPassThroughByRef(_ ref: IntPair) -> IntPair
27
29
// CHECK: class func create() -> IntPair
28
30
// CHECK: var a: Int32
29
31
// CHECK: var b: Int32
30
32
// CHECK: }
31
33
// CHECK: func mutateIt(_ x: IntPair)
32
34
// CHECK-NOT: func passThroughByValue(_ x: IntPair) -> IntPair
35
+ // CHECK: func passThroughByRef(_ x: IntPair) -> IntPair
33
36
34
37
// CHECK: class RefHoldingPair {
35
38
// CHECK-NOT: init
68
71
// CHECK: var otherValue: Int32
69
72
// CHECK: }
70
73
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
+
71
81
// CHECK: class BigType {
72
82
// CHECK-NOT: init
73
83
// CHECK: func test() -> Int32
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ PODTestSuite.test("RefHoldingPairPtr") {
114
114
expectEqual ( x. test ( ) , 41 )
115
115
}
116
116
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
+
117
127
PODTestSuite . test ( " StructHoldingPair " ) {
118
128
var x = StructHoldingPair ( pair: IntPair . create ( ) )
119
129
expectEqual ( x. pair. test ( ) , 1 )
You can’t perform that action at this time.
0 commit comments