[Issue 15965] [REG 2.070] Reference to other CT-known field on struct instantiation now yields "circular reference"

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri May 6 07:09:42 PDT 2016


--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
First, is the summary "[REG 2.070] ..." a mistake of REG-master (or REG-devel,

You've said:

> This used to compile up until 2.071.0, where it broke.

So the *issue* exists only in current master branch that not yet released as


The displayed error with git-head dmd is:

test.d(4): Error: struct test.Element no size because of forward reference

And yes it is an intentional change. Until 2.071, an use of 'offsetof' property
during declarations of instance fields has returned 0 always. Next is an
example of the bug:

struct Element
    ubyte x;    // add a field before Element.val

    public ubyte[256] val;

    // printed 0 until 2.071, it was incorrect
    pragma(msg, "1: ", val.offsetof);

    private ubyte[(val.offsetof + 256) % size_t.sizeof] _padding;

// After Element struct fields are determined, offsetof can return correct
pragma(msg, "2: ", Element.val.offsetof);

// If val.offsetof correctly returned 1 during declaration of _padding,
// this pragma(msg) would have printed 1, but actually it printed 0...
pragma(msg, Element._padding.sizeof);

To disallow use of incorrect offsetof value, the "no size bevause of ..." error
was introduced.


Although the master change is intentional, I still think compiler would be able
to supply correct offset value in the OP case. In other words, I think we can
change this issue to an enhancement request.


More information about the Digitalmars-d-bugs mailing list