<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<style type="text/css">

body { color: #000000; background-color: #FFFFFF; }
del { text-decoration: line-through; color: #8B0040; }
ins { text-decoration: underline; color: #005100; }

p.example { margin-left: 2em; }
pre.example { margin-left: 2em; }
div.example { margin-left: 2em; }

code.extract { background-color: #F5F6A2; }
pre.extract { margin-left: 2em; background-color: #F5F6A2;
  border: 1px solid #E1E28E; }

p.function { }
.attribute { margin-left: 2em; }
.attribute dt { float: left; font-style: italic;
  padding-right: 1ex; }
.attribute dd { margin-left: 0em; }

blockquote.std { color: #000000; background-color: #F1F1F1;
  border: 1px solid #D1D1D1;
  padding-left: 0.5em; padding-right: 0.5em; }
blockquote.stddel { text-decoration: line-through;
  color: #000000; background-color: #FFEBFF;
  border: 1px solid #ECD7EC;
  padding-left: 0.5empadding-right: 0.5em; ; }

blockquote.stdins { text-decoration: underline;
  color: #000000; background-color: #C8FFC8;
  border: 1px solid #B3EBB3; padding: 0.5em; }

table { border: 1px solid black; border-spacing: 0px;
  margin-left: auto; margin-right: auto; }
th { text-align: left; vertical-align: top;
  padding-left: 0.8em; border: none; }
td { text-align: left; vertical-align: top;
  padding-left: 0.8em; border: none; }

</style>

<title>Dynarray Allocation Context</title>
</head>

<body>
<h1>Dynarray Allocation Context</h1>

<p>
ISO/IEC JTC1 SC22 WG21 N4043 - 2014-05-22
</p>

<p>
Lawrence Crowl, Lawrence@Crowl.org
</p>


<h2>Contents</h2>

<p>
<a href="#Introduction">Introduction</a><br>
<a href="#Solution">Solution</a><br>
<a href="#Wording">Wording changes</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#dynarray.cons">23.3.4.2 <code>dynarray</code> constructor and destructor [dynarray.cons]</a><br>
</p>


<h2><a name="Introduction">Introduction</a></h2>

<p>
The <code>dynarray</code> class
(<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3662.html">
N3662 C++ Dynamic Arrays</a>
and 
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3820.html">
N3820 Working Draft, Technical Specification &mdash; Array Extensions</a>)
and any other named class attempting to use the execution stack for allocation
may suffer failure if the class is reallocated
with in-place destruction and a placement new.
This problem is described in
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3899.html">
N3899 Nested Allocation</a>
section
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3899.html#Lifetime">
Nested Lifetime</a>.
We need specific wording to address this case.
</p>


<h2><a name="Solution">Solution</a></h2>

<p>
We choose to permit the stack optimization for constructors called an automatic variables
and then only if not called with the placement new operator.
This change effectively requires the compiler
to recognize the context of a constructor call
and, when appropriate, change the implementation to an alternate implementation.
</p>


<h2><a name="Wording">Wording changes</a></h2>

<p>
The proposed wording changes are relative to
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3820.html">
N3820 Working Draft, Technical Specification &mdash; Array Extensions</a>).
</p>


<h3><a name="dynarray.cons">23.3.4.2 <code>dynarray</code> constructor and destructor [dynarray.cons]</a></h3>

<p>
Edit the effects paragraph for the explicit single-argument constructor as follows.
</p>

<blockquote class="std">

<blockquote>
<p>
<i>Effects:</i>
Allocates storage for <var>c</var> elements.
<del>May or may not invoke the global <code>operator new</code>.</del>
The <tt>c</tt> elements of the <code>dynarray</code>
are default-initialized (8.5).
<ins>When invoked for an object with other than automatic storage duration,
or when invoked via a placement new,
allocates elements with the global <code>operator new</code>.
Otherwise may allocate elements with the global <code>operator new</code>
or may use another mechanism.</ins>
</p>
</blockquote>

</blockquote>

<p>
Edit the effects paragraph for the two-argument constructor as follows.
</p>


<blockquote class="std">

<blockquote>
<p>
<i>Effects:</i>
Allocates storage for <code>c</code> elements.
<del>May or may not invoke the global <code>operator new</code>.</del>
The <code>c</code> elements of the <code>dynarray</code>
are direct-initialized ([decl.init]) with argument <code>v</code>.
<ins>When invoked for an object with other than automatic storage duration,
or when invoked via a placement new,
allocates elements with the global <code>operator new</code>.
Otherwise may allocate elements with the global <code>operator new</code>
or may use another mechanism.</ins>
</p>
</blockquote>

</blockquote>

<p>
Edit the effects paragraph for the copy constructor as follows.
</p>

<blockquote class="std">

<blockquote>
<p>
<i>Effects:</i>
Allocates storage for <code>d.size()</code> elements.
The <code>c</code> elements of the <code>dynarray</code>
are direct-initialized ([decl.init]) with the corresponding elements of <code>d</code>.
<del>May or may not invoke the global <code>operator new</code>.</del>
<ins>When invoked for an object with other than automatic storage duration,
or when invoked via a placement new,
allocates elements with the global <code>operator new</code>.
Otherwise may allocate elements with the global <code>operator new</code>
or may use another mechanism.</ins>
</p>
</blockquote>

</blockquote>

<p>
Edit the effects paragraph for the allocator constructors.
</p>

<blockquote class="std">

<blockquote>
<p>
<i>Effects:</i>
Equivalent to the preceding constructors except that
each element is constructed with uses-allocator construction ([allocator.uses.construction])
<ins>where the global <code>operator new</code> would have been used. 
</p>
</blockquote>

</blockquote>


</body></html>
