mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Zero sized fields are messing up the offset calculations when we import C++ fields to Swift. We assume that the size of the field is determined by the type of the field. This is not true for fields marked with no_unique_address. Those fields can have 0 size while the sizeof(decltype(field)) is still 1. rdar://143907490
32 lines
597 B
C++
32 lines
597 B
C++
#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_MEMBER_VARIABLES_H
|
|
#define TEST_INTEROP_CXX_CLASS_INPUTS_MEMBER_VARIABLES_H
|
|
|
|
class MyClass {
|
|
public:
|
|
const int const_member = 23;
|
|
};
|
|
|
|
struct Empty {
|
|
using type = int;
|
|
int getNum() const { return 42; }
|
|
};
|
|
|
|
struct HasZeroSizedField {
|
|
int a;
|
|
[[no_unique_address]] Empty b;
|
|
short c;
|
|
[[no_unique_address]] Empty d;
|
|
int* e;
|
|
[[no_unique_address]] Empty f;
|
|
|
|
int get_a() const { return a; }
|
|
short get_c() const { return c; }
|
|
void set_c(short c) { this->c = c; }
|
|
};
|
|
|
|
inline int takesZeroSizedInCpp(HasZeroSizedField x) {
|
|
return x.a;
|
|
}
|
|
|
|
#endif
|