public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/9075: Destructor is called more times than required..
@ 2002-12-27 20:26 Andrew Pinski
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2002-12-27 20:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/9075; it has been noted by GNATS.
From: Andrew Pinski <pinskia@physics.uc.edu>
To: sunil.k.davasam@intel.com
Cc: Andrew Pinski <pinskia@physics.uc.edu>, gcc-gnats@gcc.gnu.org
Subject: Re: c++/9075: Destructor is called more times than required..
Date: Fri, 27 Dec 2002 23:16:07 -0500
This is not a bug because func's c is not a reference to a variable but
a variable that is copied.
If you want a function that does not copy, then use a `&' and then the
destructor is not called twice, only once.
Read a C++ book for more information about pass by value, not reference.
Thanks,
Andrew Pinski
On Friday, Dec 27, 2002, at 22:46 US/Eastern, sunil.k.davasam@intel.com
wrote:
>
> void func(C c)
> {
> printf("func()\n");
> }
>
> int main(void)
> {
> C c;
>
> func(c);
> printf("main()\n");
> return 0;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c++/9075: Destructor is called more times than required..
@ 2002-12-29 10:16 lerdsuwa
0 siblings, 0 replies; 3+ messages in thread
From: lerdsuwa @ 2002-12-29 10:16 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, sunil.k.davasam
Synopsis: Destructor is called more times than required..
State-Changed-From-To: open->closed
State-Changed-By: lerdsuwa
State-Changed-When: Sun Dec 29 10:16:30 2002
State-Changed-Why:
Not a bug.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9075
^ permalink raw reply [flat|nested] 3+ messages in thread
* c++/9075: Destructor is called more times than required..
@ 2002-12-27 19:56 sunil.k.davasam
0 siblings, 0 replies; 3+ messages in thread
From: sunil.k.davasam @ 2002-12-27 19:56 UTC (permalink / raw)
To: gcc-gnats
>Number: 9075
>Category: c++
>Synopsis: Destructor is called more times than required..
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Dec 27 19:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: sunil.k.davasam@intel.com
>Release: g++3.2
>Organization:
>Environment:
$ g++ -v
Reading specs from /local/skdavasa/gcc321/lib/gcc-lib/i386-redhat-linux/3.2.1/specs
Configured with: gcc-3.2.1/configure --prefix=/local/skdavasa/gcc321 --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2.1
$ cat /etc/issue
Red Hat Linux release 8.0 (Psyche)
Kernel \r on an \m
>Description:
I have a small testcase.
[skdavasa@yeti testing]$ cat t1.cpp
#include <stdio.h>
class C {
public:
C() {
printf("C()\n");
}
~C() {
printf("~C()\n");
}
};
void func(C c)
{
printf("func()\n");
}
int main(void)
{
C c;
func(c);
printf("main()\n");
return 0;
}
When I compiled and ran the above the test case, I found that destructor is called twice, where as constructor is called only once. I think it is wrong.
>How-To-Repeat:
$ g++ t1.cpp
$ a.out
C()
func()
~C()
main()
~C()
---
Where as expected output:
------
C()
func()
main()
~C()
--------
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="t1.cpp"
Content-Disposition: inline; filename="t1.cpp"
#include <stdio.h>
class C {
public:
C() {
printf("C()\n");
}
~C() {
printf("~C()\n");
}
};
void func(C c)
{
printf("func()\n");
}
int main(void)
{
C c;
func(c);
printf("main()\n");
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-12-29 18:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-27 20:26 c++/9075: Destructor is called more times than required Andrew Pinski
-- strict thread matches above, loose matches on Subject: below --
2002-12-29 10:16 lerdsuwa
2002-12-27 19:56 sunil.k.davasam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).