www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3516] New: Destructor not called on temporaries

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516

           Summary: Destructor not called on temporaries
           Product: D
           Version: 2.032
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bartosz relisoft.com


--- Comment #0 from Bartosz Milewski <bartosz relisoft.com> 2009-11-16 14:32:39
PST ---
Created an attachment (id=497)
Reference counting doesn't work when temporaries created

Function f returns (by value) a struct that has a destructor. If I explicitly
assign the result of f to a temporary, that temporary is destroyed at the end
of scope. If I don't assign it, the hidden temporary is not destroyed. In the
attached example this screws up reference counting.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516



--- Comment #1 from Bartosz Milewski <bartosz relisoft.com> 2009-11-16 16:31:43
PST ---
*** Issue 3518 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: -------
Nov 16 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Leandro Motta Barros <lmb stackedboxes.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lmb stackedboxes.org


--- Comment #2 from Leandro Motta Barros <lmb stackedboxes.org> 2009-11-29
03:21:36 PST ---
I don't know if this is useful information, but I've been bitten by this same
bug under Linux with DMD 2.036.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 29 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |critical


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 18 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr puremagic.com


--- Comment #3 from Brad Roberts <braddr puremagic.com> 2010-05-30 15:59:09 PDT
---
Reduced test case:
extern(C) int printf(const char*, ...);

int numctor, numdtor;

struct Tid
{
    this(int i) { ++numctor; }
    ~this() { ++numdtor; }
}

Tid f() { return Tid(1); }

// This temporary is destroyed
void test1() { Tid tid = f(); }

// This (invisible) temporary is never destroyed
void test2() { f(); }

void main()
{
    numctor = numdtor = 0;
    test1();
    printf("numctor = %d, numdtor = %d\n", numctor, numdtor);
    assert(numctor == 1);
    assert(numdtor == 1);

    numctor = numdtor = 0;
    test2();
    printf("numctor = %d, numdtor = %d\n", numctor, numdtor);
    assert(numctor == 1);
    assert(numdtor == 1);
}

Current results:
numctor = 1, numdtor = 1
numctor = 1, numdtor = 0
core.exception.AssertError bug3516(31): Assertion failure

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Lionello Lunesu <lio+bugzilla lunesu.com> changed:

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


--- Comment #4 from Lionello Lunesu <lio+bugzilla lunesu.com> 2010-07-06
01:34:59 PDT ---
*** Issue 3285 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: -------
Jul 06 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Adrian Matoga <epi atari8.info> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |epi atari8.info


--- Comment #5 from Adrian Matoga <epi atari8.info> 2010-07-10 06:11:10 PDT ---
Still active in 2.047,

testcase:

import std.stdio;
struct A
{
    int a;
    this(int a) { this.a = a; writeln("hello, ", a); }
    ~this() { writeln("bye, ", a); }
    void doSth() { writeln("something"); }
}
void main()
{
    auto a1 = A(1);
    a1.doSth();
    A(2).doSth();
}

produces:

hello, 1
something
hello, 2
something
bye, 1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 10 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com


--- Comment #6 from Andrei Alexandrescu <andrei metalanguage.com> 2010-07-10
06:25:14 PDT ---
Upvoted.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 10 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


SHOO <zan77137 nifty.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3
                 CC|                            |zan77137 nifty.com


--- Comment #7 from SHOO <zan77137 nifty.com> 2010-08-23 09:52:25 PDT ---
Upvoted.
By recent usage of struct, this bug is serious. This should be supported
quickly.

I suspect that these may be connected with each other:
    http://d.puremagic.com/issues/show_bug.cgi?id=4712

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 23 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


andy aligature.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andy aligature.com


--- Comment #8 from andy aligature.com 2010-09-20 08:51:34 PDT ---
This bug also seems like it could be the cause of

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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 20 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516



--- Comment #9 from Don <clugdbug yahoo.com.au> 2010-09-22 04:05:41 PDT ---
*** Issue 4613 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: -------
Sep 22 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Max Samukha <samukha voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samukha voliacable.com


--- Comment #10 from Max Samukha <samukha voliacable.com> 2010-11-14 03:09:58
PST ---
This one is critical for QtD. Can it be fixed soon?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 14 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3516


Vladimir <thecybershadow gmail.com> changed:

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


--- Comment #11 from Vladimir <thecybershadow gmail.com> 2011-04-26 05:19:34
PDT ---
The test case in comment #3 now passes with DMD git HEAD, and this bug is now
listed as fixed in the DMD changelog.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 26 2011