www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18556] New: alias this breaks emplace


          Issue ID: 18556
           Summary: alias this breaks emplace
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kytodragon e.mail.de

Given the following example:

module test.test;
import core.stdc.stdlib : malloc;
import std.conv : emplace;

class Bar {

class Foo {
    Bar bar;
    alias bar this;

void main() {
    Foo foo = NewC!Foo();

T NewC(T, A...)(A args) {
    size_t size = __traits(classInstanceSize, T);
    void* ptr = malloc(size);
    import core.memory : GC;
    GC.addRange(ptr, size);
    T res = emplace!(T, A)(ptr[0..size], args);
    return res;

Will result in the following stacktrace once started:

Tried to write to 0x0000000000000000
d_test.exe!memcpy()                                                     Line
165 (f:\dd\vctools\crt\vcruntime\src\string\amd64\memcpy.asm:165)
d_test.exe!std.conv.emplace!(test.test.Foo).emplace.__lambda3()         Line
4502 (c:\D\ldc2\import\std\conv.d:4502)
d_test.exe!std.conv.emplace!(test.test.Foo).emplace()                   Line
4529 (c:\D\ldc2\import\std\conv.d:4529)
d_test.exe!std.conv.emplace!(test.test.Foo).emplace()                   Line
4604 (c:\D\ldc2\import\std\conv.d:4604)
d_test.exe!test.test.NewC!(test.test.Foo).NewC()                        Line 22
d_test.exe!D main()                                                     Line 14
(Unknown Source:0)
d_test.exe!__entrypoint.main()                                          Line 8 
[Inline Frame] d_test.exe!invoke_main()                                 Line 64
d_test.exe!__scrt_common_main_seh()                                     Line
253 (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253)
(Unknown Source:0)
(Unknown Source:0)

Reproduced using LDC 1.7.0 on Windows 7 x64 and 10 x64, both x86 and x64
builds. Unable to reproduce using DMD v2.075.0. Issue 2605 for LDC2 says broken
since v2.077.0.
Removing the "alias bar this;" line fixes it.

Mar 04 2018