Title
basic_string range mutators unintentionally require a default constructible allocator
Status
c++17
Section
[string.append][string.assign][string.insert] [string.replace]
Submitter
Billy O'Neal III

Created on 2016-10-25.00:00:00 last changed 89 months ago

Messages

Date: 2017-03-03.22:08:49

Proposed resolution:

This wording is relative to N4606.

  1. In [string.append], add the allocator parameter to the range overload temporary:

    template<class InputIterator>
      basic_string& append(InputIterator first, InputIterator last);
    

    -19- Requires: [first, last) is a valid range.

    -20- Effects: Equivalent to append(basic_string(first, last, get_allocator())).

    -21- Returns: *this.

  2. In [string.assign], add the allocator parameter to the range overload temporary:

    template<class InputIterator>
      basic_string& assign(InputIterator first, InputIterator last);
    

    -23- Effects: Equivalent to assign(basic_string(first, last, get_allocator())).

    -24- Returns: *this.

  3. In [string.insert], add the allocator parameter to the range overload temporary:

    template<class InputIterator>
      iterator insert(const_iterator p, InputIterator first, InputIterator last);
    

    -23- Requires: p is a valid iterator on *this. [first, last) is a valid range.

    -24- Effects: Equivalent to insert(p - begin(), basic_string(first, last, get_allocator())).

    -25- Returns: An iterator which refers to the copy of the first inserted character, or p if first == last.

  4. In [string.replace], add the allocator parameter to the range overload temporary:

    template<class InputIterator>
      basic_string& replace(const_iterator i1, const_iterator i2,
                            InputIterator j1, InputIterator j2);
    

    -32- Requires: [begin(), i1), [i1, i2) and [j1, j2) are valid ranges.

    -33- Effects: Calls replace(i1 - begin(), i2 - i1, basic_string(j1, j2, get_allocator())).

    -34- Returns: *this.

Date: 2017-03-03.22:08:49

[ Kona 2017-02-28 ]

Accepted as Immediate.

Date: 2017-02-13.00:00:00

[ 2017-02-13 Alisdair responds: ]

Looks good to me - no suggested alternative

Date: 2016-11-15.00:00:00

[ 2016-11-12, Issaquah ]

Sat AM: Priority 2

Alisdair to investigate and (possibly) provide an alternate P/R

Date: 2016-10-25.00:00:00

Email discussion occurred on the lib reflector.

basic_string's mutation functions show construction of temporary basic_string instances, without passing an allocator parameter. This says that basic_string needs to use a default-initialized allocator, which is clearly unintentional. The temporary needs to use the same allocator the current basic_string instance uses, if an implmentation needs to create a temporary at all.

libc++ already does this; I believe libstdc++ does as well (due to the bug report we got from a user that brought this to our attention), but have not verified there. I implemented this in MSVC++'s STL and this change is scheduled to ship in VS "15" RTW.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2017-03-05 23:46:08adminsetstatus: immediate -> wp
2017-03-03 22:08:49adminsetmessages: + msg9051
2017-03-03 22:08:49adminsetstatus: new -> immediate
2017-02-13 16:09:44adminsetmessages: + msg8939
2016-11-21 05:09:01adminsetmessages: + msg8671
2016-11-01 19:49:14adminsetmessages: + msg8579
2016-10-25 00:00:00admincreate