Compiling the following code with -preview=bitfields:
---
struct S
{
char[] slice;
bool flag:1;
}
---
Produces: "Error: cannot take address of bit-field `flag`".
After experimenting it seems that:
- A struct with bitfields cannot contain:
- Slices of any type.
- Class instance references.
- Structs, enums or references to classes containing any of the above.
- Bitfields in classes or named unions are not affected.
- When wrapping the bitfields in a named struct, the issue doesn't happen.
- With -betterC or ldcs --fno-rtti, the issue doesn't happen.
The issue might involve TypeInfo_Struct?
More failing examples:
---
struct S1
{
bool flag:1;
Object o;
}
struct Wrapper2
{
void[] wrapped;
}
struct S2
{
bool flag:1;
Wrapper2 wrapper;
}
struct Wrapper3
{
Object wrapped;
}
struct S3
{
bool flag:1;
Wrapper3 wrapper;
}
enum Wrapper4 : string
{
empty = ""
}
struct S4
{
bool flag:1;
Wrapper4 wrapper;
}
---
Comment #1 by robert.schadek — 2024-12-13T19:35:56Z