[Issue 5657] Temporary object destruction

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 1 04:47:47 PDT 2011


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



--- Comment #1 from SHOO <zan77137 at nifty.com> 2011-04-01 04:44:14 PDT ---
I tested following commit:
https://github.com/D-Programming-Language/dmd/commit/e764b3949ae0f95f8fc4d7d2e9114e29fee12493

with following code:
http://ideone.com/Yqomf

and result is here:
http://ideone.com/qfBnx


CONCLUTION:

Almost!
Its behavior is right except a case to ignore without storing away a temporary
object produced in a return value to a variable.

+--------------+--------------+----------+------------+-------------+
| source       | distination  | postblit | destructor | correctness |
+--------------+--------------+----------+------------+-------------+
| constructor  | parameter    |    x     |     o      |      OK     |
| constructor  | return value |    x     |     x      |      OK     |
| constructor  | variable     |    x     |     o      |      OK     |
| constructor  | no operate   |    x     |     o      |      OK     |
| return value | parameter    |    x     |     o      |      OK     |
| return value | return value |    x     |     x      |      OK     |
| return value | variable     |    x     |     o      |      OK     |
| return value | no operate   |    x     |    _x_     |     _NG_    |
| variable     | parameter    |    o     |     o      |      OK     |
| variable     | return value |    o     |     o      |      OK     |
| variable     | variable     |    o     |     o      |      OK     |
| variable     | no operate   | (error)  |  (error)   |      OK     |
+--------------+--------------+----------+------------+-------------+
                                 (*) x ... not called / o ... called

Minimized case is here:
-----
import std.stdio;

struct A{
    this(int x) {writeln("ctor");}
    ~this(){writeln("dtor");}
}

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

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