--- Comment #5 from Jonathan Wakely <redi at gcc dot> ---
(In reply to Rajabharathi s from comment #3)
> But since m_a is member variable of other object FSPI, this memory exists in
> stack until its destruction.

The memory exists, but that is just some bytes of storage. After the first
destructor runs the object no longer exists.

Memory != object.

> m_g is set to NULL in destructor part when called for first time.
> So second time, this if condition should be false.

No. The m_g member is part of the object. After the object is destroyed, that
member no longer exists and it is undefined to access it again.

So the second time the destructor runs, it accesses an object which doesn't
exist. You cannot say "the member is NULL" because the member doesn't exist.

> If -fno-tree-dse option is used, then this if condition is false and works
> fine in 4.9.4.

So either fix your code to remove the undefined behaviour, or use that option
to prevent GCC from optimizing the code. But you still have a bug and the
program still has undefined behaviour.

If you want to use C++ then you need to follow the rules of the object model. 
If you want to work with raw bytes of memory, then you need to use a buffer of
raw memory (like an array of unsigned char), NOT just use an existing object as
raw storage for another object.

Reply via email to