[interfacekit] Re: oddish?
- From: "Andrew Bachmann" <shatty@xxxxxxxxxxxxx>
- To: interfacekit@xxxxxxxxxxxxx
- Date: Wed, 25 Feb 2004 02:04:10 -0800 PST
Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx> wrote:
>
> On 2004-02-16 at 17:28:58 [+0100], Marcus Overhagen wrote:
> > A temporary BString object is created, initalized with "test".
> > Then a pointer to the (copy) of the string inside the BString
> > object is returned by the String() function, and pushed on the
> > stack. Now the expression is evaluated, and the temporary
> > BString object is destroyed. Now the function bar() is executed,
> > using the pointer that is on the stack, but no longer valid since
> > the temporary object was already destroyed.
>
> I don't believe this is true. AFAIK temporary objects are not destroyed at
> the end of an expression, but at the end of a statement; that is in your
> example after bar() returned. Attached is a little program that executes two
> tests, which demonstrate that behavior. The second test is of particular
> interest, since it also shows how buggy our gcc is -- the B destructor is
> invoked twice on the same object. mwcc does it correctly though, destroying
> B after A.
>
> CU, Ingo
Marcus is right in the spec sense, Ingo is right in the realized sense of
our gcc. Ingo's observation is the basis of my warning. I understand that
Marcus is right, but our gcc is (at least sometimes) wrong. :-P Ours seems to
be not the only gcc with this problem, however I don't have a full
characterization of which gcc do exhibit it. Hence, my encouragement to
rewrite these type of expressions to not exercise that part of the spec.
Andrew
- Follow-Ups:
- [interfacekit] Re: oddish?
- From: Ingo Weinhold
- References:
- [interfacekit] Re: oddish?
- From: Ingo Weinhold
Other related posts:
- » [interfacekit] oddish?
- » [interfacekit] Re: oddish?
- » [interfacekit] Re: oddish?
- » [interfacekit] Re: oddish?
- » [interfacekit] Re: oddish?
- » [interfacekit] Re: oddish?
- » [interfacekit] Re: oddish?
- [interfacekit] Re: oddish?
- From: Ingo Weinhold
- [interfacekit] Re: oddish?
- From: Ingo Weinhold