Comment #0 by dlang-bugzilla — 2015-08-30T02:05:10Z
////////////////////// test.d /////////////////////
enum testStr = "Hello, beautiful world!";
void funA(const char* node)
{
import core.stdc.string;
assert(strcmp(node, testStr)==0);
}
unittest
{
string node = testStr;
import std.internal.cstring;
funA(node is null ? null : node.tempCString());
}
///////////////////////////////////////////////////
Introduced in https://github.com/D-Programming-Language/phobos/pull/3415/files
Happens only on x64, perhaps this is a codegen bug?
Comment #1 by k.hara.pg — 2015-08-30T02:26:08Z
Perhaps the root is issue 14696.
Comment #2 by k.hara.pg — 2015-08-30T13:51:23Z
OK, I confirmed this is actually a dup of issue 14696.
To reproduce the issue, we need to specify -unittest. By that, tempCString will make the buffer size smaller and the used heap memory will be destructed at the wrong timing.
auto tempCString(To = char, From)(From str)
if (isSomeChar!To && (isInputRange!From || isSomeString!From) &&
isSomeChar!(ElementEncodingType!From))
{
...
static struct Res
{
...
private:
To* _ptr;
version (unittest)
{
enum buffLength = 16 / To.sizeof;
// smaller size to trigger reallocations
}
else
{
enum buffLength = 256 / To.sizeof;
// production size
}
To[256 / To.sizeof] _buff; // the 'small string optimization'