Files
swift-mirror/test/Interop/SwiftToCxx/structs/zero-sized-struct-in-cxx.swift
Gabor Horvath 22b46d3c9c [cxx-interop] Mark some zero-sized value types as unavailable
Currently, we do not support exporting zero-sized value types from Swift
to C++. It needs some work on our end as these types are not part of the
lowered signature. In the meantime, this PR makes sure that common (but
not all) zero sized types are properly marked as unavailable. This is
important as the proper diagnostic will give users a hint how to work
around this problem. Moreover, it is really easy to hit this when
someone is experimenting with interop, so it is important to not have a
cryptic failure mode.

rdar://138122545
2024-10-28 14:00:35 +00:00

53 lines
1.6 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -module-name Structs -clang-header-expose-decls=all-public -emit-clang-header-path %t/structs.h
// RUN: %FileCheck %s < %t/structs.h
// CHECK: namespace Structs SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Structs") {
// CHECK-NOT: class SWIFT_SYMBOL({{.*}}) ZeroSizedStruct final {
public struct ZeroSizedStruct {}
public struct ZeroSizedStruct2 {
var property: ZeroSizedStruct
var void: Void
var bar: ()
public init() {
property = .init()
}
}
public enum ZeroSizedEnum {
}
public enum ZeroSizedEnum2 {
case foo
}
public enum ZeroSizedEnum3 {
case foo(ZeroSizedStruct, ZeroSizedEnum, ZeroSizedStruct2)
}
public func f() -> ZeroSizedStruct {
ZeroSizedStruct()
}
public func g(x: ZeroSizedStruct) {
}
// CHECK: class ZeroSizedEnum { } SWIFT_UNAVAILABLE_MSG("'ZeroSizedEnum' is a zero sized value type, it cannot be exposed to C++ yet");
// CHECK: class ZeroSizedEnum2 { } SWIFT_UNAVAILABLE_MSG("'ZeroSizedEnum2' is a zero sized value type, it cannot be exposed to C++ yet");
// CHECK: class ZeroSizedEnum3 { } SWIFT_UNAVAILABLE_MSG("'ZeroSizedEnum3' is a zero sized value type, it cannot be exposed to C++ yet");
// CHECK: class ZeroSizedStruct { } SWIFT_UNAVAILABLE_MSG("'ZeroSizedStruct' is a zero sized value type, it cannot be exposed to C++ yet");
// CHECK: class ZeroSizedStruct2 { } SWIFT_UNAVAILABLE_MSG("'ZeroSizedStruct2' is a zero sized value type, it cannot be exposed to C++ yet");
// CHECK: // Unavailable in C++: Swift global function 'f()'.
// CHECK: // Unavailable in C++: Swift global function 'g(x:)'.
// CHECK: } // namespace Structs