Inspired by this question.
We know that global variables with non-constexpr
initializers undergo two different "initializations":
Which of those initializations starts the variable lifetime? [basic.life]
is being surprisingly unhelpful:
The lifetime of an object ... begins when: ... its initialization (if any) is complete
I see several options:
(1) Would make the most sense, but it would make the static initialization of an object that will later be dynamically initialized mostly useless.
(2) Would have interesting effects. E.g. the static init order fiasco is suddenly not UB (by itself) anymore.
(3) Would be very weird.
This is CWG issue 2821.
This isn't resolved yet, but CWG has said that the intended resolution is "first initialization begins lifetime, subsequent initialization just modifies the value".