[Issue 13119] `struct` constructor attributes inferred like field destructor is called on initialization
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 8 16:02:36 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=13119
Stanislav Blinov <stanislav.blinov at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |stanislav.blinov at gmail.com
--- Comment #1 from Stanislav Blinov <stanislav.blinov at gmail.com> ---
Error in the original report is trivially worked around by replacing `s = S(0)`
with `s = 0` as that is supported by S's constructor.
However, the error comes back as soon as more than one argument gets involved:
struct S
{
this(int, int) @safe pure nothrow @nogc { }
~this() { }
}
struct T
{
S s;
this(int) @safe pure nothrow @nogc
{
s = S(0, 1); // attribute errors here as this is introducing a dtor
call
}
}
Two workarounds:
alias AliasSeq(T...) = T;
s = AliasSeq!(0, 1); // works for literals, not for moving stuff
import core.lifetime : forward;
s = forward!args; // works for moving and copying, but not for literals
Observation about `nothrow` not being looked at is still valid.
Initialization shouldn't require a destructor call, as right hand side should
ostensibly be constructed at &s, should it not?
--
More information about the Digitalmars-d-bugs
mailing list