Skip to content

Commit 7012efd

Browse files
committed
[interop][SwiftToCxx] add a testcase for generic struct passthrough
1 parent 942523f commit 7012efd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

test/Interop/SwiftToCxx/generics/generic-struct-execution.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ int main() {
1919
auto x = makeGenericPair<int, int>(11, 42);
2020
takeGenericPair(x);
2121
// CHECK: GenericPair<Int32, Int32>(x: 11, y: 42)
22+
auto xprime = passThroughGenericPair(x, -995);
23+
takeGenericPair(x);
24+
takeGenericPair(xprime);
25+
// CHECK-NEXT: GenericPair<Int32, Int32>(x: 11, y: 42)
26+
// CHECK-NEXT: GenericPair<Int32, Int32>(x: 11, y: -995)
2227
return 0;
2328
}

test/Interop/SwiftToCxx/generics/generic-struct-in-cxx.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ public func takeGenericPair<T, T1>(_ x: GenericPair<T, T1>) {
2525
print(x)
2626
}
2727

28+
public func passThroughGenericPair<T1, T>(_ x: GenericPair<T1, T>, _ y: T) -> GenericPair<T1, T> {
29+
return GenericPair<T1, T>(x: x.x, y: y)
30+
}
31+
2832
// CHECK: template<class T_0_0, class T_0_1>
2933
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1>
3034
// CHECK-NEXT: class _impl_GenericPair;
3135
// CHECK-EMPTY:
32-
// CHECK-NEXT: static_assert(2 <= 3, "unsupported generic requirement list for metadata func");
36+
// CHECK-NEXT: static_assert(2 <= 3, "unsupported generic requirement list for metadata func");
3337
// CHECK-NEXT: // Type metadata accessor for GenericPair
3438
// CHECK-NEXT: SWIFT_EXTERN swift::_impl::MetadataResponseTy $s8Generics11GenericPairVMa(swift::_impl::MetadataRequestTy, void * _Nonnull, void * _Nonnull) SWIFT_NOEXCEPT SWIFT_CALL;
3539

@@ -69,6 +73,14 @@ public func takeGenericPair<T, T1>(_ x: GenericPair<T, T1>) {
6973
// CHECK-NEXT: });
7074
// CHECK-NEXT: }
7175

76+
// CHECK: template<class T1, class T>
77+
// CHECK-NEXT: requires swift::isUsableInGenericContext<T1> && swift::isUsableInGenericContext<T>
78+
// CHECK-NEXT: inline GenericPair<T1, T> passThroughGenericPair(const GenericPair<T1, T>& x, const T & y) noexcept SWIFT_WARN_UNUSED_RESULT {
79+
// CHECK-NEXT: return _impl::_impl_GenericPair<T1, T>::returnNewValue([&](void * _Nonnull result) {
80+
// CHECK-NEXT: _impl::$s8Generics22passThroughGenericPairyAA0dE0Vyxq_GAE_q_tr0_lF(result, _impl::_impl_GenericPair<T1, T>::getOpaquePointer(x), swift::_impl::getOpaquePointer(y), swift::getTypeMetadata<T1>(), swift::getTypeMetadata<T>());
81+
// CHECK-NEXT: });
82+
// CHECK-NEXT: }
83+
7284
// CHECK: template<class T, class T1>
7385
// CHECK-NEXT: requires swift::isUsableInGenericContext<T> && swift::isUsableInGenericContext<T1>
7486
// CHECK-NEXT: inline void takeGenericPair(const GenericPair<T, T1>& x) noexcept {

0 commit comments

Comments
 (0)