// RUN: %empty-directory(%t) // RUN: %target-swift-frontend %s -module-name UseOptional -enable-experimental-cxx-interop -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/useopt.h // RUN: %check-interop-cxx-header-in-clang(%t/useopt.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY) // RUN: %FileCheck %s < %t/useopt.h public struct SmallStruct { let x: Int16 } public class Klass { let x: Int16 init(_ x: Int16) { self.x = x } } public func createCIntOpt(_ val: CInt) -> Optional { return val } public func takeCIntOpt(_ val: Optional) { print(String(describing: val)) } public func createSmallStructOpt(_ val: Int16) -> SmallStruct? { return SmallStruct(x: val) } public func takeSmallStructOpt(_ val: Optional) { print(String(describing: val)) } public func createKlassOpt(_ val: Int16) -> Klass? { return Klass(val) } public func takeKlassOpt(_ val: Klass?) { print(String(describing: val)) } public func resetOpt(_ val: inout Optional) { val = .none } // CHECK: SWIFT_INLINE_THUNK swift::Optional createCIntOpt(int val) noexcept SWIFT_SYMBOL("s:11UseOptional13createCIntOptys5Int32VSgADF") SWIFT_WARN_UNUSED_RESULT { // CHECK-NEXT: return swift::_impl::_impl_Optional::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES { // CHECK-NEXT: UseOptional::_impl::swift_interop_returnDirect_UseOptional_[[CINTENC:[a-z0-9_]+]](result, UseOptional::_impl::$s11UseOptional13createCIntOptys5Int32VSgADF(val)); // CHECK-NEXT: }); // CHECK-NEXT: } // CHECK: SWIFT_INLINE_THUNK swift::Optional createKlassOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional14createKlassOptyAA0D0CSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT { // CHECK-NEXT: return swift::_impl::_impl_Optional::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES { // CHECK-NEXT: UseOptional::_impl::swift_interop_returnDirect_UseOptional_[[CLASSENC:[a-z0-9_]+]](result, UseOptional::_impl::$s11UseOptional14createKlassOptyAA0D0CSgs5Int16VF(val)); // CHECK-NEXT: }); // CHECK-NEXT: } // CHECK: SWIFT_INLINE_THUNK swift::Optional createSmallStructOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional20createSmallStructOptyAA0dE0VSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT { // CHECK-NEXT: return swift::_impl::_impl_Optional::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES { // CHECK-NEXT: UseOptional::_impl::swift_interop_returnDirect_UseOptional_uint32_t_0_4(result, UseOptional::_impl::$s11UseOptional20createSmallStructOptyAA0dE0VSgs5Int16VF(val)); // CHECK-NEXT: }); // CHECK-NEXT: } // CHECK: template // CHECK-NEXT: #ifdef __cpp_concepts // CHECK-NEXT: requires swift::isUsableInGenericContext // CHECK-NEXT: #endif // CHECK-NEXT: SWIFT_INLINE_THUNK void resetOpt(swift::Optional& val) noexcept SWIFT_SYMBOL("s:11UseOptional8resetOptyyxSgzlF") { // CHECK-NEXT: #ifndef __cpp_concepts // CHECK-NEXT: static_assert(swift::isUsableInGenericContext, "type cannot be used in a Swift generic context"); // CHECK-NEXT: #endif // CHECK-NEXT: _impl::$s11UseOptional8resetOptyyxSgzlF(swift::_impl::_impl_Optional::getOpaquePointer(val), swift::TypeMetadataTrait::getTypeMetadata()); // CHECK-NEXT: } // CHECK: SWIFT_INLINE_THUNK void takeCIntOpt(const swift::Optional& val) noexcept SWIFT_SYMBOL("s:11UseOptional11takeCIntOptyys5Int32VSgF") { // CHECK-NEXT: UseOptional::_impl::$s11UseOptional11takeCIntOptyys5Int32VSgF(UseOptional::_impl::swift_interop_passDirect_UseOptional_[[CINTENC]](swift::_impl::_impl_Optional::getOpaquePointer(val))); // CHECK-NEXT: } // CHECK: SWIFT_INLINE_THUNK void takeKlassOpt(const swift::Optional& val) noexcept SWIFT_SYMBOL("s:11UseOptional12takeKlassOptyyAA0D0CSgF") { // CHECK-NEXT: UseOptional::_impl::$s11UseOptional12takeKlassOptyyAA0D0CSgF(UseOptional::_impl::swift_interop_passDirect_UseOptional_[[CLASSENC]](swift::_impl::_impl_Optional::getOpaquePointer(val))); // CHECK-NEXT: } // CHECK: SWIFT_INLINE_THUNK void takeSmallStructOpt(const swift::Optional& val) noexcept SWIFT_SYMBOL("s:11UseOptional18takeSmallStructOptyyAA0dE0VSgF") { // CHECK-NEXT: UseOptional::_impl::$s11UseOptional18takeSmallStructOptyyAA0dE0VSgF(UseOptional::_impl::swift_interop_passDirect_UseOptional_uint32_t_0_4(swift::_impl::_impl_Optional::getOpaquePointer(val))); // CHECK-NEXT: }