This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: throw(), pure and const flags on functions


On Wed, Apr 15, 2009 at 10:39 PM, Mark Mitchell <mark@codesourcery.com> wrote:
> Gabriel Dos Reis wrote:
>
>> Well, the reason I'm pointing this out is that there are
>> influencial people in the C++ community who make claims
>> tthat 'throw()' is to be discouraged because it makes compilers
>> generate worse code. ?You are claiming to the opposite, that is
>> why the issue is so important.
>
> That's because it depends on where you use throw().
>
> If you write:
>
> ?extern void f();
> ?void g() throw() {
> ? ?f();
> ?}
>
> the "throw()" on "g" probably makes "g" bigger (and/or slower, depending
> on how your compiler implements exceptions). ?That's because the
> compiler has to turn "g" into something like:
>
> ?void g() {
> ? ?try {
> ? ? ?f();
> ? ?} catch (...) {
> ? ? ?std::unexpected();
> ? ?}
> ?}
>
> That try/catch clause costs you. ?But, if you do:

Yes.  But now, if f() is a standard C function that cannot
possibly throw, then annotating g() 'throw()' makes g unnecessarily
bigger and slower.  Thus my suggestion of having the compiler
uses the standard semantics of f() it already has as opposed
to having to annotate g().

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]