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
[Voted into WP at April 2005 meeting.]
I have a couple of questions about 6.10.3.2 [basic.start.static],"Initialization ofnon-local objects." I believe I recall some discussion ofrelated topics, but I can't find anything relevant in the issueslist.
The first question arose when I discovered that differentimplementations treat reference initialization differently.Consider, for example, the following (namespace-scope) code:
int i; int& ir = i; int* ip = &i;Both initializers, "i" and "&i", are constant expressions, per7.7 [expr.const] paragraph 4-5 (a reference constant expression andan address constantexpression, respectively). Thus, both initializations arecategorized as static initialization, according to6.10.3.2 [basic.start.static] paragraph 1:
Zero-initialization and initialization with a constant expression are collectively called static initialization; all other initialization is dynamic initialization.
However, that does not mean that both ir and ip must beinitialized at the same time:
Objects of POD types (3.9) with static storage duration initialized with constant expressions (5.19) shall be initialized before any dynamic initialization takes place.
Because "int&" is not a POD type, there is no requirement that itbe initialized before dynamic initialization is performed, andimplementations differ in this regard. Using a function calledduring dynamic initialization to print the values of "ip" and"&ir", I found that g++, Sun, HP, and Intel compilers initializeir before dynamic initialization and the Microsoft compiler doesnot. All initialize ip before dynamic initialization. I believethis is conforming (albeit inconvenient :-) behavior.
So, my first question is whether it is intentional that areference of static duration, initialized with a referenceconstant expression, need not be initialized before dynamicinitialization takes place, and if so, why?
The second question is somewhat broader. As6.10.3.2 [basic.start.static] is currentlyworded, it appears that there areno requirements on when ir isinitialized. In fact, there is a whole category of objects --non-POD objects initialized with a constant expression -- forwhich no ordering is specified. Because they are categorized aspart of "static initialization," they are not subject to therequirement that they "shall be initialized in the order in whichtheir definition appears in the translation unit." Because theyare not POD types, they are not required to be initialized beforedynamic initialization occurs. Am I reading this right?
My preference would be to change6.10.3.2 [basic.start.static] paragraph 1 so that 1) referencesare treated like POD objects with respect to initialization, and2) "static initialization" applies only to POD objects andreferences. Here's some sample wording to illustrate:
Suggested resolution:
Objects with static storage duration (3.7.1) shall be zero-initialized (8.5) before any other initialization takes place. Initializing a reference, or an object of POD type, of static storage duration with a constant expression (5.19) is called constant initialization. Together, zero-initialization and constant initialization are called static initialization; all other initialization is dynamic initialization. Static initialization shall be performed before any dynamic initialization takes place. [Remainder unchanged.]
Proposed Resolution:
Change 6.10.3.2 [basic.start.static] paragraph 1 as follows:
Objects with static storage duration (3.7.1) shall bezero-initialized (8.5) before any other initialization takesplace.Initializing a reference, or an object of POD type, ofstatic storage duration with a constant expression (5.19) iscalledconstant initialization. Together,zero-initialization and constant initialization areZero-initialization and initialization with aconstant expression are collectivelycalledstaticinitialization; all other initialization isdynamicinitialization.Static initialization shall be performedObjects of POD types (3.9) with static storageduration initialized with constant expressions (5.19) shall beinitializedbefore any dynamic initialization takesplace.