-fno-exceptions documentation

Peter Dimov pdimov@mmltd.net
Thu Dec 8 13:50:00 GMT 2005


Paolo Carlini wrote:
> Hi Peter,
>
>> The actual throwing is done by using X<void>::throw_bad_alloc. The
>> helper template is only necessary to give the correct "linkage" to
>> throw_bad_alloc so that multiple definitions do not result in an
>> error.
>>
>> A compiled library that wishes to be "exception neutral" (such as
>> libstdc++ itself) should #define _EXCEPTION_NEUTRAL and would receive
>> no definition of throw_bad_alloc, leaving the calls unresolved.
>>
>> User code just #includes the above header (indirectly via any
>> libstdc++ include) and receives an appropriate (for the current
>> __EXCEPTIONS setting) definition for X<void>::throw_bad_alloc because
>> of the explicit instantiation.
>
> I'm trying to catch up on this (after a few days spent on something
> completely different...)
>
> First, thanks of course both to you and Howard for the interesting
> feedback.
>
> Peter, at the moment, I have trouble understanding what you are
> suggesting specifically for libsupc++, for things like operator new...

I'm not familiar with the internal structure of libstdc++, so please forgive 
me if I'm not making any sense.

Howard's request was to come up with a way that would allow libstdc++ to 
work with

1. Programs compiled without -fno-exceptions

and

2. Programs compiled with -fno-exceptions

without a recompile of libstdc++.

The approach I present achieves this by making libstdc++ (and libsupc++) 
issue calls to X<void>::throw_...; since these functions are declared but 
not defined when _EXCEPTION_NEUTRAL is in effect, this will result in 
libstdc++ containing unresolved references to these functions.

When a program includes a libstdc++ header, these functions will be defined 
as either throwing or aborting depending on the current state of 
__EXCEPTIONS, then an explicit template instantiation will inject these 
definitions into the .o file that is produced.

These definitions will satisfy the unresolved references in libstdc++ and 
libsupc++ when the program is linked.



More information about the Libstdc++ mailing list