<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1284</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1284"></A><H4>1284.
  
Should the lifetime of an array be independent of that of its elements?
</H4>
<B>Section: </B>6.8.4&#160; [<A href="https://wg21.link/basic.life">basic.life</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD4
 &#160;&#160;&#160;

 <B>Submitter: </B>Gabriel Dos Reis
 &#160;&#160;&#160;

 <B>Date: </B>2011-04-02<BR>


<P>[Adopted at the February, 2016 meeting.]</P>



<P>The note in 6.8.4 [<A href="https://wg21.link/basic.life#2">basic.life</A>] paragraph 2 reads,</P>

<BLOCKQUOTE>

[<I>Note:</I> The lifetime of an array object starts as soon as
storage with proper size and alignment is obtained, and its lifetime
ends when the storage which the array occupies is reused or released.
11.9.3 [<A href="https://wg21.link/class.base.init">class.base.init</A>] describes the lifetime of base and member
subobjects.  &#8212;<I>end note</I>]

</BLOCKQUOTE>

<P>This wording reflects an earlier version of paragraph 1 that
deferred the start of an object's lifetime only for initialization of
objects of class type. The note simply emphasized the implication that
that the lifetime of a POD type or an array began immediately, even if
lifetime of an array's elements began later.</P>

<P>The decomposition of POD types removed the mention of PODs, leaving
only the array types, and when the normative text was changed to
include aggregates whose members have non-trivial initialization, the
note was overlooked.</P>

<P>It is not clear whether it would be better to update the note to
emphasize the distinction between aggregates with non-trivial
initialization and those without or to delete it entirely.</P>

<P>A possible related normative change to consider is whether the
specification of paragraph 1 is sufficiently clear with respect to
multidimensional arrays.  The current definition of &#8220;non-trivial
initialization&#8221; is:</P>

<BLOCKQUOTE>

An object is said to have non-trivial initialization if it is of a
class or aggregate type and it or one of its members is initialized by
a constructor other than a trivial default constructor.

</BLOCKQUOTE>

<P>Presumably the top-level array of an N-dimensional array whose
ultimate element type is a class type with non-trivial initialization
would also have non-trivial initialization, but it's not clear that
this wording says that.</P>

<P>A more radical change that came up in the discussion was whether the
undefined behavior resulting from an lvalue-to-rvalue conversion of an
uninitialized object in 7.3.2 [<A href="https://wg21.link/conv.lval#1">conv.lval</A>] paragraph 1 would be
better dealt with as a lifetime violation instead.</P>

<P><B>Proposed resolution (October, 2015):</B></P>

<P>Change 6.8.4 [<A href="https://wg21.link/basic.life">basic.life</A>] paragraphs 1 and 2 as follows:</P>

<BLOCKQUOTE>

<P>The <I>lifetime</I> of an object is a runtime property of
the object. An object is said to have <I>non-vacuous</I>
initialization if it is of a class or aggregate type and it
or one of its <DEL>members</DEL> <INS>subobjects</INS> is
initialized by a constructor other than a trivial default
constructor. [<I>Note:</I> initialization...</P>

<P>[<I>Note:</I> <DEL>The lifetime of an array object starts
as soon as storage with proper size and alignment is
obtained, and its lifetime ends when the storage which the
array occupies is reused or released.</DEL>
11.9.3 [<A href="https://wg21.link/class.base.init">class.base.init</A>] describes the lifetime of base
and member subobjects. &#8212;<I>end note</I>]</P>

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
