[Issue 4356] New: Copy constructor not called under extremely mysterious circumstances

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 20 20:40:20 PDT 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 at puremagic.com
        ReportedBy: andrei at metalanguage.com


--- Comment #0 from Andrei Alexandrescu <andrei at 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: -------


More information about the Digitalmars-d-bugs mailing list