[v3 PATCH, RFC] Rewrite variant. Also PR libstdc++/85517

Ville Voutilainen ville.voutilainen@gmail.com
Wed Mar 6 09:56:00 GMT 2019


On Wed, 6 Mar 2019 at 11:33, Jonathan Wakely <jwakely@redhat.com> wrote:
> >+      else if constexpr (is_rvalue_reference_v<_Tp&&>)
>
> I know what this is doing, but it still looks a little odd to ask if
> T&& is an rvalue-reference.
>
> Would it be clearer to structure this as:
>
>       if constexpr (is_lvalue_reference_v<_Tp>)
>         {
>           if constexpr (is_const_v<remove_reference_t<_Tp>>)
>             return static_cast<const variant<_Types...>&>(__rhs);
>           else
>             return static_cast<variant<_Types...>&>(__rhs);
>         }
>       else
>         return static_cast<variant<_Types...>&&>(__rhs);
>
> ?
> >+          ::new (std::addressof(__this_mem))
>
> Is there any way that this can find the wrong operator new?
>
> Even if it can't, saying ::new ((void*)std::addressof(__this_mem))
> would avoid having to think about that question again in future.
>
> Therre are a few other new expressions where that applies too (several
> of them already there before your patch).
> >+      ::new (&__storage) remove_reference_t<decltype(__storage)>
>
> This one definitely needs to be cast to void* and needs to use
> addressof (or __addressof), otherwise ...


Sure thing; an incremental diff attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: variant-tweaks.diff
Type: text/x-patch
Size: 2183 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190306/b8fb8607/attachment.bin>


More information about the Libstdc++ mailing list