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.

2318. basic_string's wording has confusing relics from the copy-on-write era

Section: 20.3.2 [basic.string] Status: Resolved Submitter: Stephan T. Lavavej Opened: 2013-09-21 Last modified: 2018-12-01

Priority: 4

View all other issues in [basic.string].

View all issues with Resolved status.

Discussion:

20.3.2.4 [string.capacity]/8 specifies basic_string::resize(n, c) with:

Effects: Alters the length of the string designated by *this as follows:

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.

At least 7 paragraphs are affected: 20.3.2.4 [string.capacity]/8, 20.3.2.6.2 [string.append]/9, 20.3.2.6.3 [string.assign]/3 and /10, 20.3.2.6.4 [string.insert]/11, 20.3.2.6.5 [string.erase]/4, and 20.3.2.6.6 [string.replace]/11 say "replaces the string [designated/controlled] by *this". (20.3.2.6.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: