This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: catch(...) and forced unwind
- From: Jamie Lokier <jamie at shareable dot org>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Matt Austern <austern at apple dot com>, David Abrahams <dave at boost-consulting dot com>, Jason Merrill <jason at redhat dot com>, Ulrich Drepper <drepper at redhat dot com>, gcc at gcc dot gnu dot org, Richard Henderson <rth at redhat dot com>, Nathan Myers <ncm at cantrip dot org>, Jakub Jelinek <jakub at redhat dot com>, wekempf at cox dot net, fjh at cs dot mu dot oz dot au, Benjamin Kosnik <bkoz at redhat dot com>, William Kempf <williamkempf at hotmail dot com>
- Date: Thu, 18 Dec 2003 18:20:51 +0000
- Subject: Re: catch(...) and forced unwind
- References: <xypekv9nr9u.fsf@miranda.boston.redhat.com> <u65gkyhv4.fsf@boost-consulting.com> <20031214035909.GE2416@tofu.dreamhost.com> <xypk74xltaa.fsf@miranda.boston.redhat.com> <ullpdlksl.fsf@boost-consulting.com> <xyp1xr5lh5q.fsf@miranda.boston.redhat.com> <usmjlhryu.fsf@boost-consulting.com> <278A5A0A-3001-11D8-8564-00039390D9E0@apple.com> <20031218133852.GA16315@mail.shareable.org> <1071766144.3543.20.camel@minax.codesourcery.com>
Mark Mitchell wrote:
> You'd also want to do the disabling inside "throw (int)" functions for
> example. And, then, you'd want to reenable if a "throw (int)" function
> called a "throw (...)" function (perhaps inside a try-block).
>
> I think that if you did all that, your idea would not violate either
> standard. However, it still wouldn't really solve the problem. For
> example:
>
> // This function has no exception-specification but I know
> // it only throws ints!
> inline void f() { printf ("Throwing now!"); throw 3; }
>
> // This function will never throw anything.
> void g() throw () { try { f(); } catch (int) { } }
>
> is the sort of C++ code that could be validated in a non-threaded
> environment, but would call "std::terminate" if "printf" were
> cancelled.
No, it wouldn't call std::terminate.
g() would disable cancellations for its duration due to "throw()", and
the "try {} catch (int) {}" block doesn't change that. ("catch (...)"
would change it as you said). g() calls f() which makes no change to
the cancellation state. Therefore the printf cannot be cancelled -
the cancellation will be deferred to the next cancellation point after
g() returns, assuming g()'s caller didn't disable cancellations too.
-- Jamie