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++ <libstd...@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 via email to