public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: snyder@fnal.gov
To: gcc-gnats@gcc.gnu.org
Subject: c++/6527: g++ 3.1: class member dtor order wrong (regression in past week)
Date: Tue, 30 Apr 2002 20:56:00 -0000	[thread overview]
Message-ID: <200205010349.g413nYJ18179@karma.fnal.gov> (raw)


>Number:         6527
>Category:       c++
>Synopsis:       g++ 3.1: class member dtor order wrong (regression in past week)
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 30 20:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     scott snyder
>Release:        3.1 20020429 (prerelease)
>Organization:
>Environment:
System: Linux karma 2.4.9-13 #1 Tue Oct 30 20:11:04 EST 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../egcs/configure --prefix=/usr/local/egcs --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77
>Description:


The C++ standard specifies that for class members and bases, destructors
are to be called in the reverse of the order in which the constructors
were called.  gcc used to do this, but the present cvs version of 3.1
calls the destructors in the _same_ order as the constructors.
This is demonstrated by the example below:

$ g++ -o x x.cc
$ ./x
ctor 3
ctor 1
ctor 2
dtor 3
dtor 1


If i compile this with gcc 2.95 instead, i get this output instead:
ctor 3
ctor 1
ctor 2
dtor 2
dtor 1
dtor 3


>How-To-Repeat:

-- x.cc ---------------------------------------------------------------
extern "C" int printf(...);

struct B
{
  int x;
  B (int i) : x (i) { printf ("ctor %d\n", x); }
  ~B () { printf ("dtor %d\n", x); }
};

struct A
  : public B
{
  A () : B (3), x1(1), x2(2) {}
  B x1;
  B x2;
};


int main ()
{
  A a;
  return 0;
}
-----------------------------------------------------------------------

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-05-01  3:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-30 20:56 snyder [this message]
2002-05-01 13:09 paolo
2002-05-01 14:54 mmitchel
2002-05-01 22:17 mmitchel

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=200205010349.g413nYJ18179@karma.fnal.gov \
    --to=snyder@fnal.gov \
    --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).