This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-01-15


2207. Alignment of allocation function return value

Section: 6.7.5.5.2  [basic.stc.dynamic.allocation]     Status: CD5     Submitter: Richard Smith     Date: 2015-12-02

[Accepted as a DR at the July, 2019 meeting.]

According to 6.7.5.5.2 [basic.stc.dynamic.allocation] paragraph 2,

For an allocation function other than a reserved placement allocation function (17.6.3.4 [new.delete.placement]), the pointer returned is suitably aligned so that it can be converted to a pointer to any suitable complete object type (17.6.3.2 [new.delete.single]) and then used to access the object or array in the storage allocated (until the storage is explicitly deallocated by a call to a corresponding deallocation function).

This requirement seems excessive, as it appears to require the strictest fundamental alignment even for objects that are too small to require such an alignment.

Proposed resolution (March, 2019):

  1. Change 6.7.5.5.2 [basic.stc.dynamic.allocation] paragraph 2 as follows:

  2. ...The order, contiguity, and initial value of storage allocated by successive calls to an allocation function are unspecified. For an allocation function other than a reserved placement allocation function (17.6.3.4 [new.delete.placement]), the pointer returned is suitably aligned so that it can be converted to a pointer to any suitable complete object type (17.6.3.2 [new.delete.single]) and then used to access the object or array in the storage allocated (until the storage is explicitly deallocated by a call to a corresponding deallocation function). Even if the size of the space requested...
  3. Add the following as a new paragraph to 6.7.5.5.2 [basic.stc.dynamic.allocation] after the existing paragraph 2:

  4. For an allocation function other than a reserved placement allocation function (17.6.3.4 [new.delete.placement]), the pointer returned on a successful call shall represent the address of storage that is aligned as follows:

  5. Change 17.6.3.2 [new.delete.single] paragraph 1 as follows:

  6. Effects: The allocation functions (6.7.5.5.2 [basic.stc.dynamic.allocation]) called by a new-expression (7.6.2.8 [expr.new]) to allocate size bytes of storage. The second form is called for a type with new-extended alignment, and allocates storage with the specified alignment. The the first form is called otherwise, and allocates storage suitably aligned to represent any object of that size provided the object's type does not have new-extended alignment.
  7. Change 17.6.3.3 [new.delete.array] paragraph 1 as follows:

  8. Effects: The allocation functions (6.7.5.5.2 [basic.stc.dynamic.allocation]) called by the array form of a new-expression (7.6.2.8 [expr.new]) to allocate size bytes of storage. The second form is called for a type with new-extended alignment, and allocates storage with the specified alignment. The the first form is called otherwise, and allocates storage suitably aligned to represent any array object of that size or smaller, provided the object's type does not have new-extended alignment.218