Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
denizzzka opened this issue Jun 28, 2024 · 0 comments
Open

Comments

@denizzzka
Copy link

denizzzka commented Jun 28, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant