Bug 13119 – `struct` constructor attributes inferred like field destructor is called on initialization

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-13T08:27:40Z
Last change time
2024-12-13T18:22:05Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Denis Shelomovskii
Moved to GitHub: dmd#18849 →

Comments

Comment #0 by verylonglogin.reg — 2014-07-13T08:27:40Z
This code should compile: --- struct S { this(int) @safe pure nothrow @nogc { } ~this() { } } struct T { S s; this(int) @safe pure nothrow @nogc { s = S(0); // line 13 } } --- main.d(13): Error: pure function 'main.T.this' cannot call impure function 'main.S.~this' main.d(13): Error: safe function 'main.T.this' cannot call system function 'main.S.~this' main.d(13): Error: @nogc function 'main.T.this' cannot call non-@nogc function 'main.S.~this' --- Note there is no errors for `nothrow` attribute.
Comment #1 by stanislav.blinov — 2021-12-08T16:02:36Z
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?
Comment #2 by robert.schadek — 2024-12-13T18:22:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18849 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB