Thread overview
[Issue 19598] CTFE fails to assign struct
Jan 21, 2019
Manu
Jan 21, 2019
Nicholas Wilson
Jan 21, 2019
Simen Kjaeraas
Jan 21, 2019
Manu
Jan 21, 2019
Simen Kjaeraas
Jan 21, 2019
Manu
Jan 21, 2019
Simen Kjaeraas
Dec 17, 2022
Iain Buclaw
January 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19598

--- Comment #1 from Manu <turkeyman@gmail.com> ---
Error: `*n1 = t1` cannot be evaluated at compile time

--
January 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19598

Nicholas Wilson <iamthewilsonator@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |iamthewilsonator@hotmail.co
                   |                            |m

--- Comment #2 from Nicholas Wilson <iamthewilsonator@hotmail.com> ---
*** Issue 19600 has been marked as a duplicate of this issue. ***

--
January 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19598

Simen Kjaeraas <simen.kjaras@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras@gmail.com

--- Comment #3 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
Defining an opAssign for S seems to do the trick:

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());

--
January 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19598

--- Comment #4 from Manu <turkeyman@gmail.com> ---
This also works:

(*n1).tupleof = t1.tupleof

The compiler can do it... it's just that this expression doesn't work.

--
January 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19598

--- Comment #5 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
Workaround #2:
int test2()
{
    struct S { int x;  }
    S t1;
    S* n1 = &(new S[1])[0];
    *n1 = t1;

    return 10;
}
pragma(msg, test2());

Something gets weird when using `new S` - it seems the allocated block is marked in some way that prevents *m1 = t1 from working.

--
January 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19598

--- Comment #6 from Manu <turkeyman@gmail.com> ---
I also thought of and found that workaround... it's fine for arrays. It's very strange that because it's just one, this doesn't work.

--
January 21, 2019
https://issues.dlang.org/show_bug.cgi?id=19598

--- Comment #7 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
It seems this can be fixed by teaching assignToLvalue about StructLiteralExps:


        else if (auto sle = e1.isStructLiteralExp())
        {
            oldval = sle;
        }

There may be issues with this fix though.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=19598

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=19598

--- Comment #8 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17894

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--