Skip to content

Commit a8ed297

Browse files
committed
[interop][SwiftToCxx] class bridging: use makeRetained to return a class value from Swift
1 parent 399530a commit a8ed297

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/PrintAsClang/PrintClangClassType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void ClangClassTypePrinter::printClassTypeDecl(
7070
os << "public:\n";
7171
os << "static inline ";
7272
printer.printBaseName(typeDecl);
73-
os << " fromUnretained(void * _Nonnull ptr) noexcept { return ";
73+
os << " makeRetained(void * _Nonnull ptr) noexcept { return ";
7474
printer.printBaseName(typeDecl);
7575
os << "(ptr); }\n";
7676
os << "};\n";
@@ -85,7 +85,7 @@ void ClangClassTypePrinter::printClassTypeReturnScaffold(
8585
type->getModuleContext(), moduleContext);
8686
os << cxx_synthesis::getCxxImplNamespaceName() << "::";
8787
ClangValueTypePrinter::printCxxImplClassName(os, type);
88-
os << "::fromUnretained(";
88+
os << "::makeRetained(";
8989
bodyPrinter();
9090
os << ");\n";
9191
}

test/Interop/SwiftToCxx/class/swift-class-in-cxx.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class ClassWithIntField {
4343
// CHECK-EMPTY:
4444
// CHECK-NEXT:class _impl_ClassWithIntField {
4545
// CHECK-NEXT:public:
46-
// CHECK-NEXT:static inline ClassWithIntField fromUnretained(void * _Nonnull ptr) noexcept { return ClassWithIntField(ptr); }
46+
// CHECK-NEXT:static inline ClassWithIntField makeRetained(void * _Nonnull ptr) noexcept { return ClassWithIntField(ptr); }
4747
// CHECK-NEXT:};
4848
// CHECK-EMPTY:
4949
// CHECK-NEXT:} // namespace _impl
@@ -57,5 +57,5 @@ public func returnClassWithIntField() -> ClassWithIntField {
5757
}
5858

5959
// CHECK: inline ClassWithIntField returnClassWithIntField() noexcept SWIFT_WARN_UNUSED_RESULT {
60-
// CHECK-NEXT: return _impl::_impl_ClassWithIntField::fromUnretained(_impl::$s5Class06returnA12WithIntFieldAA0acdE0CyF());
60+
// CHECK-NEXT: return _impl::_impl_ClassWithIntField::makeRetained(_impl::$s5Class06returnA12WithIntFieldAA0acdE0CyF());
6161
// CHECK-NEXT: }

0 commit comments

Comments
 (0)