Created on 2003-03-25.00:00:00 last changed 172 months ago
Proposed resolution:
In [string.swap], add a throws clause:
Throws: Shall not throw exceptions.
std::basic_string, [basic.string] paragraph 2 says that basic_string "conforms to the requirements of a Sequence, as specified in (23.1.1)." The sequence requirements specified in (23.1.1) to not include any prohibition on swap members throwing exceptions.
Section [container.requirements] paragraph 10 does limit conditions under which exceptions may be thrown, but applies only to "all container types defined in this clause" and so excludes basic_string::swap because it is defined elsewhere.
Eric Niebler points out that [basic.string] paragraph 5 explicitly permits basic_string::swap to invalidates iterators, which is disallowed by [container.requirements] paragraph 10. Thus the standard would be contradictory if it were read or extended to read as having basic_string meet [container.requirements] paragraph 10 requirements.
Yet several LWG members have expressed the belief that the original intent was that basic_string::swap should not throw exceptions as specified by [container.requirements] paragraph 10, and that the standard is unclear on this issue. The complexity of basic_string::swap is specified as "constant time", indicating the intent was to avoid copying (which could cause a bad_alloc or other exception). An important use of swap is to ensure that exceptions are not thrown in exception-safe code.
Note: There remains long standing concern over whether or not it is possible to reasonably meet the [container.requirements] paragraph 10 swap requirements when allocators are unequal. The specification of basic_string::swap exception requirements is in no way intended to address, prejudice, or otherwise impact that concern.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg2501 |
2003-03-25 00:00:00 | admin | create |