Lifetime of object which has vacuous initialization

后端 未结 3 781
夕颜
夕颜 2021-01-15 17:26

Current draft standard says (previous standards have similar wording) in [basic.life/1]:

The lifetime of an object or reference is a runtime property of

3条回答
  •  礼貌的吻别
    2021-01-15 17:44

    I interpret

    The lifetime of an object of type T begins when...

    to mean

    Given that a program creates an object of T, the following describes when that object's lifetime is said to begin...

    and not

    If the following conditions are satisfied, then an object of type T exists, and its lifetime begins when...

    That is, there's an implicit additional condition that the object is "created" in some way described in [intro.object]/1. But the paragraph [basic.life]1/ does not mean to by itself imply that any object exist, only one of the properties of objects that do exist.

    So for your declaration, the text describes the beginning of the lifetimes of one object of type char[sizeof(int)] and one or more objects of type char (even if the declaration is a statement in a block scope and there is no initialization), but since there is no object of type int implied to exist, we won't say anything about the lifetime of such an object.

提交回复
热议问题