[libcxx-commits] [PATCH] D81954: Remove the try/catch codepath if `swap` is `noexcept`.

Michael Park via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 16 12:05:21 PDT 2020

mpark marked 2 inline comments as done.
mpark added inline comments.

Comment at: libcxx/include/variant:1046
   void __swap(__impl& __that)  {
     if (this->valueless_by_exception() && __that.valueless_by_exception()) {
mclow.lists wrote:
> ldionne wrote:
> > zoecarver wrote:
> > > I think it would be good to also mark this `noexcept(__all<(is_nothrow_move_constructible_v<_Types> && is_nothrow_swappable_v<_Types>)...>::value)`.
> > Yeah, I was going to suggest the same thing. If it makes sense. If not, why?
> You pretty much have to do that, otherwise you get the try/catch/terminate block in the caller
I would actually prefer to not mark this `noexcept`, because trying to propagate `noexcept` down doesn't really scale.
As in, if we mark this with the `noexcept` condition, we'd also, with the same principle, mark `__generic_construct`,
`__visit_alt_at`, and essentially propagate it down to all of the helper functions like `__assign`, etc.

Comment at: libcxx/include/variant:1072
+      if constexpr (is_noexcept) {
         this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
zoecarver wrote:
> I think this is OK but, are there any compilers that we support that don't support `if constexpr` in C++17?
Not that I know of...

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list