[Issue 19479] Garbage .init in string mixins in static foreach in mixin templates

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 12 08:31:13 UTC 2018


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

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras at gmail.com
           Hardware|x86_64                      |All
            Summary|ints defined in template    |Garbage .init in string
                   |mixins have garbage values  |mixins in static foreach in
                   |                            |mixin templates
                 OS|Linux                       |All

--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
This issue is far stranger than one might expect. All of these simplifications
give correct results:

unittest {
    mixin("int i = 5;");
    assert(i == 5);
}

template genInts1() {
    int i = 5;
}

unittest {
    mixin genInts1!();
    assert(i == 5);
}

template genInts2() {
    mixin("int i = 5;");
}

unittest {
    mixin genInts2!();
    assert(i == 5);
}

unittest {
    static foreach (t; 0..1) {
        mixin("int i = 5;");
    }
    assert(i == 5);
}

While this one fails:

mixin template genInts3() {
    static foreach (t; 0..1) {
        mixin("int i = 5;");
    }
}

unittest{
    mixin genInts3!();
    assert(i == 5);
}

I also tested this by replacing int with string. Same issue.

So, a correct description is: initial values are not correctly set for
variables defined in string mixins inside static foreach inside mixin
templates.

run.dlang.io says that this has never worked (static foreach was introduced in
2.076, so it doesn't even compile before then).

--


More information about the Digitalmars-d-bugs mailing list