digitalmars.D.bugs - [Issue 14402] New: std.conv.emplace for classes segfaults for nested
- via Digitalmars-d-bugs (55/55) Apr 03 2015 https://issues.dlang.org/show_bug.cgi?id=14402
https://issues.dlang.org/show_bug.cgi?id=14402 Issue ID: 14402 Summary: std.conv.emplace for classes segfaults for nested class Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: major Priority: P1 Component: Phobos Assignee: nobody puremagic.com Reporter: mkline.on.d gmail.com I came across this while doing work on std.typecons.Unique (see https://github.com/D-Programming-Language/phobos/pull/3139). Any class that accesses a local context seems to segfault when emplaced. A minimal test case follows: import core.stdc.stdlib : malloc, free; import std.conv : emplace; import std.traits : classInstanceAlignment; void main() { int created; int destroyed; class Foo { this() { ++created; } ~this() { ++destroyed; } } immutable size_t size = __traits(classInstanceSize, Foo); void* m = malloc(size); assert(m); Foo f = emplace!Foo(m[0 .. size]); assert(created == 1); f.destroy(); free(m); assert(destroyed == 1); } The problem doesn't seem to be the amount of memory I am allocating, given that it makes it past the testEmplaceChunk call in emplace. A stack trace from GDB is as follows: Program received signal SIGSEGV, Segmentation fault. 0x000000000042afd4 in wat.main().Foo.this() (this=0x66d450) at wat.d:10 10 this() { ++created; } (gdb) where (chunk=...) at /home/mrkline/src/dlang/phobos/std/conv.d:5005 where the relevant line in conv.d is result.__ctor(args); This was seen on 2.067 and the current master for dmd and phobos as of 2015-04-03 01:20 PST. --
Apr 03 2015