Can 'noreturn' functions throw exceptions?

James Avera
Mon Dec 15 18:43:00 GMT 2003

QUESTION: May a function marked with the
'noreturn' attribute terminate by throwing
an exception?  The gcc info entry is silent on this

The answer is not obvious, because the spec says the
compiler can avoid generating code needed only if the
function returns (such as saving registers not
preserved by the function).  For an exception to
be caught, it is necessary for the stack-unwinding
library to find active catch blocks in the call chain.
If the compiler did not genrerate the info needed to
walk the call chain, then 'throw' would not work

I want to use 'noreturn' for an error function called
from performance-critical inlined code (this
register-save instructions in the normal-case flow).

However, the error function throws an excepition which
must be caught at a higher level.  It works in a 
trivial test case on i386/linux.

My question is : Does GCC guarantee that this works
on all platforms?

Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.

More information about the Gcc-help mailing list