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]
Other format: [Raw text]

c++/6527: g++ 3.1: class member dtor order wrong (regression in past week)



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


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