Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > std::string exc...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 9346 of 10104
Post > Topic >>

std::string exception safety guarantees?

by hervebronnimann@[EMAIL PROTECTED] Mar 5, 2008 at 10:43 AM

For the life of me, I cannot find anything in the C++ standard that
says what the value of s is after this code, assuming that the resize
*does* throw an exception:

     std::string s("Here is a short string");
     std::string s1 = s;
     try {
         s.resize(s.max_size() + 1); // will throw length_error
exception.
     catch(...) {
     }

I'd expect that s == s1 holds after catching the exception, but there
seems to be no guarantee in the C++ standard.  (Of course, any
implementation I know attempts to allocate, without modifying the
string.)

The closest it comes to offering any guarantees is 21.3, para 3: "3
The class template basic_string conforms to the requirements for a
Sequence (23.1.1) and for a Reversible Container (23.1)."  However,
the chapter 23 only says, on the topic of exceptions:

23.1, para 10: Unless otherwise specified (see 23.2.2.3 and 23.2.5.4)
all container types defined ***in this clause*** (emphasis mine) meet
the following additional requirements: - if an exception is thrown
by...

I take it as saying that this paragraph has *no* implication on
std::basic_string, as it does not define a requirement of Sequence nor
Reversible Container.

Would someone please either 1. point to the relevant language, 2.
share knowledge of an implementation where string does not offer the
strong exception guarantee, 3. point me to the relevant LWG Issue, or
4. encourage me to file one? :)

Thanks for any feedback,
--
Herve Bronnimann


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 8 Posts in Topic:
std::string exception safety guarantees?
hervebronnimann@[EMAIL PR  2008-03-05 10:43:48 
Re: std::string exception safety guarantees?
Martin Sebor <msebor@[  2008-03-06 17:42:26 
Re: std::string exception safety guarantees?
Niels Dekker - no return   2008-03-07 19:07:38 
Re: std::string exception safety guarantees?
"Bo Persson" &l  2008-03-08 11:53:33 
Re: std::string exception safety guarantees?
Mathias Gaunard <loufo  2008-03-09 17:12:21 
Re: std::string exception safety guarantees?
hervebronnimann@[EMAIL PR  2008-03-14 12:07:25 
Re: std::string exception safety guarantees?
hervebronnimann@[EMAIL PR  2008-03-14 12:32:03 
Re: std::string exception safety guarantees?
"Bo Persson" &l  2008-03-16 02:00:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:34:47 CDT 2008.