www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4437] New: copy construction bug with "return this;"

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

           Summary: copy construction bug with "return this;"
           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-07-07
15:55:37 PDT ---
To reproduce, run this on Linux from the Phobos dir (after I'll check
std.container in):

make unittest BUILD=debug DMDEXTRAFLAGS="-debug=RefCounted -version=bugxxxx"

where xxxx is the number of this bug. Basically in a range containing a type
with an elaborate copy constructor, this works:

   Range save() { auto copy = this; return copy; }

but this doesn't:

   Range save() { return this; }

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


Shin Fujishiro <rsinfu gmail.com> changed:

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


--- Comment #1 from Shin Fujishiro <rsinfu gmail.com> 2010-09-18 14:32:47 PDT
---
Reduced test case:
-------------------- test.d
void main()
{
    S s;
    auto t = s.copy();
    assert(t.count == 1);   // (5)
}
struct S
{
    int count;
    this(this) { ++count; }
    S copy() { return this; }
}
--------------------
% dmd -run test.d
core.exception.AssertError test(5): Assertion failure
--------------------

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical


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


Brad Roberts <braddr puremagic.com> changed:

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


--- Comment #2 from Brad Roberts <braddr puremagic.com> 2010-12-10 00:32:40 PST
---
I'm 99% sure this is a dup of bug 3516 or together they form the basis of a
more general ticket: structs and their postblit and dtors are just mostly
unimplmented.

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg gmail.com


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-02-26 23:03:46 PST ---
Following patch fixes this bug.

 src/s2ir.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/s2ir.c b/src/s2ir.c
index 08d802b..982adfc 100644
--- a/src/s2ir.c
+++ b/src/s2ir.c
   -1247,7 +1247,7    void ReturnStatement::toIR(IRState *irs)
                  */
                 Type *tb = exp->type->toBasetype();
                 //if (tb->ty == Tstruct) exp->dump(0);
-                if ((exp->op == TOKvar || exp->op == TOKdotvar || exp->op ==
TOKstar) &&
+                if ((exp->op == TOKvar || exp->op == TOKdotvar || exp->op ==
TOKstar || exp->op == TOKthis) &&
                     tb->ty == Tstruct)
                 {   StructDeclaration *sd = ((TypeStruct *)tb)->sym;
                     if (sd->postblit)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4437



--- Comment #4 from Andrei Alexandrescu <andrei metalanguage.com> 2011-02-27
06:37:43 PST ---
Great fix! I changed my votes to vote this...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4437


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2011-03-31
15:48:21 PDT ---
https://github.com/D-Programming-Language/dmd/commit/52dd808de9d6ec904d3ca60a8bdbd4b276a5b15b

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 31 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4437


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cristi.cobzarenco gmail.com


--- Comment #6 from Kenji Hara <k.hara.pg gmail.com> 2012-04-24 18:19:32 PDT ---
*** Issue 6195 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: -------
Apr 24 2012