public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: "Jonathan Wakely via Libstdc++" <libstdc++@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: Fix build failure due to missing <langinfo.h> [PR98374]
Date: Fri, 18 Dec 2020 12:16:45 -0500	[thread overview]
Message-ID: <CAMOnLZZMPez2RgsSRnejYs5qF0BcQj2Hs68OUohh0tprBjNrXw@mail.gmail.com> (raw)
In-Reply-To: <20201218160407.1498119-1-ppalka@redhat.com>

On Fri, Dec 18, 2020 at 11:04 AM Patrick Palka <ppalka@redhat.com> wrote:
>
> This fixes a build failure on Windows which lacks <langinfo.h>.
> (We can't use the more portable localeconv() from <clocale> to obtain
> the radix character of the current locale here because it's not
> thread-safe, unfortunately.)
>
> This change means that on Windows and other such systems, we'll just
> always assume the radix character used by printf is '.' when formatting
> a long double through it.
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/98374
>         * src/c++17/floating_to_chars.cc: Guard include of <langinfo.h>
>         with __has_include.
>         (__floating_to_chars_precision) [!defined(RADIXCHAR)]: Don't
>         attempt to obtain the radix character of the current locale,
>         just assume it's '.'.

I went ahead and committed this patch under the "obvious" rule as r11-6259.

> ---
>  libstdc++-v3/src/c++17/floating_to_chars.cc | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc
> index 474e791e717..6470fbb0b95 100644
> --- a/libstdc++-v3/src/c++17/floating_to_chars.cc
> +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
> @@ -33,7 +33,9 @@
>  #include <cmath>
>  #include <cstdio>
>  #include <cstring>
> -#include <langinfo.h>
> +#if __has_include(<langinfo.h>)
> +# include <langinfo.h> // for nl_langinfo
> +#endif
>  #include <optional>
>  #include <string_view>
>  #include <type_traits>
> @@ -1113,6 +1115,7 @@ template<typename T>
>         // to handle a radix point that's different from '.'.
>         char radix[6] = {'.', '\0', '\0', '\0', '\0', '\0'};
>         if (effective_precision > 0)
> +#ifdef RADIXCHAR
>           // ???: Can nl_langinfo() ever return null?
>           if (const char* const radix_ptr = nl_langinfo(RADIXCHAR))
>             {
> @@ -1121,6 +1124,7 @@ template<typename T>
>               // UTF-8 character) wide.
>               __glibcxx_assert(radix[4] == '\0');
>             }
> +#endif
>
>         // Compute straightforward upper bounds on the output length.
>         int output_length_upper_bound;
> --
> 2.30.0.rc0
>


      reply	other threads:[~2020-12-18 17:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-18 16:04 Patrick Palka
2020-12-18 17:16 ` Patrick Palka [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=CAMOnLZZMPez2RgsSRnejYs5qF0BcQj2Hs68OUohh0tprBjNrXw@mail.gmail.com \
    --to=ppalka@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).