File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
test/Interop/Cxx/operators Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -2221,7 +2221,21 @@ namespace {
2221
2221
MD->overwriteAccess (AccessLevel::Private);
2222
2222
} else if (cxxOperatorKind ==
2223
2223
clang::OverloadedOperatorKind::OO_PlusPlus) {
2224
- if (cxxMethod->param_empty ()) {
2224
+ // Make sure the type is not an immortal foreign reference type.
2225
+ // We cannot handle `operator++` for those types, since the
2226
+ // current implementation creates a new instance of the type.
2227
+ bool isImmortal = false ;
2228
+ if (auto classDecl = dyn_cast<ClassDecl>(result)) {
2229
+ auto retainOperation = evaluateOrDefault (
2230
+ Impl.SwiftContext .evaluator ,
2231
+ CustomRefCountingOperation (
2232
+ {classDecl, CustomRefCountingOperationKind::retain}),
2233
+ {});
2234
+ isImmortal = retainOperation.kind ==
2235
+ CustomRefCountingOperationResult::immortal;
2236
+ }
2237
+
2238
+ if (cxxMethod->param_empty () && !isImmortal) {
2225
2239
// This is a pre-increment operator. We synthesize a
2226
2240
// non-mutating function called `successor() -> Self`.
2227
2241
FuncDecl *successorFunc = synthesizer.makeSuccessorFunc (MD);
Original file line number Diff line number Diff line change @@ -85,6 +85,18 @@ struct HasPreIncrementOperatorWithVoidReturnType {
85
85
void operator ++() { ++value; }
86
86
};
87
87
88
+ struct __attribute__ ((swift_attr(" import_reference" ),
89
+ swift_attr (" retain:immortal" ),
90
+ swift_attr(" release:immortal" ))) ImmortalCounter {
91
+ int value = 0 ;
92
+
93
+ ImmortalCounter &operator ++() {
94
+ value++;
95
+ return *this ;
96
+ }
97
+ };
98
+ static ImmortalCounter myCounter;
99
+
88
100
struct HasDeletedOperator {
89
101
void operator !=(HasDeletedOperator) const = delete ;
90
102
};
Original file line number Diff line number Diff line change @@ -49,3 +49,5 @@ let anotherReturnTypeResult: HasPreIncrementOperatorWithAnotherReturnType = anot
49
49
50
50
let voidReturnType = HasPreIncrementOperatorWithVoidReturnType ( )
51
51
let voidReturnTypeResult : HasPreIncrementOperatorWithVoidReturnType = voidReturnType. successor ( )
52
+
53
+ let immortalIncrement = myCounter. successor ( ) // expected-error {{value of type 'ImmortalCounter' has no member 'successor'}}
You can’t perform that action at this time.
0 commit comments