atilaneves / dpp

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

Handle nested C11 anonymous structs/unions #204

Closed cbecerescu closed 4 years ago

cbecerescu commented 4 years ago

An example of this bug is shown here. (the issue being the last two accessors in the translated D code).

My understanding is that, previously, we would only go to the sub-sub members of a given anonymous struct or union. But if the nesting level is deeper than that, then we no longer generate the accessors correctly for the deeper levels.

jacob-carlborg commented 4 years ago

D supports nested anonymous unions and structs, the correct fix is to use that instead of accessors. Or have I missed something why this wouldn’t work?

atilaneves commented 4 years ago

I don't remember why things are the way they are anymore. However, it's true that this compiles fine in D right now:

struct Struct {
    union {
        int a;
        struct {
            int b;
            union {
                int c;
                char d;
            };
        };
    };
}

void main() {

    Struct s;
    s.a = 42;
    s.b = 1337;
    s.c = 7;
    s.d = 'D';
}