This patch adds a new doWithCleanup abstraction to LLVM that works
with llvm::Error, int, bool, and <insert your own type here>
return types that propagate status.
This abstraction is a more general way of having a conditional cleanup
that can be used with multiple return paths out of a function.
Test cases and a first use case in clang are part of the patch.
I guess this would be written as:
Which seems pretty legible - makes me unsure it's worth the complexity of building something like doWithCleanup, not that it's heinously complicated by any means - but all the traits stuff, etc.
& ideally/in general this'd usually be dealt with with some kind of RAII ownership model rather than such a strong stateful transition of an existing object that needs to be undone, rather than destroying an object.