This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.
forward_list::resize(size_type, const value_type&) effects incorrectSection: 23.3.7.5[forward.list.modifiers]Status:C++17Submitter: Tim SongOpened: 2016-01-14Last modified: 2023-02-07
Priority:0
View all otherissues in [forward.list.modifiers].
View all issues withC++17 status.
Discussion:
[forwardlist.modifiers]/29 says that the effects offorward_list::resize(size_type sz, const value_type& c) are:
Effects: If
sz < distance(begin(), end()), erases the lastdistance(begin(), end()) - szelementsfrom the list. Otherwise, insertssz - distance(begin(), end())elements at the end ofthe list such that each new element,e, is initialized by a method equivalent to callingallocator_traits<allocator_type>::construct(get_allocator(), std::addressof(e), c).
In light of LWG2218(i), the use ofallocator_traits<allocator_type>::construct is incorrect, as a rebound allocator may be used. There's no need to repeat this information, in any event — no other specification ofresize() does it.
[2016-02, Issues Telecon]
P0; move to Tentatively Ready.
[2016-02-11, Alisdair requests reopening]
I believe the standard is correct as written, and that by removing the clear directionto make the copy with uses-allocator-construction, we open ourselves to disputingthis very point again at some point in the future.
The issue seems to be complaining that a rebound allocator may be used instead ofthe allocator returned byget_allocator() call, and nailing us down to exactly whichinstantiation ofallocator_traits is used. Given the requirements on allocators beingconstructible from within the same template "family" though, and specifically thatcopies compare equal and can allocate/deallocate on each other's behalf, this shouldclearly fall under existing as-if freedom. The construct call is even more clear, asthere is no requirement that the allocator to construct be of a kind that can allocatethe specific type being constructed — a freedom granted precisely so this kind of codecan be written, and be correct, regardless of internal node type of any container andthe actual rebound allocator used internally.I think the new wording is less clear than the current wording, and would prefer toresolve as NAD.Proposed resolution:
This wording is relative to N4567.
Edit [forwardlist.modifiers]/29 as indicated:
[Drafting note: "copies of
c" is the phrase used byvector::resizeanddeque::resize.]
void resize(size_type sz, const value_type& c);-29-Effects: If
sz < distance(begin(), end()), erases the lastdistance(begin(), end()) - szelementsfrom the list. Otherwise, insertssz - distance(begin(), end())elementscopies ofcat the end of the listsuch that each new element,.e, is initialized by a method equivalent to callingallocator_traits<allocator_type>::construct(get_allocator(), std::addressof(e), c)