atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
230 stars 31 forks source link

Wrong bitfields paddings are no longer generated if the current member should be skipped #219

Closed cbecerescu closed 4 years ago

cbecerescu commented 4 years ago

The following C struct declaration

struct Bad {
    int a : 1;
    int b : 1;
    struct C *ptr; // C is undeclared
}

would be translated in D to

struct Bad
{
    import std.bitmanip: bitfields;

    align(4);
    mixin(bitfields!(
        int, "a", 1,
        int, "b", 1,
        uint, "_padding_0", 6
    ));
        uint, "_padding_1", 8
    ));
    C* ptr;
}

The issue is that the bitfields final padding would be added twice:

This issue doesn't occur when C is a pre-declared struct, as we will only have a FieldDecl for that line.