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]

Re: c_std/ and throw()


On Wed, Apr 11, 2001 at 06:17:28PM +0400, Artem Khodush wrote:
> Jakub Jelinek <jakub@redhat.com> wrote:
> 
> > The c_std/ headers throw away the carefully maintained throw()
> > lists glibc maintains in its installed headers for functions which cannot
> > throw.
> > IMHO this is bad and results in worse code generation.
> 
> May be I'm missing something, but for all compilers I know adding 
> throw() lists to function declaration actually makes code _worse_, 
> because any call to such function should be wrapped in a code 
> that checks for violations of throw specifications at run time. 

??
Adding throw() (note the empty list) means the function cannot throw any
exceptions, which means g++ can count on this.
Try compiling
extern "C" void foo(void) throw();
extern "C" void bar(void);

struct C {
  C();
  ~C();
  void n();
};

void f()
{
  C x;
  foo();
}

void b()
{
  C x;
  bar();
}

On i386 with g++ 3.1 branch and -O2, _Z1fv is 41 bytes while while _Z1bv is
63 bytes.
And the vast majority of glibc functions cannot throw any exceptions, it is
C code compiled with -fno-exceptions. The exceptions in glibc are functions
like qsort or bsearch which take function pointer argument, which could be
written in C++ and throw exceptions. These functions are compiled with
-fexceptions and have no throw() at their prototypes in glibc headers.

	Jakub


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