public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Josh Marshall <joshua.r.marshall.1991@gmail.com>
To: Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>
Subject: Re: Should reinterpret_cast be constexpr?
Date: Mon, 28 Dec 2020 15:49:50 -0500	[thread overview]
Message-ID: <CAFkJGRepM-v4AjAqQHFBSmtOUux0sr9zHqZeSg-edvE-rJT+AA@mail.gmail.com> (raw)
In-Reply-To: <CAH6eHdRUC-7zWXrVNYcBg5HO8XGfpK_TYerLd3RobV=miAD=Zw@mail.gmail.com>

Is this in master?  If so, I'll just merge it in.

On Mon, Dec 28, 2020 at 3:47 PM Jonathan Wakely <jwakely.gcc@gmail.com>
wrote:

> On Mon, 28 Dec 2020 at 20:33, Jonathan Wakely <jwakely.gcc@gmail.com>
> wrote:
> >
> > On Mon, 28 Dec 2020 at 19:51, Josh Marshall via Libstdc++
> > <libstdc++@gcc.gnu.org> wrote:
> > >
> > > Hello all,
> > >
> > > From the test error `libstdc++-v3/include/bits/stl_vector.h:1837:
> error:
> > > 'reinterpret_cast' is not a constant expression` and the documentation
> at
> > > https://en.cppreference.com/w/cpp/language/reinterpret_cast , is
> > > `reinterpret_cast()` not constexpr in error?
> >
> > No, it's not an error. reinterpret_cast is not allowed in constant
> expressions.
>
> This patch replaces the use of reinterpret_cast with an alternative
> using C++20 features:
>
> diff --git a/libstdc++-v3/include/bits/vector.tcc
> b/libstdc++-v3/include/bits/vector.tcc
> index 27e63388feb..93b2ccc02e3 100644
> --- a/libstdc++-v3/include/bits/vector.tcc
> +++ b/libstdc++-v3/include/bits/vector.tcc
> @@ -516,9 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
>            {
> #if __cplusplus < 201103L
>              value_type __x_copy = __x;
> -#else
> +#elif ! __cpp_lib_make_obj_using_allocator
>              _Temporary_value __tmp(this, __x);
>              value_type& __x_copy = __tmp._M_val();
> +#else
> +             value_type __x_copy = std::make_from_tuple<value_type>(
> +                 std::uses_allocator_construction_args<value_type>(
> +                   _M_get_Tp_allocator(), __x));
> #endif
>              const size_type __elems_after = end() - __position;
>              pointer __old_finish(this->_M_impl._M_finish);
>

  reply	other threads:[~2020-12-28 20:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-28 19:51 Josh Marshall
2020-12-28 20:33 ` Jonathan Wakely
2020-12-28 20:47   ` Jonathan Wakely
2020-12-28 20:49     ` Josh Marshall [this message]
2020-12-28 21:24       ` Jonathan Wakely
     [not found]         ` <CAFkJGRem_HFTtj93pyWVpvMtjSDLBU8u9nUVXshOTovsEjDaHw@mail.gmail.com>
2020-12-29  1:19           ` Josh Marshall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFkJGRepM-v4AjAqQHFBSmtOUux0sr9zHqZeSg-edvE-rJT+AA@mail.gmail.com \
    --to=joshua.r.marshall.1991@gmail.com \
    --cc=jwakely.gcc@gmail.com \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).