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

fix Issue 6659 - Destructor in range foreach called after initialization #826

Merged
merged 1 commit into from
Mar 29, 2012

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Mar 23, 2012

http://d.puremagic.com/issues/show_bug.cgi?id=6659

If for statement has two or more declarations in its Intiliaze part, we should handle their destructors correctly.
This pull transform such for statement like follows.

for (auto x=X(a), y = Y(b); ...; ...) {}

to:

try {
  try {
    for (auto x=((x=X.init).this(a)), auto y=((y=Y.init)).this(b)); ...; ...) {}
  } finally {
    y.~this();
  }
} finally {
  x.~this();
}

The way is basically same as in CompoundStatement::semantic.

@Trass3r
Copy link
Contributor

Trass3r commented Mar 23, 2012

The old problem: this nice description isn't present as source code comments and will be lost in here.

@9rnsr
Copy link
Contributor Author

9rnsr commented Mar 23, 2012

Added comment. Thanks for you point out!

@Trass3r
Copy link
Contributor

Trass3r commented Mar 23, 2012

np :)

WalterBright added a commit that referenced this pull request Mar 29, 2012
fix Issue 6659 - Destructor in range foreach called after initialization
@WalterBright WalterBright merged commit b5aa4bc into dlang:master Mar 29, 2012
braddr pushed a commit to braddr/dmd that referenced this pull request Oct 22, 2012
Tweak to fullyQualifiedName allowing to check for parents of not-express...
auto value = 0;
try
{
for ({scope(success) { assert(value == 1); value = 2;} } true; )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this require a comma before the true in order for this to be properly valid? This currently triggers a parsing error in Mono-D and I'm trying to figure out if the error is in DMD or if Mono-D should be parsing this as valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. It would probably be better if we didn't accept this syntax, but it does appear to be valid in the grammar.

for ( Initialize Test(opt) ; Increment(opt) )

Where Initialize is {scope(success) { assert(value == 1); value = 2;} }.

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

Successfully merging this pull request may close these issues.

5 participants