mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Zero sized fields are messing up the offset calculations when we import C++ fields to Swift. We assume that the size of the field is determined by the type of the field. This is not true for fields marked with no_unique_address. Those fields can have 0 size while the sizeof(decltype(field)) is still 1. rdar://143907490
28 lines
692 B
Swift
28 lines
692 B
Swift
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -Xcc -std=c++20)
|
|
//
|
|
// REQUIRES: executable_test
|
|
|
|
import StdlibUnittest
|
|
import MemberVariables
|
|
|
|
var FieldsTestSuite = TestSuite("Generating code with zero sized fields")
|
|
|
|
func takeTypeWithZeroSizedMember(_ x: HasZeroSizedField) {}
|
|
|
|
FieldsTestSuite.test("Zero sized field") {
|
|
var s = HasZeroSizedField()
|
|
s.a = 5
|
|
s.set_c(7)
|
|
takeTypeWithZeroSizedMember(s)
|
|
let s2 = s
|
|
let myInt : Empty.type = 6
|
|
expectEqual(s.a, 5)
|
|
expectEqual(s.a, s.get_a())
|
|
expectEqual(s2.c, 7)
|
|
expectEqual(s2.c, s2.get_c())
|
|
expectEqual(takesZeroSizedInCpp(s2), 5)
|
|
expectEqual(s.b.getNum(), 42)
|
|
}
|
|
|
|
runAllTests()
|