~= call copy ctor?
Ali Çehreli
acehreli at yahoo.com
Sat Jul 21 14:59:11 PDT 2012
On 07/21/2012 01:41 PM, Namespace wrote:
> Ok. I hope it will not take months. :/
>
> BTW:
> I have a new strange behaviour by experiementing with structs.
>
> This code http://dpaste.dzfl.pl/new#top
> works fine, as long as i don't do _any_ operation after line 91.
> If i activate one of the out comment operations or something else, the
> program works still fine but crashes after termination.
>
> I use Windows 7, dmd 2.059 and compile with
> -w -O -property -unittest -debug
>
> I have no explanation.
I was able to reproduce the segmentation fault when I compiled with -m32
under a 64 bit Linux environment. And this much is sufficient to
reproduce the problem:
void main() {
Foo f3 = new Foo();
Test t = new Test(f3);
writeln("exit main"); // <-- note the added line
}
One thing that I've noticed is that opAssign() is probably buggy because
it overwrites this._ptr without taking care of it first (i.e. it is not
doing '*_ptr = null'). But I don't think it is related to the main issue.
'Test' is a class having a struct member. The destructor of that member
is accessing memory that is already gone. The last line in main makes it
more clear how that destructor is accessing an already destroyed pointer:
this
this
exit main <--
DTOR TEST
DESTROY SCOPED
make: *** [deneme] Segmentation fault
_sc_f._ptr points to f3, which is a local object in main.
Ali
More information about the Digitalmars-d-learn
mailing list