public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [committed] libstdc++: Fix constexpr functions in <experimental/internet>
Date: Thu, 30 Mar 2023 15:44:25 +0100	[thread overview]
Message-ID: <CACb0b4=VgYjG+x09woOhwSOVwv=0z9v0us6FQyPB-Vce2p7qbg@mail.gmail.com> (raw)
In-Reply-To: <20230329234000.1405216-1-jwakely@redhat.com>

On Thu, 30 Mar 2023 at 00:40, Jonathan Wakely via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Tested powerpc64le-linux. Pushed to trunk.
>
> -- >8 --
>
> Change ip::basic_endpoint to work in constant expressions, but only for
> C++20 and later (due to the use of a union, which cannot change active
> member in constexpr evaluation until C++20).
>
> During constant evaluation we cannot inspect the common initial sequence
> of basic_endpoint's union members to check whether sin_family == AF_INET
> or AF_INET6.  This means we need to store an additional boolean member
> that remembers whether we have a v4 or v6 address. The address type can
> change behind our backs if a user copies an address to the data()
> pointer and then calls resize(n), so we need to inspect the sa_family_t
> member in the union after a resize and update the boolean. POSIX only
> guarantees that the sa_family_t member of each protocol-specific address
> structure is at the same offset and of the same type, not that there is
> a common initial sequence. The check in resize is done using memcmp, so
> that we avoid accessing an inactive member of the union if the
> sockaddr_in and sockaddr_in6 structures do not have a common initial
> sequence that includes the sa_family_t member.

If we had https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2641r2.html
then we wouldn't need the extra boolean. During constant evaluation we
could use the new magic function to check which union member is
active, and during runtime we could inspect the sa_family_t member
(still using memcmp, because POSIX doesn't guarantee a common initial
sequence, even though I think everybody does give it one in practice).


  reply	other threads:[~2023-03-30 14:44 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 [this message]
2023-03-30 15:59   ` Jonathan Wakely
2023-03-30 16:01     ` Daniel Krügler
2023-03-31 11:06       ` Jonathan Wakely
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=VgYjG+x09woOhwSOVwv=0z9v0us6FQyPB-Vce2p7qbg@mail.gmail.com' \
    --to=jwakely@redhat.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).