__attribute__((cleanup(function)) versus try/finally

Jason Merrill jason@redhat.com
Thu May 15 17:00:00 GMT 2003


On 13 May 2003 14:06:50 -0700, Mark Mitchell <mark@codesourcery.com> wrote:

> I'd also still prefer to see a solution that was maximally circumspect;
> rather than approach this from a "what is the most elegant language
> design?" point of view, I'd prefer a "what is the absolute minimal
> feature needed to implement this POSIX requirement?" point of view.
>
> That leads me towards __builtin_pthread_cleanup_push.  

I think this is the core of the disagreement, and it seems like a
philosophical difference which can't really be addressed with technical
arguments.  Perhaps this is a matter for the steering committee, after all.

Basically, the choice is between a general language extension and a
specific compiler hook.

> For now, I'd much rather we just do as little as possible in the
> compiler, and I'd also rather that we encourage people who really want
> exceptions to use a language that has them.  We do ourselves a
> disservice if we implicitly perpetuate the myth that using the C subset
> of C++ is somehow worse than just using "straight" C.

But try/finally doesn't provide exceptions.  It provides a way of making
cleanups explicit, which in turn provides exception safety.  People who
really want exceptions would still need to use a language that have them.

try/finally is a useful construct even in the absence of exceptions; it
provides a structured alternative to "goto cleanup_and_return;".

> In any case, there are some semantics to be defined; if a cleanup throws
> an exception, what happens?  (You can't call std::terminate in a pure C
> program.)

A C++ exception carries a pointer to terminate; we could generalize that.

Jason



More information about the Gcc mailing list