Why is the concept of vacuous initialization necessary?

  c++, initialization, language-lawyer, object-lifetime

The concept of vacuous initialization is introduced and used at [basic.life/1], and it does not seem to be used anywhere else in the C++ standard:

The lifetime of an object or reference is a runtime property of the object or reference. A variable is said to have vacuous initialization if it is default-initialized and, if it is of class type or a (possibly multi-dimensional) array thereof, that class type has a trivial default constructor. The lifetime of an object of type T begins when:

  • storage with the proper alignment and size for type T is obtained, and
  • its initialization (if any) is complete (including vacuous initialization) ([dcl.init]),

Since vacuous initialization is a subset of default initialization, it is initialization for class and array types, and no initialization for scalar types (cf. [dcl.init.general/7]), and therefore both cases are covered by the phrase ‘initialization (if any)’.

So why is the concept of vacuous initialization necessary?

The quote seems equivalent to this amended version:

The lifetime of an object or reference is a runtime property of the object or reference. The lifetime of an object of type T begins when:

  • storage with the proper alignment and size for type T is obtained, and
  • its initialization (if any) is complete ([dcl.init]),

Source: Windows Questions C++

LEAVE A COMMENT