🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #767

Re: Order of destructor calls for auto objects

#767
From: Bjarne Stroustrup
Date: Fri, 21 Dec 1990 14:21
44 lines
2038 bytes

About order of destructor calls.

A quick glance in the index of the ARM tells me:

	Destructors for global objects within the same compilation unit
	are destroyed in reverse order of their construction.

	Destructors for class members are exceuted in reverse order of
	their construction.

	Destructors for base classes are exceuted in reverse order of
	their construction.

	Destructors for array elements are executed in reverse order
	of their construction.

The guarantee that I had expected to find but didn't:

	Destructors for named auto variables are executed in reverse
	order of their construction.

If it is not there it is an oversight that ought to be remedied.
I believe this to be non-controversial and that all compilers in
fact guarantees this.

I believe that this guarantee could also be given
	
	Destructors for local static variables are executed in reverse
	order of their construction.

but that this might be less obvious and therefore possibly controversial.
I'm sure X3J16 will consider this issue.

Note that complete determinism is probably not possible since the order
of evaluation or sub-expressions is not guaranteed by C or C++. This implies
that guarantees about the order of destruction of temporaries are hard
to make.

Also, the order of construction and destruction of global variables in
different compilation units are hard to guarantee. Given the diversity
of linkers and in particular the possibility of dynamic linking this
problem is fundamentally hard.
Technical Details
Message-ID: <11730@alice.att.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!bu.edu!att!att!dptg!ulysses!andante!alice!bs
References: <1990Dec14.221247.9487@lia> <martino.661601979@krypton> <1990Dec20.074232.9416@lth.se>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!bu.edu!att!att!dptg!ulysses!andante!alice!bs
From: bs@alice.att.com (Bjarne Stroustrup)
Newsgroups: comp.std.c++
Subject: Re: Order of destructor calls for auto objects
Message-ID: <11730@alice.att.com>
Date: 21 Dec 90 14:21:45 GMT
References: <1990Dec14.221247.9487@lia> <martino.661601979@krypton> <1990Dec20.074232.9416@lth.se>
Organization: AT&T Bell Laboratories, Murray Hill NJ
Lines: 44