D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23236 - can't initialize a @mustuse member in constructor
Summary: can't initialize a @mustuse member in constructor
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2022-07-10 14:30 UTC by Dennis
Modified: 2022-07-14 15:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dennis 2022-07-10 14:30:17 UTC
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 Dlang Bot 2022-07-14 12:40:14 UTC
@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 Dlang Bot 2022-07-14 15:32:51 UTC
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