Skip to content

CWG2914 [basic.start.static] Unclear order of initialization of static and thread local variables #559

@t3nsor

Description

@t3nsor

Full name of submitter: Brian Bi

Issue description: It is heavily implied, but not stated outright, that initialization of all non-local static variables happens before initialization of all non-local thread-local variables. For example, [basic.start.static] seems to refer to initializing variables with static storage duration and thread storage duration as "phases", which may imply that one phase completes before the other starts. [basic.start.term]/2 appears to guarantee that returning from main destroys all thread-local variables of the main thread before destroying any static variables, which would be peculiar if the static variables were not initialized first.

Suggested resolution: Edit [basic.start.static]/1 as shown:

Variables with static storage duration are initialized as a consequence of program initiation. Variables with thread storage duration are initialized as a consequence of thread execution. The initialization of all non-block variables with static storage duration (if any) strongly happens before the initialization of any non-block variable with thread storage duration. Within each of these phases of initiation, initialization occurs as follows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions