Possible g++ bug

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Wed Jun 30 23:07:00 GMT 1999


> When a temporary is returned by value, it gets destroyed before it
> is assigned, and then again before main exits.  Common sense tells
> me that this is an error, but I cannot afford a copy of the ANSI-C++
> standard, so I could be wrong.
[...]
> If a copy constructor is defined, the bug will disappear.

I could not reproduce that on i586-pc-linux-gnu with egcs 1.1.2, which
is strange because these kinds of problems should be platform
independent.

However, not defining a copy ctor is clearly an error in this case,
because the compiler can chose to create a copy when returning from
CreateTest. 

Since the default copy ctor would copy the id member, your destructors
can't tell whether the original or the copy has been destroyed, so I
would interpret the first destruction to destroy the original (after a
copy has been made), and the second destruction as destroying the
copy.

As I said, I can't reproduce it with either 1.1.2, nor gcc 2.95. egcs
1.1 definitely had problems with calling too many/too few destructors,
so the bug might as well be fixed (if there was one).

Regards,
Martin



More information about the Gcc-bugs mailing list