Skip to content

Commit 25a8885

Browse files
authored
Merge pull request #76170 from swiftlang/gaborh/read-accessor
[cxx-interop] Do not attempt to export read accessors to C++
2 parents 6e5702b + 131a354 commit 25a8885

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,9 +2069,10 @@ class DeclAndTypePrinter::Implementation
20692069
if (outputLang == OutputLanguageMode::Cxx) {
20702070
if (!SD->isInstanceMember())
20712071
return;
2072-
auto *getter = SD->getOpaqueAccessor(AccessorKind::Get);
2073-
printAbstractFunctionAsMethod(getter, false,
2074-
/*isNSUIntegerSubscript=*/false, SD);
2072+
// TODO: support read accessors.
2073+
if (auto *getter = SD->getOpaqueAccessor(AccessorKind::Get))
2074+
printAbstractFunctionAsMethod(getter, false,
2075+
/*isNSUIntegerSubscript=*/false, SD);
20752076
return;
20762077
}
20772078
assert(SD->isInstanceMember() && "static subscripts not supported");

test/Interop/SwiftToCxx/functions/swift-operators.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ public struct IntBox {
2525
}
2626
}
2727

28+
public struct CustomArray<Element> where Element : ~Copyable {
29+
private var buffer: UnsafeMutableBufferPointer<Element>
30+
31+
public subscript(index: Int) -> Element {
32+
_read {
33+
yield buffer[index]
34+
}
35+
nonmutating _modify {
36+
yield &buffer[index]
37+
}
38+
}
39+
}
40+
2841
// CHECK: #if __cplusplus >= 202302L
2942
// CHECK-NEXT: SWIFT_INLINE_THUNK int operator [](int x, int _2) const SWIFT_SYMBOL("s:9Operators6IntBoxVys5Int32VAE_AEtcig");
3043
// CHECK-NEXT: #endif // #if __cplusplus >= 202302L

0 commit comments

Comments
 (0)