Skip to content

Commit d395c5d

Browse files
authored
Merge pull request #76212 from swiftlang/gaborh/read-accessor-6.0
🍒[6.0][cxx-interop] Do not attempt to export read accessors to C++
2 parents d966414 + 3bf02d1 commit d395c5d

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
@@ -2072,9 +2072,10 @@ class DeclAndTypePrinter::Implementation
20722072
if (outputLang == OutputLanguageMode::Cxx) {
20732073
if (!SD->isInstanceMember())
20742074
return;
2075-
auto *getter = SD->getOpaqueAccessor(AccessorKind::Get);
2076-
printAbstractFunctionAsMethod(getter, false,
2077-
/*isNSUIntegerSubscript=*/false, SD);
2075+
// TODO: support read accessors.
2076+
if (auto *getter = SD->getOpaqueAccessor(AccessorKind::Get))
2077+
printAbstractFunctionAsMethod(getter, false,
2078+
/*isNSUIntegerSubscript=*/false, SD);
20782079
return;
20792080
}
20802081
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
@@ -16,6 +16,19 @@
1616

1717
public struct IntBox { var x: CInt }
1818

19+
public struct CustomArray<Element> where Element : ~Copyable {
20+
private var buffer: UnsafeMutableBufferPointer<Element>
21+
22+
public subscript(index: Int) -> Element {
23+
_read {
24+
yield buffer[index]
25+
}
26+
nonmutating _modify {
27+
yield &buffer[index]
28+
}
29+
}
30+
}
31+
1932
public func -(lhs: IntBox, rhs: IntBox) -> CInt {
2033
return lhs.x - rhs.x
2134
}

0 commit comments

Comments
 (0)