Files
swift-mirror/test/Interop/Cxx/class/Inputs/sendable.h
Egor Zhdan 6943986c71 [cxx-interop] Import private fields of C++ structs
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
2024-11-12 12:47:26 +00:00

40 lines
1.1 KiB
C++

struct HasPrivatePointerField {
private:
const int *ptr;
};
struct HasProtectedPointerField {
protected:
const int *ptr;
};
struct HasPublicPointerField {
const int *ptr;
};
struct HasPrivateNonSendableField {
private:
HasPrivatePointerField f;
};
struct HasProtectedNonSendableField {
protected:
HasProtectedPointerField f;
};
struct HasPublicNonSendableField {
HasPublicPointerField f;
};
struct DerivedFromHasPublicPointerField : HasPublicPointerField {};
struct DerivedFromHasPublicNonSendableField : HasPublicNonSendableField {};
struct DerivedFromHasPrivatePointerField : HasPrivatePointerField {};
struct DerivedPrivatelyFromHasPublicPointerField : private HasPublicPointerField {};
struct DerivedPrivatelyFromHasPublicNonSendableField : private HasPublicNonSendableField {};
struct DerivedPrivatelyFromHasPrivatePointerField : private HasPrivatePointerField {};
struct DerivedProtectedFromHasPublicPointerField : protected HasPublicPointerField {};
struct DerivedProtectedFromHasPublicNonSendableField : protected HasPublicNonSendableField {};
struct DerivedProtectedFromHasPrivatePointerField : protected HasPrivatePointerField {};