Re: Is there any standard/guarantees for exception safety in STL operations?
On 18 Jul., 05:24, Michael Kilburn <crusader.m...@gmail.com> wrote:
Hi,
I have checked C++ standard and did not find requirements imposed on
library implementation with respect to exception safety. But this is
as important of other parts of contract between library and client set
in standard. E.g. if program relies on strong guarantee provided by
some operation and another STL implementation provides only basic --
this program is not C++ program (in a sense that compiled in different
standard-compliant environment it will behave differently).
There exist some very general statements and guarantees, see below.
Did I miss some standard addendum or followup papers?
Surely, but none of them is relevant for the C++ standard.
Unless an ISO standard particularly refers to some other
standard, no such statements/guarantees could be imposed
on a compiler satisfying the standard.
Can someone point me to right direction, please?
Some examples (all referring to ISO/IEC 14882:2003(E)):
1) 17.4.3.6/2:
"In particular, the effects are undefined in the following cases
[..]
? if any replacement function or handler function or destructor
operation throws an exception, unless specifically allowed in
the applicable Required behavior paragraph."
2) 17.4.4.8/2+3:
2 None of the functions from the Standard C library shall
report an error by throwing an exception, unless it calls
a program-supplied function that throws an exception.
3 No destructor operation defined in the C++ Standard Library
will throw an exception. Any other functions defined in the
C++ Standard Library that do not have an exception-specification
may throw implementation-defined exceptions unless otherwise
specified. [..]
3) 20.4.4/1:
"[..] In the following algorithms, if an exception is thrown
there are no effects."
4) 21.1.1/1:
"[..] Operations on Traits shall not throw exceptions."
5) 23.1/10:
"Unless otherwise specified (see 23.2.1.3 and 23.2.4.3) all
container types defined in this clause meet the following
additional requirements:
? if an exception is thrown by an insert() function while
inserting a single element, that function has no effects.
? if an exception is thrown by a push_back() or push_front()
function, that function has no effects.
? no erase(), pop_back() or pop_front() function throws an
exception.
? no copy constructor or assignment operator of a returned
iterator throws an exception.
? no swap() function throws an exception unless that exception
is thrown by the copy constructor or assignment operator of
the container?s Compare object (if any; see 23.1.2).[..]"
6) 23.2.1.3/2:
"Notes: If an exception is thrown other than by the copy
constructor or assignment operator of T there are no effects."
Remark: While this is a seemingly non-normative note in C++03
the intend was to make this a normative requirement. This
state has been fixed in C++0x.
7) 23.2.1.3/6:
"Throws: Nothing unless an exception is thrown by the copy
constructor or assignment operator of T."
8) 23.2.2.3/1:
"Notes: [..] If an exception is thrown there are no effects."
(See bullet 5)
9) 23.2.2.4/16:
"Throws: Nothing unless an exception is thrown by *i == value
or pred(*i) != false."
10) 23.2.2.4/31:
"Notes: Stable: the relative order of the equivalent elements
is preserved. If an exception is thrown the order of the
elements in the list is indeterminate."
(See bullet 5)
I'm stopping here, but it is quite easy to find the relevant
locations in the wording by searching for the word "exception"
in the document.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]