Files
swift-mirror/test/Interop/Cxx/class/zero-sized-field.swift
Gabor Horvath 998591e9f9 [cxx-interop] Do not import zero-sized fields
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
2025-02-03 11:55:54 +00:00

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()