[Issue 13848] overlapping initialization for r

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Dec 10 13:48:50 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13848

deadalnix <deadalnix at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #2 from deadalnix <deadalnix at gmail.com> ---
(In reply to Kenji Hara from comment #1)
> (In reply to deadalnix from comment #0)
> > 	auto fun() {
> > 		return SS(a, p);
> > 	}
> 
> Your're trying to initialize SS.a by the value a. and SS.r by using p.

What ? That do not make any sense. Also, I was able to trigger that error with
an explicit constructor in a much more convoluted sample code. Basically as
follow:

module a;

import b;
struct S {
    mixin MixinTpl!P;
    this(...) { ... }
}

module b;

template MixinTpl(P) {

    union {
        A a;
    }

    P p;

    auto fun() {
        return SS(a, p);
    }

    struct SS {

        union {
            A a;
            ulong r;
        }

        P p;
    }
}

struct A {}

union P {}

> Of course SS.a and SS.r are overlapped each other, so initializing the two
> fields at the same time is invalid.
> 
> In this case, you cannot use literal style syntax to construct SS. An
> alternative way is:
> 
> auto fun() {
>     SS ss = {a:a, p:p};  // use StructInitializer syntax
>     return ss;
> }

Ok at least I have a workaround, thank. There is still an issue in there, so
I'm reopening.

--


More information about the Digitalmars-d-bugs mailing list