basic_string
's wording has confusing relics from the copy-on-write eraSection: 27.4.3 [basic.string] Status: Resolved Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2018-11-25
Priority: 4
View other active issues in [basic.string].
View all other issues in [basic.string].
View all issues with Resolved status.
Discussion:
27.4.3.5 [string.capacity]/8 specifies basic_string::resize(n, c)
with:
Effects: Alters the length of the string designated by
*this
as follows:
If
n <= size()
, the function replaces the string designated by*this
with a string of lengthn
whose elements are a copy of the initial elements of the original string designated by*this
.If
n > size()
, the function replaces the string designated by*this
with a string of lengthn
whose firstsize()
elements are a copy of the original string designated by*this
, and whose remaining elements are all initialized toc
.
This wording is a relic of the copy-on-write era. In addition to being extremely confusing, it has undesirable implications.
Saying "replaces the string designated by *this
with a string of length n
whose elements are a copy" suggests
that the trimming case can reallocate. Reallocation during trimming should be forbidden, like vector
.
*this
". (27.4.3.7.7 [string.copy]/3
is different — it "replaces the string designated by s
".)
Of the affected paragraphs, resize()
and erase()
are the most important to fix because they should forbid
reallocation during trimming.
Resolved by the adoption of P1148 in San Diego.
Proposed resolution: