Dynarray Allocation Context (original) (raw)
ISO/IEC JTC1 SC22 WG21 N4043 - 2014-05-22
Lawrence Crowl, Lawrence@Crowl.org
Contents
Introduction
Solution
Wording changes
23.3.4.2 dynarray constructor and destructor [dynarray.cons]
Introduction
The dynarray
class (N3662 C++ Dynamic Arraysand 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 inN3899 Nested AllocationsectionNested Lifetime. We need specific wording to address this case.
Solution
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.
Wording changes
The proposed wording changes are relative toN3820 Working Draft, Technical Specification — Array Extensions).
23.3.4.2 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.