public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Redefine __from_chars_alnum_to_val's table
Date: Thu, 20 Oct 2022 13:01:05 +0100	[thread overview]
Message-ID: <CACb0b4mXWiZPK=RdTn=ManD17mkqVt4eTZcBvRQC8ztRSXL=yQ@mail.gmail.com> (raw)
In-Reply-To: <20221017162632.1085359-1-ppalka@redhat.com>

On Mon, 17 Oct 2022 at 17:27, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> It looks like the constexpr <charconv> commit r13-3313-g378a0f1840e694
> caused some modules regressions:
>
>   FAIL: g++.dg/modules/xtreme-header-4_b.C -std=c++2b (test for excess errors)
>   FAIL: g++.dg/modules/xtreme-header_b.C -std=c++2b (test for excess errors)
>
> Like PR105297, the problem seems to be the local class from
> __from_chars_alnum_to_val ending up as the type of a namespace-scope
> entity (the variable template __detail::__table in this case).
>
> This patch works around this modules issue by using an ordinary class
> instead of a local class.  Also, I suppose we might as well use a static
> data member to define the table once for all dialects instead of having
> to define it twice in C++23 mode, once as a static local variable (which
> isn't usable during constexpr evaluation) and again as a variable template
> (which is).
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?  Diff
> generated with -w to ignore noisy whitespace changes.

OK, thanks.


>
> libstdc++-v3/ChangeLog:
>
>         * include/std/charconv (__detail::__from_chars_alnum_to_val_table):
>         Redefine as a class template containing type, value and _S_table
>         members.  Don't use a local class as the table type.
>         (__detail::__table): Remove.
>         (__detail::__from_chars_alnum_to_val): Adjust after the above.
> ---
>  libstdc++-v3/include/std/charconv | 31 ++++++++++++++-----------------
>  1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv
> index 7aefdd3298c..c157d4c74ab 100644
> --- a/libstdc++-v3/include/std/charconv
> +++ b/libstdc++-v3/include/std/charconv
> @@ -413,14 +413,19 @@ namespace __detail
>        return true;
>      }
>
> +  template<bool _DecOnly>
> +    struct __from_chars_alnum_to_val_table
> +    {
> +      struct type { unsigned char __data[1u << __CHAR_BIT__] = {}; };
> +
>        // Construct and return a lookup table that maps 0-9, A-Z and a-z to their
>        // corresponding base-36 value and maps all other characters to 127.
> -  constexpr auto
> -  __from_chars_alnum_to_val_table()
> +      static constexpr type
> +      _S_table()
>        {
>         constexpr unsigned char __lower_letters[27] = "abcdefghijklmnopqrstuvwxyz";
>         constexpr unsigned char __upper_letters[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> -    struct { unsigned char __data[1u << __CHAR_BIT__] = {}; } __table;
> +       type __table;
>         for (auto& __entry : __table.__data)
>           __entry = 127;
>         for (int __i = 0; __i < 10; ++__i)
> @@ -433,10 +438,11 @@ namespace __detail
>         return __table;
>        }
>
> -#if __cpp_lib_constexpr_charconv
> -  template<bool _DecOnly>
> -    inline constexpr auto __table = __from_chars_alnum_to_val_table();
> -#endif
> +      // This initializer is made superficially dependent in order
> +      // to prevent the compiler from wastefully constructing the
> +      // table ahead of time when it's not needed.
> +      static constexpr type value = (_DecOnly, _S_table());
> +    };
>
>    // If _DecOnly is true: if the character is a decimal digit, then
>    // return its corresponding base-10 value, otherwise return a value >= 127.
> @@ -449,16 +455,7 @@ namespace __detail
>        if _GLIBCXX17_CONSTEXPR (_DecOnly)
>         return static_cast<unsigned char>(__c - '0');
>        else
> -       {
> -#if __cpp_lib_constexpr_charconv
> -         if (std::__is_constant_evaluated())
> -           return __table<_DecOnly>.__data[__c];
> -#endif
> -         // This initializer is deliberately made dependent in order to work
> -         // around modules bug PR105322.
> -         static constexpr auto __table = (_DecOnly, __from_chars_alnum_to_val_table());
> -         return __table.__data[__c];
> -       }
> +       return __from_chars_alnum_to_val_table<_DecOnly>::value.__data[__c];
>      }
>
>    /// std::from_chars implementation for integers in a power-of-two base.
> --
> 2.38.0.68.ge85701b4af
>


      reply	other threads:[~2022-10-20 12:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 16:26 Patrick Palka
2022-10-20 12:01 ` Jonathan Wakely [this message]

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='CACb0b4mXWiZPK=RdTn=ManD17mkqVt4eTZcBvRQC8ztRSXL=yQ@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /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).