<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">FWIW, I agree ::abort is more appropriate.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 2019 Jan  28, at 10:44, Louis Dionne via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" class="">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">My understanding is that libc++ has a no-exceptions mode under which we never throw and never use try-catch blocks. This mode is enabled by defining <font face="Menlo" class="">_LIBCPP_NO_EXCEPTIONS</font>, or by passing <font face="Menlo" class="">LIBCXX_ENABLE_EXCEPTIONS=OFF</font> when configuring CMake.</div><div class=""><br class=""></div><div class="">However, I'd like to understand the design of this mode a bit better. It seems like we sometimes call <font face="Menlo" class="">abort()</font> instead of throwing, but sometimes we just swallow the would-be exception and carry on. For example, instead of throwing <font face="Menlo" class="">std::bad_optional_access</font>, we call <font face="Menlo" class="">std::abort()</font>:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">    void __throw_bad_optional_access() {</font></div><div class=""><font face="Menlo" class="">    #ifndef _LIBCPP_NO_EXCEPTIONS</font></div><div class=""><font face="Menlo" class="">            throw bad_optional_access();</font></div><div class=""><font face="Menlo" class="">    #else</font></div><div class=""><font face="Menlo" class="">            _VSTD::abort();</font></div><div class=""><font face="Menlo" class="">    #endif</font></div><div class=""><font face="Menlo" class="">    }</font></div><div class=""><br class=""></div><div class="">This makes sense to me. However, in other cases, we just swallow the exception. For example, in <font face="Menlo" class="">std::map::at</font> when we can't find the key, we just don't throw an exception, and we dereference a null pointer unless I'm mistaken:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">    template <class _Key, class _Tp, class _Compare, class _Allocator></font></div><div class=""><font face="Menlo" class="">    const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const {</font></div><div class=""><font face="Menlo" class="">        __parent_pointer __parent;</font></div><div class=""><font face="Menlo" class="">        __node_base_pointer __child = __tree_.__find_equal(__parent, __k);</font></div><div class=""><font face="Menlo" class="">    #ifndef _LIBCPP_NO_EXCEPTIONS</font></div><div class=""><font face="Menlo" class="">        if (__child == nullptr)</font></div><div class=""><font face="Menlo" class="">            throw out_of_range("map::at:  key not found");</font></div><div class=""><font face="Menlo" class="">    #endif  // _LIBCPP_NO_EXCEPTIONS</font></div><div class=""><font face="Menlo" class="">        return static_cast<__node_pointer>(__child)->__value_.__get_value().second;</font></div><div class=""><font face="Menlo" class="">    }</font></div><div class=""><br class=""></div><div class="">Here, when <font face="Menlo" class="">__child == nullptr</font>, we do NOT throw an exception and we end up dereferencing it, which is UB. I haven't made a full survey of libc++, but I'd like to know whether this is by design, and if so, what is the rationale for it. Otherwise, I'd like for us to agree on what the behaviour should be (I suggest <font face="Menlo" class="">std::abort()</font>) so that we can fix places that don't behave correctly.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Louis</div></div><div class=""><br class=""></div></div>_______________________________________________<br class="">libcxx-dev mailing list<br class=""><a href="mailto:libcxx-dev@lists.llvm.org" class="">libcxx-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev<br class=""></div></blockquote></div><br class=""></body></html>