<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 119</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="119"></A><H4>119.
  
Object lifetime and aggregate initialization
</H4>
<B>Section: </B>6.8.4&#160; [<A href="https://wg21.link/basic.life">basic.life</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Jack Rouse
 &#160;&#160;&#160;

 <B>Date: </B>20 May 1999<BR>



<P>[Moved to DR at 4/02 meeting.]</P>



<P>
<B>Jack Rouse:</B>
6.8.4 [<A href="https://wg21.link/basic.life#1">basic.life</A>] paragraph 1

includes:</P>
<BLOCKQUOTE>
The lifetime of an object is a runtime property of the object. The
lifetime of an object of type <TT>T</TT> begins when:
<UL>
<LI>storage with the proper alignment and size for type <TT>T</TT>
is obtained, and</LI>

<LI>if <TT>T</TT> is a class type with a non-trivial constructor
(11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>]
), the
constructor call has completed.</LI>
</UL>
</BLOCKQUOTE>

Consider the code:
<PRE>
    struct B {
        B( int = 0 );
        ~B();
    };

    struct S {
        B b1;
    };

    int main()
    {
        S s = { 1 };
        return 0;
    }
</PRE>

In the code above, class <TT>S</TT> does have a non-trivial constructor, the
default constructor generated by the compiler.  According the text
above, the lifetime of the auto <TT>s</TT> would never begin because a
constructor for <TT>S</TT> is never called.  I think the second case in the
text needs to include aggregate initialization.

<P>
<B>Mike Miller:</B>
I see a couple of ways of fixing the problem.  One way would be
to change "the constructor call has completed" to "the object's
initialization is complete."</P>

<P>Another would be to add following "a class type with a non-trivial
constructor" the phrase "that is not initialized with the brace
notation (9.5.2 [<A href="https://wg21.link/dcl.init.aggr">dcl.init.aggr</A>]
)."</P>

<P>The first formulation treats aggregate initialization like a
constructor call; even POD-type members of an aggregate could
not be accessed before the aggregate initialization completed.
The second is less restrictive; the POD-type members of the
aggregate would be usable before the initialization, and the
members with non-trivial constructors (the only way an
aggregate can acquire a non-trivial constructor) would be
protected by recursive application of the lifetime rule.</P>

<P>
<B>Proposed resolution (04/01):</B> </P>

<P>In 6.8.4 [<A href="https://wg21.link/basic.life#1">basic.life</A>] paragraph 1, change</P>

<BLOCKQUOTE>

If <TT>T</TT> is a class type with a non-trivial constructor
(11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>]), the constructor call has
completed.

</BLOCKQUOTE>

<P>to</P>

<BLOCKQUOTE>

If <TT>T</TT> is a class type with a non-trivial constructor
(11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>]), the initialization is complete.
[<I>Note:</I> the initialization can be performed by a
constructor call or, in the case of an aggregate with an
implicitly-declared non-trivial default constructor, an
aggregate initialization (9.5.2 [<A href="https://wg21.link/dcl.init.aggr">dcl.init.aggr</A>]).]

</BLOCKQUOTE>

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