File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
test/Interop/SwiftToCxx/class Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,14 @@ void ClangClassTypePrinter::printClassTypeDecl(
44
44
os << " () { swift::" << cxx_synthesis::getCxxImplNamespaceName ()
45
45
<< " ::swift_release(_opaquePointer); }\n " ;
46
46
47
+ os << " inline " ;
48
+ printer.printBaseName (typeDecl);
49
+ os << " (const " ;
50
+ printer.printBaseName (typeDecl);
51
+ os << " & other) noexcept : _opaquePointer(other._opaquePointer) { swift::"
52
+ << cxx_synthesis::getCxxImplNamespaceName ()
53
+ << " ::swift_retain(_opaquePointer); }\n " ;
54
+
47
55
// FIXME: move semantics should be restricted?
48
56
os << " inline " ;
49
57
printer.printBaseName (typeDecl);
Original file line number Diff line number Diff line change @@ -63,6 +63,17 @@ int main() {
63
63
// CHECK-NEXT: init ClassWithIntField
64
64
// CHECK-NEXT: destroy ClassWithIntField
65
65
// CHECK-NEXT: ClassWithIntField: -11;
66
+ // CHECK-NEXT: destroy ClassWithIntField
67
+
68
+ {
69
+ auto x = returnClassWithIntField ();
70
+ {
71
+ auto x2 = x;
72
+ assert (getRetainCount (x) == 2 );
73
+ }
74
+ assert (getRetainCount (x) == 1 );
75
+ }
76
+ // CHECK-NEXT: init ClassWithIntField
66
77
// CHECK-NEXT: destroy ClassWithIntField
67
78
return 0 ;
68
79
}
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ public final class ClassWithIntField {
34
34
// CHECK-NEXT: class ClassWithIntField final {
35
35
// CHECK-NEXT: public:
36
36
// CHECK-NEXT: inline ~ClassWithIntField() { swift::_impl::swift_release(_opaquePointer); }
37
+ // CHECK-NEXT: inline ClassWithIntField(const ClassWithIntField& other) noexcept : _opaquePointer(other._opaquePointer) { swift::_impl::swift_retain(_opaquePointer); }
37
38
// CHECK-NEXT: inline ClassWithIntField(ClassWithIntField&&) noexcept = default;
38
39
// CHECK-NEXT: private:
39
40
// CHECK-NEXT: inline ClassWithIntField(void * _Nonnull ptr) noexcept : _opaquePointer(ptr) {}
You can’t perform that action at this time.
0 commit comments