Thread overview
[Issue 4356] New: Copy constructor not called under extremely mysterious circumstances
Jun 21, 2010
Walter Bright
Jun 22, 2010
Walter Bright
June 21, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4356

           Summary: Copy constructor not called under extremely mysterious
                    circumstances
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrei@metalanguage.com


--- Comment #0 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-06-20 20:40:18 PDT ---
I spent the better part of today trying to escape this elusive bug. It's extremely subtle because it depends on some unrelated code existing or not. Here it is:

import std.stdio;

struct X(T)
{
    this(this)
    {
        writeln("I was copied");
    }
}

void main()
{
    struct A
    {
        X!int x;
        this(int y)
        {
        }
        A copy()
        {
            auto another = this;
            return another;
        }
    }
    auto a = A(4);
    auto b = a.copy();
    writefln("a: %p, b: %p\n", &a, &b);
}

At the end of this program the writefln witnesses that we have two objects, but the stdout is mute so the subobject was not copied.

Changing some code in the example above makes the example work. For example,
replacing A(4) with A() produces a correct program.

Please give this priority (as all ctor/dtor bugs should have). Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 21, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4356


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2010-06-21 02:13:46 PDT ---
Simpler test case:

import std.c.stdio;

struct A
{
    int m;
    this(this)
    {
        printf("this(this) %p\n", &this);
    }
    ~this()
    {
        printf("~this() %p\n", &this);
    }
    A copy()
    {
        A another = this;
        return another;
    }
}

void main()
{
    A a;
    A b = a.copy();
    printf("a: %p, b: %p\n", &a, &b);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4356


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2010-06-21 22:15:06 PDT ---
http://www.dsource.org/projects/dmd/changeset/555

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4356



--- Comment #3 from github-bugzilla@puremagic.com 2012-05-23 11:16:51 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/ca86dad193372aee89de3712dfab0589502f3564 Bug 4356 is fixed, use ordinary assertion.

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