Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization of @mustuse member variable causes spurious error #20583

Open
pbackus opened this issue Dec 20, 2024 · 1 comment
Open

Initialization of @mustuse member variable causes spurious error #20583

pbackus opened this issue Dec 20, 2024 · 1 comment

Comments

@pbackus
Copy link
Contributor

pbackus commented Dec 20, 2024

As of DMD 2.109.1, the following program fails to compile:

import core.attribute;

@mustuse struct Inner
{
    this(int n) {}
}

struct Outer
{
    Inner inner;
    this(int n)
    {
        this.inner = n;
    }
}

The error message is:

bug.d(13): Error: ignored value of `@mustuse` type `bug.Inner`; prepend a `cast(void)` if intentional

That is, the initialization of this.inner is incorrectly flagged as a violation of @mustuse.

@pbackus
Copy link
Contributor Author

pbackus commented Dec 20, 2024

The error happens because this.inner = n; is lowered by the DMD frontend to (roughly) the following:

(this.inner = typeof(this.inner).init, this.inner.__ctor(n));

And the function that checks for @mustuse violations in DMD does not recognize the lowered code as an assignment expression.

thewilsonator added a commit to thewilsonator/dmd that referenced this issue Dec 21, 2024
thewilsonator added a commit to thewilsonator/dmd that referenced this issue Dec 21, 2024
thewilsonator added a commit to thewilsonator/dmd that referenced this issue Dec 21, 2024
thewilsonator added a commit to thewilsonator/dmd that referenced this issue Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant