[Issue 17258] Pass by name doesn't work reliably and can sometimes lead to memory corruption

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Mar 15 12:40:27 PDT 2017


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

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g at gmail.com

--- Comment #1 from ag0aep6g at gmail.com ---
Looks like the compiler thinks `var` is a field. Writing to `v.var` then stomps
over anything that's actually there.

----
struct ByName3(alias Var)
{
    alias var = Var;
    ubyte value = 1;
}

void main()
{
    ushort x;
    ByName3!x v;
    ubyte w = 2;

    v.var = 0xAA_BB; /* stomps over v.value and w */

    import std.stdio;
    writefln("%X", v.value); /* prints "BB", should be 1 */
    writefln("%X", w); /* prints "AA", should be 2 */
}
----

--


More information about the Digitalmars-d-bugs mailing list