public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/3282: Problems with throw and destuctor callings
@ 2001-06-20  1:26 Bohdan Vlasyuk
  0 siblings, 0 replies; 3+ messages in thread
From: Bohdan Vlasyuk @ 2001-06-20  1:26 UTC (permalink / raw)
  To: gcc-gnats

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2078 bytes --]

>Number:         3282
>Category:       c++
>Synopsis:       Problems with throw and destuctor callings
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 20 01:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Bohdan Vlasyuk
>Release:        3.0
>Organization:
VSTU
>Environment:
System: Linux kivc.vstu.vinnica.ua 2.4.5 #12 ÷ÔÒ þÅÒ 19 10:01:01 EEST 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../srcdir/configure --enable-threads --enable-languages=c,c++ --disable-libgcj
>Description:

When I want to throw class, which has other class inside, and
constructor copies some properties of given class -- it look like
destructors are called wrond. I guess code will explain it better:

--------------------------------------

#include <iostream.h>
int global;

class One {
public:
        int num;
        One() { num=++global; cout << "One " <<num<<endl; };
        void Copy(One second_one) { cout << "Copy " <<num<<endl; };
        ~One() { cout << "~One "<<num<<endl; };
};

class Two {
public:
        One my_one;
        Two(One one) { my_one.Copy(one); };
};


int main() 
{
        One a;
        try {
                throw Two(a);
        } catch (Two two) {
                cout << "Ok"<<endl;
        }
        return 0;       
}


--------------------------------------

It produces following output:
( g++ _test.cpp -o test )


11:12:39 ~/src/eval/src # ./test 
One 1
One 2
Copy 2
~One 1
~One 1
~One 1
~One 1
~One 2
Ok
~One 2
~One 2
~One 1


You see, each destructor is called way more tnat once.


P.s.: It work in a same way with 2.95.3

As a side note: 3.0's g++ appears to be MUCH MUCH slower than 2.95.3

	
>How-To-Repeat:

Preprocessed file is ~600kb large.

Just take file from the above, and compile it with

g++ _test.cpp -o test


	
>Fix:

No ideas.
	
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c++/3282: Problems with throw and destuctor callings
@ 2001-08-11 14:32 gdr
  0 siblings, 0 replies; 3+ messages in thread
From: gdr @ 2001-08-11 14:32 UTC (permalink / raw)
  To: bohdan, gcc-bugs, gcc-prs, gdr, nobody

Synopsis: Problems with throw and destuctor callings

Responsible-Changed-From-To: unassigned->gdr
Responsible-Changed-By: gdr
Responsible-Changed-When: Sat Aug 11 14:32:43 2001
Responsible-Changed-Why:
    Analyzed.
State-Changed-From-To: open->closed
State-Changed-By: gdr
State-Changed-When: Sat Aug 11 14:32:43 2001
State-Changed-Why:
    Not a bug.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3282&database=gcc


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: c++/3282: Problems with throw and destuctor callings
@ 2001-06-21  2:16 Artem Khodush
  0 siblings, 0 replies; 3+ messages in thread
From: Artem Khodush @ 2001-06-21  2:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/3282; it has been noted by GNATS.

From: "Artem Khodush" <artem@duma.gov.ru>
To: "Bohdan Vlasyuk" <bohdan@kivc.vstu.vinnica.ua>
Cc: <gcc-gnats@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>
Subject: Re: c++/3282: Problems with throw and destuctor callings
Date: Thu, 21 Jun 2001 13:00:03 +0400

 > 
 > #include <iostream.h>
 > int global;
 > 
 > class One {
 > public:
 >         int num;
 >         One() { num=++global; cout << "One " <<num<<endl; };
 >         void Copy(One second_one) { cout << "Copy " <<num<<endl; };
 >         ~One() { cout << "~One "<<num<<endl; };
 > };
 > 
 
 This is not a bug. Define copy constructor for class One, like        
 
    One( const One& ) { num=++global; cout<<"One copy constructor"<<num<<endl; }
 
 and see if it helps.
 
 
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-08-11 14:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-20  1:26 c++/3282: Problems with throw and destuctor callings Bohdan Vlasyuk
2001-06-21  2:16 Artem Khodush
2001-08-11 14:32 gdr

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).