call of extra destructor
Dima Volodin
dvv@dvv.ru
Wed Mar 17 10:13:00 GMT 1999
On Wed, 17 Mar 1999 19:52:55 GMT+03:00, you wrote:
>Date: Wed, 17 Mar 1999 19:52:51 +0000
>From: ZVYAGIN <ZVYAGIN@mx.ihep.su>
>X-Sender: ZVYAGIN@polar.ihep.su
>To: egcs-bugs@egcs.cygnus.com
>Subject: call of extra destructor
>Message-ID: <Pine.VMS.3.91-b11-vms.990317193653.20312A-100000@polar.ihep.su>
>MIME-Version: 1.0
>Content-Type: TEXT/PLAIN; charset=US-ASCII
>
>// File
>#include <stream.h>
>class A
>{
> public:
> ~A (void) {cout << "D";}
> A (void) {cout << "C";}
>};
>
>void f(A a) {}
>
>int main(void)
>{
> { A a; f(a); }
> cout << endl;
> return 0;
>}
>// End of file
>
>$ g++ -v
>Reading specs from
>/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.66/specs
>gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
>
>$ uname -a
>Linux gams 2.0.32 #22 Mon Jan 5 22:42:45 MSK 1998 i686 unknown
>
>$ g++ bug.c
>$ a.out
>CDDD
>
>This is incorrect result.
This is a correct result. The compiler creates an extra temp A object
(which we all could easily live without), but it doesn't make its
behavior incorrect. If you throw in some members into A, this extra temp
object will disappear.
> There is extra call of the destructor. Other
>compilers produce correct output:
>CDD
This one is correct, too.
>Alexander.
Dima
More information about the Gcc-bugs
mailing list