CTFE bug?
Simen Kjærås
simen.kjaras at gmail.com
Mon Jan 21 07:31:39 UTC 2019
On Monday, 21 January 2019 at 00:44:02 UTC, Manu wrote:
> Does anyone understand:
> https://issues.dlang.org/show_bug.cgi?id=19598 And are there
> any known workarounds?
Defining an opAssign for S seems to work:
int test()
{
struct S { int x; void opAssign(S s) { x = s.x; } }
S t1;
S* n1 = new S;
*n1 = t1;
return 10;
}
pragma(msg, test());
Fascinatingly, it seems 'new' is doing something special in this
code - replacing 'new S' with '&t1', things compile.
Second workaround: create an array of S, then take the address of
the first one:
int test2()
{
struct S { int x; }
S t1;
S* n1 = &(new S[1])[0];
*n1 = t1;
return 10;
}
pragma(msg, test2());
Now, as for why the simple, sensible code in the bug report
doesn't work, I have no idea. It seems `new S` marks the block in
some way that prevents regular assignment from working.
--
Simen
More information about the Digitalmars-d
mailing list