[libcxx-commits] [PATCH] D57761: [libc++] Avoid UB in the no-exceptions mode in a few places

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 5 10:13:44 PST 2019


mclow.lists added a comment.

I think all of these are no-brainers except the one calling `__throw_failure`.



================
Comment at: libcxx/src/ios.cpp:271
     if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
-        throw failure("ios_base::clear");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+        __throw_failure("ios_base::clear");
 }
----------------
dexonsmith wrote:
> ldionne wrote:
> > Actually, looking at this again, it seems like we probably don't want to abort here, since the stream will report the error with the error flags. So I should not change this one -- @mclow.lists does that seem right to you?
> `::abort` seems more consistent to me.  The user has set the exception bit, so I wouldn't expect them to have control flow to handle errors otherwise.  Moreover, the direct user could be templated/inlined header code which doesn't know that `-fno-exceptions` has been passed for this project/TU.
> 
> More generally, I think a strict library policy of turning throws into aborts will lead to behaviour that's predictable for users.
If we do this, we should be consistent about it.  
Do we want to say "Compiling with exceptions disabled makes iostreams act as if `state & __exceptions_` is always `false`?

And then what do we do if the user explicitly sets the `__exceptions_` flag? Abort there?


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D57761





More information about the libcxx-commits mailing list