D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6257 - Struct postblit not called in one case
Summary: Struct postblit not called in one case
Status: RESOLVED DUPLICATE of issue 6199
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-07-06 03:27 UTC by bearophile_hugs
Modified: 2012-05-10 19:53 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-07-06 03:27:03 UTC
With DMD 2.053 the second assert of this program fires, is this a DMD bug?


struct Foo {
   int[] data;

   this(int n) {
       data.length = n;
   }

   this(this) {
       data = data.dup;
   }
}
void main() {
   Foo f1, f2;
   f1 = Foo(1);
   f2 = f1;
   assert(f1.data.ptr != f2.data.ptr); // OK
   f1 = f2 = Foo(1);
   assert(f1.data.ptr != f2.data.ptr); // asserts
}
Comment 1 Kenji Hara 2012-05-10 19:52:21 UTC
The bug mechanism is:

struct Foo {
   int[] data;
   this(int n) {
       data.length = n;
   }
   this(this) {
       data = data.dup;
   }

   // Implicitly generated by compiler
   ref Foo opAssign(Foo rhs) { ... }
}

void main() {
   ...
   f1 = f2 = Foo(1);
   // is translated to:
   f1.opAssign(f2.opAssign(Foo(1)));  // f2.opAssign returns ref Foo
}

"Postblit not called on ref returned object" is same as bug 6119.
Then, this was a dup of it.

*** This issue has been marked as a duplicate of issue 6119 ***
Comment 2 Kenji Hara 2012-05-10 19:53:28 UTC
Sorry, I missed. This is a dup of bug 6199.

*** This issue has been marked as a duplicate of issue 6199 ***