mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
While private and protected fields coming from C++ cannot be accessed from Swift, they can affect Swift typechecking. For instance, the Swift typechecker mechanism that adds implicit `Sendable` conformances works by iterating over all of the struct's fields and checking whether all of them are `Sendable`. This logic was broken for C++ types with private fields, since they were never accounted for. This resulted in erroneous implicit `Sendable` confromances being added. Same applies for `BitwiseCopyable`. In addition to this, ClangImporter used to mistakenly mark all C++ structs that have private fields as types with unreferenceable storage, which hampered optimizations. As a side effect of this change, we now also provide a better diagnostic when someone tries to access a private C++ field from Swift. rdar://134430857
35 lines
1.3 KiB
Swift
35 lines
1.3 KiB
Swift
// RUN: %target-swift-ide-test -print-module -module-to-print=UsingBaseMembers -access-filter-public -I %S/Inputs -source-filename=x -cxx-interoperability-mode=swift-6 | %FileCheck %s
|
|
// RUN: %target-swift-ide-test -print-module -module-to-print=UsingBaseMembers -access-filter-public -I %S/Inputs -source-filename=x -cxx-interoperability-mode=upcoming-swift | %FileCheck %s
|
|
|
|
// CHECK: struct PublicBase {
|
|
// CHECK-NEXT: init()
|
|
// CHECK-NEXT: func publicGetter() -> Int32
|
|
// CHECK-NEXT: mutating func publicSetter(_ v: Int32)
|
|
// CHECK-NEXT: func notExposed()
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK: struct PublicBasePrivateInheritance {
|
|
// CHECK-NEXT: init()
|
|
// CHECK-NEXT: func publicGetter() -> Int32
|
|
// CHECK-NEXT: mutating func publicSetter(_ v: Int32)
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK: struct PublicBaseProtectedInheritance {
|
|
// CHECK-NEXT: init()
|
|
// CHECK-NEXT: func publicGetter() -> Int32
|
|
// CHECK-NEXT: mutating func publicSetter(_ v: Int32)
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK: struct UsingBaseConstructorWithParam {
|
|
// CHECK-NEXT: init(_: IntBox)
|
|
// CHECK-NEXT: init(_: UInt32)
|
|
// CHECK-NEXT: init(_: Int32)
|
|
// CHECK-NEXT: var value: Int32
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK: struct UsingBaseConstructorEmpty {
|
|
// CHECK-NEXT: init()
|
|
// CHECK-NEXT: init(_: Empty)
|
|
// CHECK-NEXT: var value: Int32
|
|
// CHECK-NEXT: }
|