<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Menlo;
        panose-1:2 11 6 9 3 8 4 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">+1. I’m configured in this mode exclusively, and also prefer abort().<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Olivier<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">libcxx-dev <libcxx-dev-bounces@lists.llvm.org> on behalf of Duncan Exon Smith via libcxx-dev <libcxx-dev@lists.llvm.org><br>
<b>Reply-To: </b>Duncan Exon Smith <dexonsmith@apple.com><br>
<b>Date: </b>Monday, January 28, 2019 at 11:01 AM<br>
<b>To: </b>Louis Dionne <ldionne@apple.com><br>
<b>Cc: </b>Libc++ Dev <libcxx-dev@lists.llvm.org><br>
<b>Subject: </b>Re: [libcxx-dev] Question about the no-exceptions mode of libc++<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">FWIW, I agree ::abort is more appropriate.<o:p></o:p></p>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On 2019 Jan  28, at 10:44, Louis Dionne via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Hi,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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
<span style="font-family:Menlo">_LIBCPP_NO_EXCEPTIONS</span>, or by passing <span style="font-family:Menlo">
LIBCXX_ENABLE_EXCEPTIONS=OFF</span> when configuring CMake.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">However, I'd like to understand the design of this mode a bit better. It seems like we sometimes call
<span style="font-family:Menlo">abort()</span> instead of throwing, but sometimes we just swallow the would-be exception and carry on. For example, instead of throwing
<span style="font-family:Menlo">std::bad_optional_access</span>, we call <span style="font-family:Menlo">
std::abort()</span>:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    void __throw_bad_optional_access() {</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    #ifndef _LIBCPP_NO_EXCEPTIONS</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">            throw bad_optional_access();</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    #else</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">            _VSTD::abort();</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    #endif</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    }</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This makes sense to me. However, in other cases, we just swallow the exception. For example, in
<span style="font-family:Menlo">std::map::at</span> when we can't find the key, we just don't throw an exception, and we dereference a null pointer unless I'm mistaken:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    template <class _Key, class _Tp, class _Compare, class _Allocator></span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const {</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">        __parent_pointer __parent;</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">        __node_base_pointer __child = __tree_.__find_equal(__parent, __k);</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    #ifndef _LIBCPP_NO_EXCEPTIONS</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">        if (__child == nullptr)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">            throw out_of_range("map::at:  key not found");</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    #endif  // _LIBCPP_NO_EXCEPTIONS</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">        return static_cast<__node_pointer>(__child)->__value_.__get_value().second;</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Menlo">    }</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Here, when <span style="font-family:Menlo">__child == nullptr</span>, 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
<span style="font-family:Menlo">std::abort()</span>) so that we can fix places that don't behave correctly.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Louis<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a><br>
https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev<o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
</div>

<DIV>
<HR>
</DIV>
<DIV>This email message is for the sole use of the intended recipient(s) and may 
contain confidential information.  Any unauthorized review, use, disclosure 
or distribution is prohibited.  If you are not the intended recipient, 
please contact the sender by reply email and destroy all copies of the original 
message. </DIV>
<DIV>
<HR>
</DIV>
</body>
</html>