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: nob...@puremagic.com ReportedBy: acehr...@yahoo.com --- Comment #0 from Ali Cehreli <acehr...@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: -------