ISO/IEC JTC1 SC22 WG21 N4043 - 2014-05-22
Lawrence Crowl, Lawrence@Crowl.org
Introduction
Solution
Wording changes
23.3.4.2 dynarray
constructor and destructor [dynarray.cons]
The dynarray
class
(
N3662 C++ Dynamic Arrays
and
N3820 Working Draft, Technical Specification — Array Extensions)
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
N3899 Nested Allocation
section
Nested Lifetime.
We need specific wording to address this case.
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.
The proposed wording changes are relative to N3820 Working Draft, Technical Specification — Array Extensions).
dynarray
constructor and destructor [dynarray.cons]Edit the effects paragraph for the explicit single-argument constructor as follows.
Effects: Allocates storage for c elements.
May or may not invoke the globalThe c elements of theoperator new
.dynarray
are default-initialized (8.5). When invoked for an object with other than automatic storage duration, or when invoked via a placement new, allocates elements with the globaloperator new
. Otherwise may allocate elements with the globaloperator new
or may use another mechanism.
Edit the effects paragraph for the two-argument constructor as follows.
Effects: Allocates storage for
c
elements.May or may not invoke the globalTheoperator new
.c
elements of thedynarray
are direct-initialized ([decl.init]) with argumentv
. When invoked for an object with other than automatic storage duration, or when invoked via a placement new, allocates elements with the globaloperator new
. Otherwise may allocate elements with the globaloperator new
or may use another mechanism.
Edit the effects paragraph for the copy constructor as follows.
Effects: Allocates storage for
d.size()
elements. Thec
elements of thedynarray
are direct-initialized ([decl.init]) with the corresponding elements ofd
.May or may not invoke the globalWhen invoked for an object with other than automatic storage duration, or when invoked via a placement new, allocates elements with the globaloperator new
.operator new
. Otherwise may allocate elements with the globaloperator new
or may use another mechanism.
Edit the effects paragraph for the allocator constructors.
Effects: Equivalent to the preceding constructors except that each element is constructed with uses-allocator construction ([allocator.uses.construction]) where the global
operator new
would have been used.