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
[basic.life] Does zero-initialization as a static initialization begin the lifetime of an object? CWG2821 #4802
Comments
We can't access out-of-lifetime variables. However, the example at the bottom of [basic.start.static] p3 makes it clear that the intermediate state of "zero-initialized, but not yet dynamic-initialized" is a perfectly fine state. In any case, this is not an editorial issue; maybe CWG wishes to somehow remove the double-initialization to make this clear, instead of saying something like "its first initialization" in [basic.life]. |
@xmh0511 Excellent question.
@jensmaurer Interesting. |
[basic.life] p1 says
The declaration at
#1
will undergo initialization twice. One happens in static initialization(zero-initialization), the other happens in dynamic initialization(whose initializer is itself).However, the second bullet only requires that its initialization is complete, which initialization does it refer to in the intent here? Before the dynamic initialization occurs,
i
has been statically initialized to be0
, which can still say its initialization is complete. Does it mean the lifetime ofi
at this point has begun?I don't know why do we change the original second bullet of the c++17 version to the current wording.
I think the older version's intent is clearer to me, which means if the initialization for the object is not non-vacuous, only the specified initialization is complete will the lifetime of the object begin. Except that the possible defect that it didn't say whether the vacuous initialization contributes to this rule.
Could we just say
The text was updated successfully, but these errors were encountered: