[Issue 8269] New: The 'with' statement does not observe temporary object lifetime
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jun 19 12:21:39 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8269
Summary: The 'with' statement does not observe temporary object
lifetime
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: acehreli at yahoo.com
--- Comment #0 from Ali Cehreli <acehreli at yahoo.com> 2012-06-19 12:23:56 PDT ---
The spec at
http://dlang.org/statement.html#WithStatement
says:
<quote>
The WithStatement
with (expression)
{
...
ident;
}
is semantically equivalent to:
{
Object tmp;
tmp = expression;
...
tmp.ident;
}
</quote>
Unfortunately, the anonymous object in the following code is destroyed even
before entering the 'with' scope:
import std.stdio;
struct S {
this(int i = 0)
{
writeln("constructed");
}
~this()
{
writeln("destructed");
}
}
void main() {
with(S(1)) {
writeln("inside 'with' statement");
}
}
Observed output:
constructed
destructed
inside 'with' statement
Expected output:
constructed
inside 'with' statement
destructed
Ali
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list