Skip to content

P1874R1 Dynamic Initialization Order of Non-Local Variables in Modules #3438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6343,31 +6343,42 @@
variable template specialization has ordered initialization.
\end{note}

\pnum
A declaration \tcode{D} is
\defn{appearance-ordered} before a declaration \tcode{E} if
\begin{itemize}
\item \tcode{D} appears in the same translation unit as \tcode{E}, or
\item the translation unit containing \tcode{E}
has an interface dependency on the translation unit containing \tcode{D},
\end{itemize}
in either case prior to \tcode{E}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what we're talking about in this last phrase, especially when applied to the 2nd bullet. Can this be clarified?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally handwaving around our not having precise wording for this constraint; the same handwaving occurs in [module.reach]p1. Filed #3502 to track this.


\pnum
Dynamic initialization of non-local variables \tcode{V} and \tcode{W}
with static storage duration are ordered as follows:
\begin{itemize}
\item
If \tcode{V} and \tcode{W} have
ordered initialization and \tcode{V} is defined before \tcode{W} within
a single translation unit, the initialization of \tcode{V} is sequenced
before the initialization of \tcode{W}.

\item
If \tcode{V} has partially-ordered initialization, \tcode{W} does not have
unordered initialization, and \tcode{V} is defined before \tcode{W} in
every translation unit in which \tcode{W} is defined, then
If \tcode{V} and \tcode{W} have ordered initialization and
the definition of \tcode{V}
is appearance-ordered before the definition of \tcode{W}, or
if \tcode{V} has partially-ordered initialization,
\tcode{W} does not have unordered initialization, and
for every definition \tcode{E} of \tcode{W}
there exists a definition \tcode{D} of \tcode{V}
such that \tcode{D} is appearance-ordered before \tcode{E}, then
\begin{itemize}
\item
if the program starts a thread\iref{intro.multithread}
other than the main thread\iref{basic.start.main},
if the program does not start a thread\iref{intro.multithread}
other than the main thread\iref{basic.start.main}
or \tcode{V} and \tcode{W} have ordered initialization and
they are defined in the same translation unit,
the initialization of \tcode{V}
strongly happens before
is sequenced before
the initialization of \tcode{W};
\item
otherwise,
the initialization of \tcode{V}
is sequenced before
strongly happens before
the initialization of \tcode{W}.
\end{itemize}

Expand Down