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

'goto' skips over declaration triggered for unused variable #19616

Open
dlangBugzillaToGithub opened this issue Aug 29, 2019 · 1 comment
Open
Labels

Comments

@dlangBugzillaToGithub
Copy link

Mathias LANG (@Geod24) reported this on 2019-08-29T03:11:02Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20179

CC List

  • RazvanN

Description

The following code:
```
string foo () { return null; }

void main ()
{
    if (auto str = foo())
    {
	assert(str.length);
    L1:
    }
    else
        goto L1;
}
```

Produces "oa.d(10): Error: goto skips declaration of variable oa.main.str at oa.d(5)"
But the variable is not used after L1.
@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2023-04-18T11:06:29Z

The compiler does not do any dataflow analysis so it cannot know whether `str` is used or not below L1. However, `str` could be used, therefore the compiler is conservative in this case and errors. In most cases, I think that the error could actually prevent wrong code.

Anyway, if last use analysis is implemented for move constructors/perfect fordwarding maybe this will have a chance of being fixed, however, chances are slim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant