This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Possible g++ bug
- To: hookflash at hotmail dot com
- Subject: Re: Possible g++ bug
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Tue, 8 Jun 1999 08:46:08 +0200
- CC: egcs-bugs at egcs dot cygnus dot com
- References: <19990607211900.22417.qmail@hotmail.com>
> 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