File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed
test/Interop/SwiftToCxx/class Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,19 @@ void ClangClassTypePrinter::printClassTypeDecl(
52
52
<< cxx_synthesis::getCxxImplNamespaceName ()
53
53
<< " ::swift_retain(_opaquePointer); }\n " ;
54
54
55
+ os << " inline " ;
56
+ printer.printBaseName (typeDecl);
57
+ os << " & operator=(const " ;
58
+ printer.printBaseName (typeDecl);
59
+ os << " & other) noexcept {\n swift::"
60
+ << cxx_synthesis::getCxxImplNamespaceName ()
61
+ << " ::swift_retain(other._opaquePointer);\n " ;
62
+ os << " swift::" << cxx_synthesis::getCxxImplNamespaceName ()
63
+ << " ::swift_release(_opaquePointer);\n " ;
64
+ os << " _opaquePointer = other._opaquePointer;\n " ;
65
+ os << " return *this;\n " ;
66
+ os << " }\n " ;
67
+
55
68
// FIXME: move semantics should be restricted?
56
69
os << " inline " ;
57
70
printer.printBaseName (typeDecl);
Original file line number Diff line number Diff line change @@ -74,6 +74,24 @@ int main() {
74
74
assert (getRetainCount (x) == 1 );
75
75
}
76
76
// CHECK-NEXT: init ClassWithIntField
77
+ // CHECK-NEXT: destroy ClassWithIntField
78
+
79
+ {
80
+ auto x = returnClassWithIntField ();
81
+ {
82
+ auto x2 = returnClassWithIntField ();
83
+ assert (getRetainCount (x2) == 1 );
84
+ assert (getRetainCount (x) == 1 );
85
+ x = x2;
86
+ assert (getRetainCount (x) == 2 );
87
+ }
88
+ takeClassWithIntField (x);
89
+ assert (getRetainCount (x) == 1 );
90
+ }
91
+ // CHECK-NEXT: init ClassWithIntField
92
+ // CHECK-NEXT: init ClassWithIntField
93
+ // CHECK-NEXT: destroy ClassWithIntField
94
+ // CHECK-NEXT: ClassWithIntField: 0;
77
95
// CHECK-NEXT: destroy ClassWithIntField
78
96
return 0 ;
79
97
}
Original file line number Diff line number Diff line change @@ -34,7 +34,13 @@ 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
+ // CHECK-NEXT: inline ClassWithIntField(const ClassWithIntField& other) noexcept : _opaquePointer(other._opaquePointer) { swift::_impl::swift_retain(_opaquePointer); }
38
+ // CHECK-NEXT: inline ClassWithIntField & operator=(const ClassWithIntField& other) noexcept {
39
+ // CHECK-NEXT: swift::_impl::swift_retain(other._opaquePointer);
40
+ // CHECK-NEXT: swift::_impl::swift_release(_opaquePointer);
41
+ // CHECK-NEXT: _opaquePointer = other._opaquePointer;
42
+ // CHECK-NEXT: return *this;
43
+ // CHECK-NEXT: }
38
44
// CHECK-NEXT: inline ClassWithIntField(ClassWithIntField&&) noexcept = default;
39
45
// CHECK-NEXT: private:
40
46
// CHECK-NEXT: inline ClassWithIntField(void * _Nonnull ptr) noexcept : _opaquePointer(ptr) {}
You can’t perform that action at this time.
0 commit comments