public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Bohdan Vlasyuk <bohdan@kivc.vstu.vinnica.ua>
To: gcc-gnats@gcc.gnu.org
Subject: c++/3282: Problems with throw and destuctor callings
Date: Wed, 20 Jun 2001 01:26:00 -0000	[thread overview]
Message-ID: <200106200817.f5K8Hi205241@kivc.vstu.vinnica.ua> (raw)

[-- 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:


             reply	other threads:[~2001-06-20  1:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-20  1:26 Bohdan Vlasyuk [this message]
2001-06-21  2:16 Artem Khodush
2001-08-11 14:32 gdr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200106200817.f5K8Hi205241@kivc.vstu.vinnica.ua \
    --to=bohdan@kivc.vstu.vinnica.ua \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).