Title
How do uninitialized memory algorithms obtain pointer without undefined behavior?
Status
resolved
Section
[specialized.algorithms]
Submitter
Alisdair Meredith

Created on 2018-02-12.00:00:00 last changed 3 weeks ago

Messages

Date: 2024-11-28.00:00:00

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

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

Date: 2018-02-15.00:00:00

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

Date: 2020-05-02.19:53:28

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.

History
Date User Action Args
2024-11-28 21:40:34adminsetmessages: + msg14501
2024-11-28 21:40:34adminsetstatus: new -> resolved
2018-03-03 15:21:00adminsetmessages: + msg9696
2018-02-12 00:00:00admincreate