[PATCH] D108905: [ItaniumCXXABI] Make __cxa_end_catch calls unconditionally nounwind

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 30 13:44:30 PDT 2021


rjmccall added a comment.

In D108905#2973172 <https://reviews.llvm.org/D108905#2973172>, @modimo wrote:

> In D108905#2973099 <https://reviews.llvm.org/D108905#2973099>, @rjmccall wrote:
>
>> Yeah, I think this is the most natural interpretation of the current standard.  But that would be a very unfortunate rule, because people who write `catch (...) {}` do reasonably expect that that code will never throw.   In fact, it would be quite difficult — perhaps impossible — to write code that actually swallowed all exceptions: even `try { try { foo() } catch(...) {} } catch (...) {}` wouldn't work, because you could throw an exception whose destructor throws an exception whose destructor throws an exception ad infinitum.
>
> Yeah it's not great and also something that practically will never happen. I think terminate guards are the only thing that really swallows all exceptions except here you can't guard the catch variable destructor unless you want to change up and depend on library implementation. My immediate thought is something like `catch(...) noexcept {}` to express this but it's a solution to a problem that really shouldn't exist.

Well, I think `catch (...) { std::terminate(); }` should work to express that outer catch, if only because the end of the catch is never reached.  But yeah, I agree that this is clearly a problem that shouldn't exist.

We might be able to require exception types to have `noexcept` destructors.  Formally, it would have source compatibility / language-version incompatibility implications, but in practice I doubt it would cause many problems, especially if it was just a "if this actually throws it'll have UB" warning in pre-C++23 language modes for throwing types with explicitly noexcept destructors.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108905/new/

https://reviews.llvm.org/D108905



More information about the cfe-commits mailing list