Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/ClangImporter/SwiftDeclSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1899,10 +1899,19 @@ SubscriptDecl *SwiftDeclSynthesizer::makeSubscript(FuncDecl *getter,
DeclName name(ctx, DeclBaseName::createSubscript(), bodyParams);
auto dc = getterImpl->getDeclContext();

SubscriptDecl *subscript = SubscriptDecl::createImported(
ctx, name, getterImpl->getLoc(), bodyParams, getterImpl->getLoc(),
elementTy, dc, getterImpl->getGenericParams(),
getterImpl->getClangNode());
SubscriptDecl *subscript;
if (auto ClangN = getterImpl->getClangNode()) {
subscript = SubscriptDecl::createImported(
ctx, name, getterImpl->getLoc(), bodyParams, getterImpl->getLoc(),
elementTy, dc, getterImpl->getGenericParams(), ClangN);
} else {
// getterImpl may lack an associated ClangNode if it is synthesized,
// e.g., if it is a cloned from a base class member due to inheritance.
subscript = SubscriptDecl::create(
ctx, name, SourceLoc(), StaticSpellingKind::None, getterImpl->getLoc(),
bodyParams, getterImpl->getLoc(), elementTy, dc,
getterImpl->getGenericParams());
}
subscript->copyFormalAccessFrom(getterImpl);

bool useAddress = rawElementTy->getAnyPointerElementType() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ struct OperatorBase {
operator bool() const { return true; }
int operator*() const { return 456; }
OperatorBase operator!() const { return *this; }
// int operator[](const int x) const { return x; } // FIXME: see below
int operator[](const int x) const { return x; }
};

struct OperatorBasePrivateInheritance : private OperatorBase {
public:
using OperatorBase::operator bool;
using OperatorBase::operator*;
using OperatorBase::operator!;
// using OperatorBase::operator[]; // FIXME: using operator[] is broken
using OperatorBase::operator[];
};

#endif // !_USING_BASE_MEMBERS_H
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ UsingBaseTestSuite.test("OperatorBasePrivateInheritance") {
// expectTrue(Bool(fromCxx: p))
// expectTrue(Bool(fromCxx: !p))
expectEqual(456, p.pointee)
// expectEqual(789, p[789]) // FIXME: operator[] is currently broken
expectEqual(789, p[789])
}

runAllTests()
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@

// CHECK: public struct OperatorBasePrivateInheritance : CxxConvertibleToBool {
// CHECK-NEXT: public init()
// CHECK-NEXT: public subscript(x: Int32) -> Int32 { get }
// CHECK-NEXT: public var pointee: Int32 { get }
// CHECK-NEXT: public func __convertToBool() -> Bool
// CHECK-NEXT: @available(*, unavailable, message: "use .pointee property")
// CHECK-NEXT: public func __operatorStar() -> Int32
// CHECK-NEXT: prefix public static func ! (lhs: OperatorBasePrivateInheritance) -> OperatorBase
// CHECK-NEXT: @available(*, unavailable, message: "use ! instead")
// CHECK-NEXT: public func __operatorExclaim() -> OperatorBase
// CHECK-NEXT: @available(*, unavailable, message: "use subscript")
// CHECK-NEXT: public func __operatorSubscriptConst(_ x: Int32) -> Int32
// CHECK-NEXT: }