This is the mail archive of the
mailing list for the libstdc++ project.
Re: throw specs on Standard destructors
On Wed, Dec 11, 2002 at 10:05:17AM -0600, Benjamin Kosnik wrote:
> >>> Third, any code that depends on tight throw specs in libstdc++
> >>> would not be portable to other implementations.
> >Any code that depends on tight throw specs of Standard-conformant
> >implementations would not be portable to GCC.
> ... which is far more of an issue, I think.
No. An implementation is not required to declare destructors throw().
Any code that fails if they're not so declared is broken, because it
assumes an implementation detail that the standard doesn't specify.
It's the worst kind of broken: testing fails to detect the error
until the code is moved. We're doing him an enormous favor by
refusing to compile his code. Wherever he's moving it from failed
to do him that favor.
As I noted earlier, if we do add any "throw()" specs, for performance
reasons, we should wrap them in "#ifndef NDEBUG" so that we can continue
to provide the service of reporting this error.
> 18.104.22.168 -3- No destructor operation defined in the C++ Standard Library
> will throw an exception. [...] An implementation may strengthen this
> implicit exception-specification by adding an explicit one.
> I still think the example code, as posted, is conformant. If it can't
> compile, there's a problem.
There's certainly a problem, but it's easily fixed, and portably:
remove the throw spec from the user code, or (failing that) wrap the
user's destructor in a function try block.
There is no rescuing throw specs from obscurity. They were a mistake.
Let them go.