Issue 24624 - Struct with both bitfields and a slice or class instance ref doesn't compile.
Summary: Struct with both bitfields and a slice or class instance ref doesn't compile.
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-22 18:03 UTC by Jonas Meeuws
Modified: 2024-06-22 18:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonas Meeuws 2024-06-22 18:03:34 UTC
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;
}
---