Bug 4437 – copy construction bug with "return this;"

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-07-07T15:55:00Z
Last change time
2012-04-24T18:19:32Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2010-07-07T15:55:37Z
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; }
Comment #1 by rsinfu — 2010-09-18T14:32:47Z
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 --------------------
Comment #2 by braddr — 2010-12-10T00:32:40Z
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.
Comment #3 by k.hara.pg — 2011-02-26T23:03:46Z
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)
Comment #4 by andrei — 2011-02-27T06:37:43Z
Great fix! I changed my votes to vote this...
Comment #5 by bugzilla — 2011-03-31T15:48:21Z
Comment #6 by k.hara.pg — 2012-04-24T18:19:32Z
*** Issue 6195 has been marked as a duplicate of this issue. ***