@@ -86,17 +86,50 @@ struct PointerOffsetTests {
86
86
typealias Base = Tuple < Int , Double >
87
87
let firstOffset = PointerOffset < Base , Int > ( byteOffset: 0 )
88
88
let secondOffset = PointerOffset < Base , Double > ( byteOffset: 8 )
89
+ withUnsafePointer ( to: tuple) { pointer in
90
+ #expect( pointer [ offset: firstOffset] == 1 )
91
+ #expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 2.0 ) )
92
+ }
89
93
withUnsafeMutablePointer ( to: & tuple) { pointer in
90
94
#expect( pointer [ offset: firstOffset] == 1 )
91
- #expect( pointer [ offset: secondOffset] == 2.0 )
95
+ #expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to : 2.0 ) )
92
96
93
97
pointer [ offset: firstOffset] = 3
94
98
pointer [ offset: secondOffset] = 4.0
99
+
100
+ #expect( pointer [ offset: firstOffset] == 3 )
101
+ #expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 4.0 ) )
95
102
}
103
+ withUnsafePointer ( to: & tuple) { pointer in
104
+ #expect( pointer [ offset: firstOffset] == 3 )
105
+ #expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 4.0 ) )
106
+ }
107
+ #if !canImport(Darwin) && !DEBUG
108
+ // FIXME: The issue only occur on Linux + Release configuration (Swift 5.10)
109
+
110
+ // Uncomment the following withKnownIssue code will make the result back to normal thus causing 5 new issues
111
+ // withKnownIssue {
112
+ // withUnsafePointer(to: tuple) { pointer in
113
+ // #expect(pointer[offset: firstOffset] == 3)
114
+ // #expect(pointer[offset: secondOffset].isApproximatelyEqual(to: 4.0))
115
+ // }
116
+ // #expect(tuple.first == 3)
117
+ // #expect(tuple.second.isApproximatelyEqual(to: 4.0))
118
+ // }
119
+ withUnsafePointer ( to: tuple) { pointer in
120
+ #expect( pointer [ offset: firstOffset] == 1 )
121
+ #expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 2.0 ) )
122
+ }
123
+ #expect( tuple. first == 1 )
124
+ #expect( tuple. second. isApproximatelyEqual ( to: 2.0 ) )
125
+ #else
96
126
withUnsafePointer ( to: tuple) { pointer in
97
127
#expect( pointer [ offset: firstOffset] == 3 )
98
128
#expect( pointer [ offset: secondOffset] . isApproximatelyEqual ( to: 4.0 ) )
99
129
}
130
+ #expect( tuple. first == 3 )
131
+ #expect( tuple. second. isApproximatelyEqual ( to: 4.0 ) )
132
+ #endif
100
133
}
101
134
102
135
do {
@@ -106,6 +139,12 @@ struct PointerOffsetTests {
106
139
let firstOffset = PointerOffset < Base , Int > . offset { . of( & $0. first) }
107
140
let secondOffset = PointerOffset < Base , Int > . offset { . of( & $0. second) }
108
141
let thirdOffset = PointerOffset < Base , Int > . offset { . of( & $0. third) }
142
+
143
+ withUnsafePointer ( to: triple) { pointer in
144
+ #expect( ( pointer + firstOffset) . pointee == 0 )
145
+ #expect( ( pointer + secondOffset) . pointee == 1 )
146
+ #expect( ( pointer + thirdOffset) . pointee == 2 )
147
+ }
109
148
withUnsafeMutablePointer ( to: & triple) { pointer in
110
149
#expect( ( pointer + firstOffset) . pointee == 0 )
111
150
#expect( ( pointer + secondOffset) . pointee == 1 )
@@ -114,12 +153,48 @@ struct PointerOffsetTests {
114
153
( pointer + firstOffset) . pointee = 3
115
154
( pointer + secondOffset) . pointee = 4
116
155
( pointer + thirdOffset) . pointee = 5
156
+
157
+ #expect( ( pointer + firstOffset) . pointee == 3 )
158
+ #expect( ( pointer + secondOffset) . pointee == 4 )
159
+ #expect( ( pointer + thirdOffset) . pointee == 5 )
160
+ }
161
+ withUnsafePointer ( to: & triple) { pointer in
162
+ #expect( ( pointer + firstOffset) . pointee == 3 )
163
+ #expect( ( pointer + secondOffset) . pointee == 4 )
164
+ #expect( ( pointer + thirdOffset) . pointee == 5 )
165
+ }
166
+ #if !canImport(Darwin) && !DEBUG
167
+ // FIXME: The issue only occur on Linux + Release configuration (Swift 5.10)
168
+
169
+ // Uncomment the following withKnownIssue code will make the result back to normal thus causing 7 new issues
170
+ // withKnownIssue {
171
+ // withUnsafePointer(to: triple) { pointer in
172
+ // #expect((pointer + firstOffset).pointee == 3)
173
+ // #expect((pointer + secondOffset).pointee == 4)
174
+ // #expect((pointer + thirdOffset).pointee == 5)
175
+ // }
176
+ // #expect(triple.first == 3)
177
+ // #expect(triple.second == 4)
178
+ // #expect(triple.third == 5)
179
+ // }
180
+ withUnsafePointer ( to: triple) { pointer in
181
+ #expect( ( pointer + firstOffset) . pointee == 0 )
182
+ #expect( ( pointer + secondOffset) . pointee == 1 )
183
+ #expect( ( pointer + thirdOffset) . pointee == 2 )
117
184
}
185
+ #expect( triple. first == 0 )
186
+ #expect( triple. second == 1 )
187
+ #expect( triple. third == 2 )
188
+ #else
118
189
withUnsafePointer ( to: triple) { pointer in
119
190
#expect( ( pointer + firstOffset) . pointee == 3 )
120
191
#expect( ( pointer + secondOffset) . pointee == 4 )
121
192
#expect( ( pointer + thirdOffset) . pointee == 5 )
122
193
}
194
+ #expect( triple. first == 3 )
195
+ #expect( triple. second == 4 )
196
+ #expect( triple. third == 5 )
197
+ #endif
123
198
}
124
199
}
125
200
}
0 commit comments