Bug 14024 – [CTFE] unstable postblit/destructor call order on static array assignment
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-22T04:10:00Z
Last change time
2015-02-18T03:38:52Z
Keywords
CTFE, pull
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2015-01-22T04:10:39Z
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.