atilaneves / dpp

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

Accessors for Bitfields: renaming for anonymous structs goes wrong #352

Open denizzzka opened 5 months ago

denizzzka commented 5 months ago

C header:

enum var { SOME1, SOME2 }; // payload with same as struct field name

union {
    struct {
        int var:1;
    };
} un;

Translation into D code - var renamed to var_ inside of accessors bodies:

[...]
extern(C)
{
    union _Anonymous_0
    {
        static struct _Anonymous_1
        {
            import std.bitmanip: bitfields;

            align(4):
            mixin(bitfields!(

                int, "var", 1,
                uint, "_padding_0", 7
            ));
        }
        _Anonymous_1 _anonymous_2;
        ref auto var_() @property @nogc pure nothrow { return _anonymous_2.var_; }
        void var_(_T_)(auto ref _T_ val) @property @nogc pure nothrow { _anonymous_2.var_ = val; }
    }
    extern export __gshared _Anonymous_0 un;

    enum var
    {
        SOME1 = 0,

        SOME2 = 1,
    }
    enum SOME1 = var.SOME1;
    enum SOME2 = var.SOME2;
}
[...]

D compiler complains:

test2.d(72): Error: no property var_ for type _Anonymous_1, did you mean test2._Anonymous_0._Anonymous_1.var?