Bug 23236 – can't initialize a @mustuse member in constructor

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-07-10T14:30:17Z
Last change time
2022-07-14T15:32:51Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2022-07-10T14:30:17Z
This should compile: ``` import core.attribute; @mustuse struct MyError { } struct S { MyError lastError; this(int x) { this.lastError = MyError(); // Error: ignored value of `@mustuse` type `onlineapp.MyError`; prepend a `cast(void)` if intentional } } ``` Assignment seems to work, but initialization is not considered ignoring the value.
Comment #1 by dlang-bot — 2022-07-14T12:40:14Z
@dkorpel created dlang/dmd pull request #14303 "Fix 23236 - can't initialize a @mustuse member in constructor" fixing this issue: - Fix 23236 - can't initialize a @mustuse member in constructor https://github.com/dlang/dmd/pull/14303
Comment #2 by dlang-bot — 2022-07-14T15:32:51Z
dlang/dmd pull request #14303 "Fix 23236 - can't initialize a @mustuse member in constructor" was merged into master: - 76a82b95a7fcfa4c381056a6040ea0d0bb0dcfab by Dennis Korpel: Fix 23236 - can't initialize a @mustuse member in constructor https://github.com/dlang/dmd/pull/14303