www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8269] New: The 'with' statement does not observe temporary object lifetime

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: acehreli yahoo.com


--- Comment #0 from Ali Cehreli <acehreli 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: -------
Jun 19 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8269


Ali Cehreli <acehreli yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8269


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maximzms gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-08
14:08:31 PST ---
*** Issue 9145 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8269


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com
            Summary|The 'with' statement does   |The 'with statement' does
                   |not observe temporary       |not observe temporary
                   |object lifetime             |object lifetime


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-08
14:08:58 PST ---
Slightly renamed title to make it more searchable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8269



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-23
05:18:18 PDT ---
(In reply to comment #0)
 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>

What it does end up doing is inject an initializer and a comma expression, and then takes the address of that. It's totally bizarre.. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 23 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8269


Martin Nowak <code dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow gmail.com


--- Comment #4 from Martin Nowak <code dawg.eu> 2013-10-25 09:57:03 PDT ---
*** Issue 11351 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 25 2013