Topic: COW strings banned because of exceptions?
Author: David Abrahams <dave@boost-consulting.com>
Date: Thu, 16 Sep 2004 15:14:40 +0000 (UTC) Raw View
kanze@gabi-soft.fr writes:
> As far as I can see, something like:
>
> template< typename CharT >
> std::basic_string< CharT >::const_reference
> std::basic_string< CharT >::at() const
> {
> throw 3.14159 ;
> }
>
> is a perfectly conforming implementation. Not a very useful one, of
> course, but the standard doesn't require usefulness.
>
> If you think that this is a misinterpretation of the standard, please
> explain why.
You understand correctly.
> If you think that it is a defect, or at least, something we should
> change, I'm behind you 100%. It means that in theory, at least, it is
> impossible to write exception safe code without depending on
> implementation defined behavior.
That's already possible.
> (Note, for example, that std::string::swap doesn't have an exception
> specification either.)
Bingo. That should be changed, just to keep people from making
mistakes with it. But it's not, strictly speaking, a defect.
>> For basic_string<>::at, we have:
>
>> 21.3.4(3):
>> Throws: out_of_range if pos >= size().
>
>> That is, at may not throw an exception of any type besides
>> out_of_range, and it may throw no exceptions if pos < size().
>
> All that says is that basic_string<>::at MUST throw the designated
> exception for this particular error.
I'm not even sure it's that strong.
> The paragraph you quote says that a function "can" report an error
> by means of the specified exception. It does not say that it "shall
> not" raise any other exceptions.
>
> (On rereading it: I don't like the use of "can" either. Normally,
> requirements on an implementation use the verb "shall". I would much
> prefer text which clearly required an implementation to report errors
> decribed in the Throws: clause by means of the described exception, or
> one derived from it. I rather think that this was the intent, but my
> interpretation of "can", in the context of the standard, is that an
> implementation is allowed to, but not required to.)
Correct. I think it's meant to be "guidance for implementors".
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]