public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "Daniel Krügler" <daniel.kruegler@gmail.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [committed] libstdc++: Fix constexpr functions in <experimental/internet>
Date: Fri, 31 Mar 2023 12:06:18 +0100	[thread overview]
Message-ID: <CACb0b4=yBjCQCaxfHjFJuNcfjnupSR_ZDg5+qQaduADUw-GUKA@mail.gmail.com> (raw)
In-Reply-To: <CAGNvRgAfQK+9CmZnwY9iN74ndSHe1btYc1k1wakfL3V0AFFirw@mail.gmail.com>

On Thu, 30 Mar 2023 at 17:01, Daniel Krügler wrote:
>
> Am Do., 30. März 2023 um 18:00 Uhr schrieb Jonathan Wakely via
> Libstdc++ <libstdc++@gcc.gnu.org>:
> >
> [..]
> >
> > In fact, thinking about P2641 some more, I might revert this change.
> > Instead of adding an extra bool member to support constexpr, I think
> > I'll just remove the 'constexpr' keywords from basic_endpoint for now,
> > and implement it in terms of just inspecting the sa_family_t member of
> > the union members. And then later, once we have something like P2641,
> > we can re-add the constexpr keywords and use is_within_lifetime during
> > constant evaluation. That way we don't add a bool then need to take it
> > away again, changing the ABI each time.
>
> I was just going to make the same suggestion.

Actually, as pointed out in Barry's P2641R1 paper, we can just use
GCC's __builtin_constant_p:

+      constexpr bool
+      _M_is_v6() const noexcept
+      {
+       // For constexpr eval we can just detect which union member is active.
+       // i.e. emulate P2641R1's std::is_active_member(&_M_data._M_v6)).
+       if (std::__is_constant_evaluated())
+         return __builtin_constant_p(_M_data._M_v6.sin6_family);
+       return _M_data._M_v6.sin6_family == AF_INET6;
+      }


  reply	other threads:[~2023-03-31 11:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29 23:40 Jonathan Wakely
2023-03-30 14:44 ` Jonathan Wakely
2023-03-30 15:59   ` Jonathan Wakely
2023-03-30 16:01     ` Daniel Krügler
2023-03-31 11:06       ` Jonathan Wakely [this message]
2023-03-31 14:49         ` Jonathan Wakely

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='CACb0b4=yBjCQCaxfHjFJuNcfjnupSR_ZDg5+qQaduADUw-GUKA@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=daniel.kruegler@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).