[PATCH] D21706: [libcxx] refactor for throw

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 12 14:55:00 PDT 2016

mclow.lists added a comment.

I just realized that this will break the following code:

  try {  __cxxabiv1:: __cxa_bad_cast(); }
  catch ( std::bad_cast &ex ) {}

because what gets thrown is a `const std::bad_cast &`

Yes, people should catch by value or const reference.
But that doesn't mean that they always do.

Comment at: include/exception:262
@@ -261,3 +261,3 @@
-inline void __libcpp_throw(_Exception const& __e) {
+inline __attribute__((noreturn)) void __libcpp_throw(_Exception const& __e) {
weimingz wrote:
> mclow.lists wrote:
> > I thought that we were going to add a macro for the "no return if no exceptions"
> something like this?
>   #define NORETURN_EXP __attribute__((noreturn))
> #else
>   #define NORETURN_EXP
> #endif
> inline NORETURN_EXP void __libcpp_throw(_Exception const& __e) {
>   ...
> }
There's another patch out for review that adds `noreturn` attributes for some functions when exceptions are disabled. I suggested a macro name like `_LIBCPP_NO_RETURN_WHEN_EXCEPTIONS_DISABLED` for this instead of using the `[[noreturn]]` or `__attribute__((noreturn)) `.

I can't find the review at the moment, but I'll turn it up.


More information about the cfe-commits mailing list