www.digitalmars.com         C & C++   DMDScript  

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

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

          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:

Segfault!
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
(c:\Users\XXXXXX\Entwicklung\D\D_Template\source\test\test.d:22)
d_test.exe!D main()                                                     Line 14
(c:\Users\XXXXXX\Entwicklung\D\D_Template\source\test\test.d:14)
d_test.exe!_d_run_main�()                                                    
 
(Unknown Source:0)
d_test.exe!__entrypoint.main()                                          Line 8 
(c:\Users\XXXXXX\Entwicklung\D\D_Template\__entrypoint.d:8)
[Inline Frame] d_test.exe!invoke_main()                                 Line 64
(f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:64)
d_test.exe!__scrt_common_main_seh()                                     Line
253 (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253)
kernel32.dll!00000000772e59cd()                                                
(Unknown Source:0)
ntdll.dll!000000007754383d()                                                   
(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