[libcxx-dev] Sequence container swap noexcept specifiers not-to-spec

Louis Dionne via libcxx-dev libcxx-dev at lists.llvm.org
Thu Mar 4 09:47:03 PST 2021


Thanks for disentangling this, Tim. For some reason, I constantly forget about the Lakos rule.

I actually think we’d be better off strengthening the `noexcept` to make it unconditional. It’s simpler that way and it’s a conforming extension.

Louis

> On Mar 4, 2021, at 12:43, Christopher Di Bella <cjdb.ns at gmail.com> wrote:
> 
> Yeah, I'm fine with that.
> 
> Louis, I can add a comment explaining this instead of a technical patch. WDYT? 
> 
> On Thu, 4 Mar 2021, 09:41 Tim Song, <t.canens.cpp at gmail.com <mailto:t.canens.cpp at gmail.com>> wrote:
> My interpretation is
> 
> - the _LIBCPP_STD_VER >= 14 unconditional noexcept is a permissible
> strengthening relative to the standard's requirement. The conditional
> noexcept in the standard is a Lakos rule relic because of the UB in
> https://timsong-cpp.github.io/cppwp/container.requirements.general#9.sentence-4 <https://timsong-cpp.github.io/cppwp/container.requirements.general#9.sentence-4>.
> - the _LIBCPP_STD_VER < 14 conditional noexcept is an attempt to
> support allocators that throw when swapped. Those allocators were
> banned by LWG2016.
> 
> So everything is OK as is, but there may be a case for treating
> LWG2016 as a DR and making this function unconditionally noexcept
> across all standard versions.
> 
> On Thu, Mar 4, 2021 at 11:24 AM Christopher Di Bella <cjdb.ns at gmail.com <mailto:cjdb.ns at gmail.com>> wrote:
> >
> > Ah, I was looking for a big "Resolved" status and missed that.
> >
> > So IIUC you're saying the conditional noexcept specifier is a relic required by the Lakos rule, but is always true thanks to LWG2016, and an allocator that throws in its swap in libc++ calls std::terminate, which is our resolution to UB, and so everything is already A-OK.
> >
> > On Thu, 4 Mar 2021, 09:16 Tim Song, <t.canens.cpp at gmail.com <mailto:t.canens.cpp at gmail.com>> wrote:
> >>
> >> On Thu, Mar 4, 2021 at 11:14 AM Christopher Di Bella <cjdb.ns at gmail.com <mailto:cjdb.ns at gmail.com>> wrote:
> >> >
> >> >
> >> >
> >> > On Thu, 4 Mar 2021, 09:03 Tim Song, <t.canens.cpp at gmail.com <mailto:t.canens.cpp at gmail.com>> wrote:
> >> >>
> >> >> I don't think this is an oversight. The conditional noexcept on swap
> >> >> in the standard is entirely due to the Lakos rule (swapping containers
> >> >> with non-propagating unequal allocators is undefined), so the
> >> >> unconditional noexcept is a permissible strengthening. The
> >> >> __is_nothrow_swappable check pre-17 is presumably to support
> >> >> allocators with throwing swaps, which were banned by LWG2016.
> >> >>
> >> >> If a change is desirable, I would suggest treating LWG2016 as a DR and
> >> >> using unconditional noexcept across the board.
> >> >
> >> >
> >> > I see LWG2016 is P2 and hasn't been looked at since 2017. What would be necessary to get LWG to review this again?
> >> >
> >>
> >> It's in C++17 already?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20210304/64b4ee27/attachment-0001.html>


More information about the libcxx-dev mailing list