-
Notifications
You must be signed in to change notification settings - Fork 772
[basic.start.static] p3 is a bit vague #4800
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
Comments
"static initialization" is defined as zero-initialization or constant-initialization. Which means we have to check whether |
I think "the static version of the initialization" is saying that double d1 = fd(); // either initialized statically or dynamically to 1.0 Regardless of static or dynamic initialization of |
There is no separate concept "statically initialized"; it just means "static initialization". And "static initialization" can't read other data, but just deal in (compile-time) constants, so an ordering problem does not arise (which is the primary motivation for static initialization). It's a valid initialization order "d1 zero-init, then d2 dynamically initialized from d1, then d1 dynamically initialized from |
It's a valid initialization order "d1 zero-init, then d2 dynamically initialized from d1, then d1 dynamically initialized from fd()" d1 is zero-initialization // this happens before the transformed static initialization of d2
double d2 = d1; // original dynamic initialization, turned to static initialization,
// which means the value of `d1` at this point is 0 It seems the initialization must perform in this order, then the conditions will be satisfied. I think the transformation does not mean transform the original dynamic initialization to be merely a zero-initialization, Instead, I think the intent is saying transform the dynamic initialization to be a constant initialization if these conditions would be true. |
Again, static initialization (which includes constant initialization) does not read the value of d1, so there is no ordering concern here. Any argument that talks about static initialization somehow reading d1 is incorrect. The idea is: If there is a valid combination of static and dynamic initialization for all variables in view resulting in some initial values for the variables and the conditions are satisfied, then a particular dynamic initialization may instead be performed as static initialization if the resulting initial values are the same as for that particular combination. |
According to your clarification, I think if add an additional wording would make the meaning clearer.
The concern is basic on what is the static version of the initialization. Does it mean the dynamic initialization would be viewed as a static initialization(which requires reading the value of the initializer) to be performed or mean a complete new static initialization generated by the implementation if conditions are satisfied(as if the initializer were replaced to a constant value)? IIUC, You clarify it to be the latter. Since if the initializer is a glvalue, lvalue-to-rvalue conversion(read value) shall be applied to it in order to perform initialization as per [dcl.init#general-15.9] and [basic.lval#1.2], hence what would the initializer be is significant when we talk about that initialization. |
An lvalue-to-rvalue conversion on a global non-const variable would violate [expr.const] and thus not be static initialization. Thus, that can't possibly be meant. |
So, I think we should clarify what is the initializer expression in the transformed static version initialization. Since we always have a prvalue to perform the initialization. Maybe, the value consisted with the dynamic initialization could be interpreted as a constant-expression to perform that static initialization. |
This might be addressed by CWG2821. |
The dynamic initialization of d2 can be finely interpreted. However, consider the case, static initialization of d2, when [basic.start.static] p3 applies.
The dynamic initialization of
d2
would be0
ifd2
andd1
are all dynamically initialized(since the zero-initialization occurs prior to any dynamic initialization). However, why could we guarantee that the value ofd2
statically initialized fromd1
is definitely 0? In other words, why is the value of the initializerd1
zero when it participates in the static initialization at that point? This implies the static initialization(zero-initialization) ofd1
must happen before the static initialization ofd2
(d2 is statically initialized fromd1
).The text was updated successfully, but these errors were encountered: