This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TC1 status.

83. String::npos vs. string::max_size()

Section: 27.4.3 [basic.string] Status: TC1 Submitter: Nico Josuttis Opened: 1998-09-29 Last modified: 2016-01-28

Priority: Not Prioritized

View other active issues in [basic.string].

View all other issues in [basic.string].

View all issues with TC1 status.

Duplicate of: 89

Discussion:

Many string member functions throw if size is getting or exceeding npos. However, I wonder why they don't throw if size is getting or exceeding max_size() instead of npos. May be npos is known at compile time, while max_size() is known at runtime. However, what happens if size exceeds max_size() but not npos, then? It seems the standard lacks some clarifications here.

Proposed resolution:

After 27.4.3 [basic.string] paragraph 4 ("The functions described in this clause...") add a new paragraph:

For any string operation, if as a result of the operation, size() would exceed max_size() then the operation throws length_error.

Rationale:

The LWG believes length_error is the correct exception to throw.