[Issue 14024] New: unstable postblit/destructor call order on static array assignment
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jan 21 20:10:39 PST 2015
https://issues.dlang.org/show_bug.cgi?id=14024
Issue ID: 14024
Summary: unstable postblit/destructor call order on static
array assignment
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: k.hara.pg at gmail.com
I found this unstable runtime behavior while fixing other CTFE issues.
Test case:
import core.stdc.stdio;
int test14022()
{
string op;
struct S
{
char x = 'x';
this(this) { op ~= x - ('a'-'A'); } // upper case
~this() { op ~= x; } // lower case
}
struct T
{
S[2] member;
}
S[2] makeSA() { return typeof(return).init; }
version(A)
{
S[2] sa = [S('a'), S('b')];
S[2] sb = [S('x'), S('y')];
}
else
{
S[2] sb = [S('x'), S('y')];
S[2] sa = [S('a'), S('b')];
}
op = null;
sa = sb;
printf("op = %.*s\n", op.length, op.ptr);
return 1;
}
void main() { test14022(); }
The program output will be switched:
op = XaYb
and:
op = YbXa
Depending on the compiler switch -version=A.
(To be precise, it depends on the stack address of sa and sb.)
On static array assignment `sa = sb;`, the order of postblit/destructor calls
should be normal if lhs and rhs have distinct memories.
--
More information about the Digitalmars-d-bugs
mailing list