It appears to me int i = i;
has undefined behavior, is not caused by the indeterminate value. The term indeterminate value is designed for the objects that have automatic or dynamic storage duration.
[basic.indet#1]
When storage for an object with automatic or dynamic storage duration is obtained, the object has an indeterminate value, and if no initialization is performed for the object, that object retains an indeterminate value until that value is replaced ([expr.ass]).
[basic.indet#2]
If an indeterminate value is produced by an evaluation, the behavior is undefined except in the following cases...
In your example, the object named i
has a static storage duration, hence it is not within the extent of talking about indeterminate value. And, such an object has a zero-initialization that happens before any dynamic initialization as per [basic.start.static#2]
Together, zero-initialization and constant initialization are called static initialization; all other initialization is dynamic initialization. All static initialization strongly happens before ([intro.races]) any dynamic initialization.
Hence, its initial value is zero. when i
is used as an initializer to initialize itself. which is a dynamic initialization and it obeys [dcl.init].
Otherwise, the initial value of the object being initialized is the (possibly converted) value of the initializer expression.
It violates the rule in [basic.lifetime]
The program has undefined behavior if:
- the glvalue is used to access the object, or
struct circular_list x = { &x, &x }
. That's what it's for. – Erdda