Question Details

No question body available.

Tags

c++ arrays nested language-lawyer implicit-lifetime

Answers (1)

Accepted Answer Available
Accepted Answer
March 25, 2026 Score: 5 Rep: 44,859 Quality: Expert Completeness: 80%

Yes, all objects that need to be created are created, including subobjects of arrays or subobjects of implicit-lifetime aggregates where the subobject has an implicit-lifetime type.

[intro.object]p12:

Some operations are described as implicitly creating objects within a specified region of storage. For each operation that is specified as implicitly creating objects, that operation implicitly creates and starts the lifetime of zero or more objects of implicit-lifetime types ([basic.types.general]) in its specified region of storage if doing so would result in the program having defined behavior. If no such set of objects would give the program defined behavior, the behavior of the program is undefined. If multiple such sets of objects would give the program defined behavior, it is unspecified which such set of objects is created.
[Note 4: Such operations do not start the lifetimes of subobjects of such objects that are not themselves of implicit-lifetime types. — end note]

With emphaisis on 'implicitly creates and starts the lifetime of zero or more objects', not just one object is created.

And the later example 3 shows:

[Example 3:

#include 
struct X { int a, b; };
X make_x() {
  // The call to std​::​malloc implicitly creates an object of type X
  // and its subobjects a and b, and returns a pointer to that X object
  // (or an object that is pointer-interconvertible ([basic.compound]) with it),
  // in order to give the subsequent class member access operations
  // defined behavior.
  X p = (X*)std::malloc(sizeof(struct X));
  p->a = 1;
  p->b = 2;
  return p;
}

end example]

An object of type X being implicity created as well as two objects of type int being created as subobjects of that X object. The exact same thing happens with subobjects of arrays.