Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


946. Order of destruction of local static objects and calls tostd::atexit

Section:6.10.3.3  [basic.start.dynamic]    Status:CD2    Submitter:Fraser Ross    Date:28 July, 2009

[Voted into WP at March, 2010 meeting.]

17.5 [support.start.term] paragraph 7 says that the order ofdestruction of objects with static storage duration and calls tofunctions registered by callingstd::atexit is given in6.10.3.3 [basic.start.dynamic]. Paragraph 1 of 6.10.3.3 [basic.start.dynamic]says,

If the completion of the constructor or dynamic initialization of anobject with static storage duration is sequenced before that ofanother, the completion of the destructor of the second is sequencedbefore the initiation of the destructor of the first.

This wording covers both local and namespace-scope objects, so itfixes the relative ordering of local object destructors with respectto those of namespace scope. Paragraph 3 says,

If the completion of the initialization of a non-local object withstatic storage duration is sequenced before a call tostd::atexit (see<cstdlib>, 17.5 [support.start.term]), the call to the function passed tostd::atexit issequenced before the call to the destructor for the object. If a calltostd::atexit is sequenced before the completion of theinitialization of a non-local object with static storage duration, thecall to the destructor for the object is sequenced before the call tothe function passed tostd::atexit.

This fixes the relative ordering of destructors for namespacescope objects with respect to calls ofatexit functions.However, the relative ordering of local destructors andatexit functions is left unspecified.

In the 2003 Standard, this was clear: 18.3 paragraph 8 said,

A local static objectobj3 is destroyed at the same time itwould be if a function calling theobj3 destructor wereregistered withatexit at the completion of theobj3constructor.

Proposed resolution (October, 2009):

Change 6.10.3.3 [basic.start.dynamic] paragraph 3 as follows:

If the completion of the initialization ofa non-localan object with static storage duration is sequenced beforea call tostd::atexit (see<cstdlib>,17.5 [support.start.term]), the call to the function passed tostd::atexit is sequenced before the call to the destructorfor the object. If a call tostd::atexit is sequenced beforethe completion of the initialization ofa non-localan object with static storage duration, the call to thedestructor for the object is sequenced before the call to the functionpassed tostd::atexit...



[8]ページ先頭

©2009-2026 Movatter.jp