[Issue 5657] New: Temporary object destruction

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 26 23:50:12 PST 2011


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

           Summary: Temporary object destruction
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P5
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: zan77137 at nifty.com


--- Comment #0 from SHOO <zan77137 at nifty.com> 2011-02-26 23:47:22 PST ---
Following code doesn't call destructor:
--------------------------
import std.stdio;
struct A
{
    this(int a) {writeln("A.ctor");}
    ~this() {writeln("A.dtor");}
}

void main()
{
    A(1);
}
--------------------------
$ dmd -run main
A.ctor
--------------------------

I suppose that this bug is related to a series of problems about the temporary
object.

The outbreak of construction, destruction, postblit are as following table:
                                 postblit | destructor
constructor  -> parameter    ...    x     |    o
constructor  -> return value ...    x     |    x
constructor  -> variable     ...    x     |    o
constructor  -> no operate   ...    x     |    x
return value -> parameter    ...    x     |    o
return value -> return value ...    x     |    x
return value -> variable     ...    x     |    o
return value -> no operate   ...    x     |    x
variable     -> parameter    ...    o     |    o
variable     -> return value ...    o     |    o
variable     -> variable     ...    o     |    o
variable     -> no operate   ... (error)  | (error)

* When a variable leaves from the scope, destructor is called.
* When a variable returns from the function or a variable copies to other
variable, postblit is called.

Test code is here: http://ideone.com/7ujuN

Are these behaviors correct? I feel suspicious...
I think these behavior should be determined more strictly.

-- 
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