<div dir="ltr"><div dir="ltr"><div><br></div><div>Changing the behavior of unary noexcept is a much larger and complicated change than fixing vector.</div><div><br></div><div>At the moment `-fno-exceptions` is a subset of standard C++. Changing noexcept would make it non-standard and non-portable.</div><div>Do we want that?</div><div><br></div><div>And there's just nastiness like this:</div><div><br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254)"><div><span style="color:rgb(0,0,255)">void</span> bar();</div><div><span style="color:rgb(0,0,255)">void</span> bar() <span style="color:rgb(0,0,255)">noexcept</span>(<span style="color:rgb(0,0,255)">noexcept</span>(bar())); <span style="color:rgb(0,128,0)">// Cool</span></div><div><span style="color:rgb(0,0,255)">void</span> bar(); <span style="color:rgb(0,0,255)">noexcept</span>(<span style="color:rgb(0,0,255)">false</span>); <span style="color:rgb(0,128,0)">// </span><span style="color:rgb(0,128,0)">Also </span><span style="color:rgb(0,128,0)">Cool</span></div><div><br></div><div>We should pursue std::vector separately. I think the current wording allows either moves or copies, as long as "if an exception is thrown, there are no effects". </div><div>For example [1]</div><div><br></div></div></div><div><span class="m_6638630188628933489gmail-keyword" style="color:rgb(0,96,124);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">void</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap"> push_back</span><span class="m_6638630188628933489gmail-parenthesis" style="color:rgb(175,25,21);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">(</span><span class="m_6638630188628933489gmail-keyword" style="color:rgb(0,96,124);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">const</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap"> T</span><span class="m_6638630188628933489gmail-operator" style="color:rgb(87,0,87);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">&</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap"> x</span><span class="m_6638630188628933489gmail-parenthesis" style="color:rgb(175,25,21);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">)</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">;
</span><span class="m_6638630188628933489gmail-keyword" style="color:rgb(0,96,124);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">void</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap"> push_back</span><span class="m_6638630188628933489gmail-parenthesis" style="color:rgb(175,25,21);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">(</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">T</span><span class="m_6638630188628933489gmail-operator" style="color:rgb(87,0,87);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">&</span><span class="m_6638630188628933489gmail-operator" style="color:rgb(87,0,87);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">&</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap"> x</span><span class="m_6638630188628933489gmail-parenthesis" style="color:rgb(175,25,21);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">)</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify;white-space:pre-wrap">;</span> </div><div><div id="m_6638630188628933489gmail-modifiers-1.sentence-1" class="m_6638630188628933489gmail-sentence" style="display:inline;color:rgb(0,0,0);font-family:serif;font-size:medium;text-align:justify;background-color:rgb(201,251,201)"><span class="m_6638630188628933489gmail-textit" style="font-style:italic">Remarks:</span> [...] </div><div id="m_6638630188628933489gmail-modifiers-1.sentence-4" class="m_6638630188628933489gmail-sentence" style="display:inline;color:rgb(0,0,0);font-family:serif;font-size:medium;text-align:justify;background-color:rgb(201,251,201)">If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of <span class="m_6638630188628933489gmail-texttt" style="font-family:monospace">T</span> or by any <span class="m_6638630188628933489gmail-texttt" style="font-family:monospace">InputIterator</span> operation there are no effects<a class="m_6638630188628933489gmail-hidden_link" href="http://eel.is/c++draft/vector#modifiers-1.sentence-4" style="text-decoration-line:none;color:inherit" target="_blank">.</a></div><span style="color:rgb(0,0,0);font-family:serif;font-size:medium;text-align:justify;background-color:rgb(201,251,201)"> </span><div id="m_6638630188628933489gmail-modifiers-1.sentence-5" class="m_6638630188628933489gmail-sentence" style="display:inline;color:rgb(0,0,0);font-family:serif;font-size:medium;text-align:justify;background-color:rgb(201,251,201)">If an exception is thrown while inserting a single element at the end and <span class="m_6638630188628933489gmail-texttt" style="font-family:monospace">T</span> is <span class="m_6638630188628933489gmail-textit" style="font-style:italic">Cpp17CopyInsertable</span> or <span class="m_6638630188628933489gmail-texttt" style="font-family:monospace">is_nothrow_move_constructible_v<span class="m_6638630188628933489gmail-anglebracket" style="color:rgb(87,0,87)"><</span>T<span class="m_6638630188628933489gmail-anglebracket" style="color:rgb(87,0,87)">></span></span> is <span class="m_6638630188628933489gmail-texttt" style="font-family:monospace"><span class="m_6638630188628933489gmail-literal" style="color:rgb(159,104,7)">true</span></span>, there are no effects<a class="m_6638630188628933489gmail-hidden_link" href="http://eel.is/c++draft/vector#modifiers-1.sentence-5" style="text-decoration-line:none;color:inherit" target="_blank">.</a></div><span style="color:rgb(0,0,0);font-family:serif;font-size:medium;text-align:justify;background-color:rgb(201,251,201)"> </span><div id="m_6638630188628933489gmail-modifiers-1.sentence-6" class="m_6638630188628933489gmail-sentence" style="display:inline;color:rgb(0,0,0);font-family:serif;font-size:medium;text-align:justify;background-color:rgb(201,251,201)">Otherwise, if an exception is thrown by the move constructor of a non-<span class="m_6638630188628933489gmail-textit" style="font-style:italic">Cpp17CopyInsertable</span> <span class="m_6638630188628933489gmail-texttt" style="font-family:monospace">T</span>, the effects are unspecified<a class="m_6638630188628933489gmail-hidden_link" href="http://eel.is/c++draft/vector#modifiers-1.sentence-6" style="text-decoration-line:none;color:inherit" target="_blank">.</a></div> </div><div><br></div><div>Cpp17CopyInsertible implies Cpp17MoveInsertable. And we meet the "if exception, no effects" requirements trivially.</div><div>I might be squinting at the wording too hard, but I think I can fix this as QoI.</div><div><br></div><div>/Eric</div><div><br></div><div>[1] <a href="http://eel.is/c++draft/container.requirements#general-11" target="_blank">http://eel.is/c++draft/container.requirements#general-11</a></div><div>[2] <a href="http://eel.is/c++draft/sequences#vector.modifiers" target="_blank">http://eel.is/c++draft/sequences#vector.modifiers</a></div><div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 17, 2019 at 7:44 PM Duncan Exon Smith via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br><div><br><blockquote type="cite"><div>On 2019 Apr 17, at 11:06, Louis Dionne <<a href="mailto:ldionne@apple.com" target="_blank">ldionne@apple.com</a>> wrote:</div><br class="m_6638630188628933489gmail-m_-8869290827680797975Apple-interchange-newline"><div><br class="m_6638630188628933489gmail-m_-8869290827680797975Apple-interchange-newline"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div>On Apr 17, 2019, at 13:38, JF Bastien <<a href="mailto:jfbastien@apple.com" target="_blank">jfbastien@apple.com</a>> wrote:</div><br class="m_6638630188628933489gmail-m_-8869290827680797975Apple-interchange-newline"><div><br class="m_6638630188628933489gmail-m_-8869290827680797975Apple-interchange-newline"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div>On Apr 17, 2019, at 10:12 AM, Louis Dionne via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="m_6638630188628933489gmail-m_-8869290827680797975Apple-interchange-newline"><div><div><br><div><br><blockquote type="cite"><div>On Apr 17, 2019, at 12:39, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>> wrote:</div><br class="m_6638630188628933489gmail-m_-8869290827680797975Apple-interchange-newline"><div><div>I'm curious about how people feel this should/could behave with -fno-exceptions. IIRC, Libc++ calls the copy constructor (following the standard), but -fno-exceptions isn't really standard, and from a user perspective that doesn't make sense. `noexcept` is essentially meaningless with -fno-exceptions.<br></div></div></blockquote><div><br></div><div>I personally feel like it would be surprising if -fno-exceptions caused the move constructor to be called instead of the copy constructor. My mental model is that -fno-exceptions only disables exceptions as a language feature, but doesn't really instruct libraries to provide a different API (even though the difference in this case is very small). Instead, I feel like it would make more sense if "everything" was implicitly marked noexcept when -fno-exceptions is used (because that's really the case). The library would behave optimally with -fno-exceptions without having to do anything special.</div></div></div></div></blockquote><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">IIUC what you’re saying: the library should just use the noexcept operator to do its business, and it seem like -fno-exceptions should make noexcept always return true? That would be pretty consistent (more than teaching the library about -fno-exceptions for move / copy).</div></div></blockquote><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">Yes, that's what I mean. I agree with Eric that moving instead of copying provides value, but I think the right way to do it is not to special case libc++, but instead to have all code bases become better under -fno-exceptions by making noexcept do the right thing.</div></div></blockquote><div><br></div><div>Yeah, that makes sense to me too.</div><div><br></div><div>+Richard, I could have sworn you and I chatted quickly about this back in 2016 by my mail-search-fu is failing me. What are your thoughts on having -fno-exceptions affect the value of `noexcept`?</div><br><blockquote type="cite"><div><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><br></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div><div><div><div>Louis</div><br><blockquote type="cite"><div><div><div><br></div><div>Thoughts?</div><div><br><blockquote type="cite"><div>On Apr 16, 2019, at 23:19, Eric Fiselier via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="m_6638630188628933489gmail-m_-8869290827680797975Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 16, 2019 at 2:25 PM Michael Narigon via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">std:vector is using the element copy constructor on existing elements during its resizing operation in reserve(). I would expect it to use the move constructor for efficiency. Is this intended behavior?<br></blockquote><div><br></div><div>Yes, this behavior is mandated by the standard. The copy constructor is used when the move constructor is not noexcept. From cppreference's `std::move_if_noexcept` documentation:<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="m_6638630188628933489gmail-m_-8869290827680797975gmail-t-lc" style="font-size:12.8px;font-family:DejaVuSansMono,"DejaVu Sans Mono",courier,monospace"><a href="https://en.cppreference.com/w/cpp/container/vector/resize" title="cpp/container/vector/resize" style="color:rgb(11,0,128);background-image:none" target="_blank">std::vector::resize</a></span><span style="font-family:DejaVuSans,"DejaVu Sans",arial,sans-serif;font-size:12.8px">, which may have to allocate new storage and then move or copy elements from old storage to new storage.<br></span><span style="font-family:DejaVuSans,"DejaVu Sans",arial,sans-serif;font-size:12.8px">If an exception occurs during this operation, </span><span class="m_6638630188628933489gmail-m_-8869290827680797975gmail-t-lc" style="font-size:12.8px;font-family:DejaVuSansMono,"DejaVu Sans Mono",courier,monospace"><a href="https://en.cppreference.com/w/cpp/container/vector/resize" title="cpp/container/vector/resize" style="color:rgb(11,0,128);background-image:none" target="_blank">std::vector::resize</a></span><span style="font-family:DejaVuSans,"DejaVu Sans",arial,sans-serif;font-size:12.8px"> undoes everything it did to this point, which is only possible if<br></span><code style="font-size:12.8px;font-family:DejaVuSansMono,"DejaVu Sans Mono",courier,monospace">std::move_if_noexcept</code><span style="font-family:DejaVuSans,"DejaVu Sans",arial,sans-serif;font-size:12.8px"> was used to decide whether to use move construction or copy construction. (unless copy constructor is</span> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-family:DejaVuSans,"DejaVu Sans",arial,sans-serif;font-size:12.8px">not available, in which case move constructor is used either way and the strong exception guarantee may be waived)</span> </blockquote><div> <a href="https://en.cppreference.com/w/cpp/utility/move_if_noexcept" target="_blank">https://en.cppreference.com/w/cpp/utility/move_if_noexcept</a></div><div><br></div><div>If you add `noexcept` to your move constructor, vector should call the move constructor.</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>This is with the libc++ delivered with Xcode 10.1.<br><br>Attached is a sample program displaying the behavior.<br>_______________________________________________<br>libcxx-dev mailing list<br><a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><br></blockquote></div></div>_______________________________________________<br>libcxx-dev mailing list<br><a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>_______________________________________________<br>libcxx-dev mailing list<br><a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a></div></blockquote></div></blockquote></div></blockquote></div><br></div>_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><br>
</blockquote></div></div>