This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH: Improve exceptions/inlining compile-time performance
On Tue, 2003-04-22 at 01:53, Richard Guenther wrote:
> Nice improvement - I'll try this on the POOMA testcases.
>
> What I'd like to know is wether the compiler can detect that in
>
> struct foo {
> int get() const { return i; }
> int i;
> };
>
> get() is actually throw(), or if we really need to start putting throw()
> after every trivial method declaration... I.e. in what cases do we really
> help the compiler here?
The compiler will figure out that "get()" cannot throw, now.
However, if you are in this situation:
template <typename T> void f() {}
template <typename T> void g() { f<T>(); }
template void g<int>();
the compiler will instantiate f<int> *while instantiating g<int>* in
order to prove that f<int> does not throw. That can cause the compiler
to use more memory. If you do:
template <typename T> void f() throw () {}
you will do (slightly) better in that it now can put off instantiating
f<int> until later.
In general, I'd put "throw ()" in as many places as possible, starting
with big functions first, and especially on functions whose bodies are
not available to the compiler, or on functions that call functions that
might throw, but handle the exception internally, like:
void f() { try { g(); } catch (...) { } }
Putting a "throw ()" on "f" will definitely be a win for the forseeable
future.
--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery dot com