Skip to content

Commit c9e86b4

Browse files
committed
[test] UnsafePointer.withMemoryRebound with capacity 1
1 parent 82fa4b0 commit c9e86b4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/stdlib/UnsafePointer.swift.gyb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,20 @@ ${SelfName}TestSuite.test("withMemoryReboundSE0333") {
498498
}
499499
}
500500

501+
${SelfName}TestSuite.test("withMemoryReboundSE0333.capacity1") {
502+
let mutablePtr = UnsafeMutablePointer<(Int,Bool,UInt8)>.allocate(capacity: 1)
503+
defer { mutablePtr.deallocate() }
504+
let ptr = ${SelfName}<(Int, Bool, UInt8)>(mutablePtr)
505+
// test rebinding to a shorter type with the same alignment
506+
ptr.withMemoryRebound(to: (Int, Bool).self, capacity: 1) {
507+
// Make sure the closure argument is a ${SelfName}
508+
let ptrT: ${SelfName}<(Int, Bool)> = $0
509+
// and that the element is (Int, Bool).
510+
let mutablePtrT = UnsafeMutablePointer(mutating: ptrT)
511+
expectType((Int, Bool).self, &mutablePtrT.pointee)
512+
}
513+
}
514+
501515
% end
502516

503517
runAllTests()

0 commit comments

Comments
 (0)