Boost logo

Boost :

Subject: Re: [boost] The noexcept Specifier & Block
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2009-04-17 04:43:58


Alexander Terekhov wrote:
> Sebastian Redl wrote:
> [...]
>
>>> unexpected() at throw point.
>>>
>>>
>> We don't need noexcept for that; that's what an empty throw declaration
>> does.
>>
>
> I'll let David Abrahams explain it to you. He knows quite well that
> violation of "throw declaration" under the current standard doesn't
> result in invocation of unexpected() at *throw point*.
>
Minor detail that I overlooked in your post. No need to get so
condescending. I really don't appreciate it.
> Beside that, you're simply not paying attention:
>
> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2855.html#exception-spec
>
> "We therefore propose to deprecate C++ exception specifications in
> C++0x"
>
So throw() is deprecated. That doesn't change the fact that its behavior
is very similar to what you propose for noexcept.

But if I were to implement noexcept in a compiler (and actually, there's
a good chance I will be the one to implement it in Clang), I might give
debug mode a stack of noexcept block locations, which is checked on
throw. Add a flag that we're inside a try, and we've pretty much covered
it. However, this approach is not suitable for what you want, for two
reasons:
1) There's a (small) cost at entering a noexcept or try block. I very
much doubt the standards committee would vote for something that
prevents zero-cost exceptions.
2) It's not completely reliable. It won't detect the case where we're in
a try block that doesn't catch all exceptions, and in particular won't
catch the one you're about to throw.

I still think that the compile error for noexcept-marked functions is
something we definitely want.

Sebastian


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk