This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: call of extra destructor


On Mar 17, 1999, dvv@dvv.ru (Dima Volodin) wrote:

> On Wed, 17 Mar 1999 19:52:55 GMT+03:00, you wrote:

>> #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; }

>> gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
>> $ g++ bug.c
>> $ a.out
>> CDDD

> The compiler creates an extra temp A object (which we all could
> easily live without), but it doesn't make its behavior incorrect.

But *why* is it creating such an extra temp A object?  It can
certainly hurt performance, since it must be destructed, and I can't
see why it is being created in the first place.  Calling f(A) needs a
single temporary, and the implicit copy constructor can't require an
additional temporary anyway...

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva aoliva@{acm.org,computer.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Instituto de Computação, Universidade Estadual de Campinas, SP, Brasil
*** E-mail about software projects will be forwarded to mailing lists



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]