This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

3064. How do uninitialized memory algorithms obtain pointer without undefined behavior?

Section: 26.11 [specialized.algorithms] Status: Resolved Submitter: Alisdair Meredith Opened: 2018-02-12 Last modified: 2024-11-28

Priority: 3

View other active issues in [specialized.algorithms].

View all other issues in [specialized.algorithms].

View all issues with Resolved status.

Discussion:

A typical specification of the algorithms for initializing raw memory in <memory> looks like:

Effects: Equivalent to:

for (; first != last; ++first)
  ::new (static_cast<void*>(addressof(*first)))
    typename iterator_traits<ForwardIterator>::value_type;

However, this hides a nasty question:

How do we bind a reference to an uninitialized object when dereferencing our iterator, so that static_cast<void*>(addressof(*first)) does not trigger undefined behavior on the call to *first?

When pointers are the only iterators we cared about, we could simply cast the iterator value to void* without dereferencing. I don't see how to implement this spec safely without introducing another customization point for iterators that performs the same function as casting a pointer to void* in order to get the address of the element.

[2018-02-20, Priority set to 3 after mailing list discussion]

[2024-11-28 Status changed: New → Resolved.]

Resolved by CWG 453, accepted as a DR in March 2024.

Proposed resolution: