From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 5F37C38515FE for ; Tue, 20 Apr 2021 11:52:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5F37C38515FE Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-lIqdxuOcOgKE5SP6cWctrQ-1; Tue, 20 Apr 2021 07:52:00 -0400 X-MC-Unique: lIqdxuOcOgKE5SP6cWctrQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13BE0343A2; Tue, 20 Apr 2021 11:52:00 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEC6010016FE; Tue, 20 Apr 2021 11:51:59 +0000 (UTC) Date: Tue, 20 Apr 2021 12:51:58 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Jakub Jelinek Subject: [committed] libstdc++: Define __cpp_lib_to_chars for C++20 [PR 100146] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="wp6Jbi03zwpgbrwy" Content-Disposition: inline X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Apr 2021 11:52:06 -0000 --wp6Jbi03zwpgbrwy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This defines the feature test macro when uselocale is available, because the floating-point std::from_chars support currently depends on that. Co-authored-by: Jakub Jelinek libstdc++-v3/ChangeLog: PR libstdc++/100146 * include/std/charconv (__cpp_lib_to_chars): Define conditionally. * include/std/version (__cpp_lib_to_chars): Likewise.. * testsuite/20_util/from_chars/4.cc: Only check feature test macro, not _GLIBCXX_HAVE_USELOCALE. * testsuite/20_util/from_chars/5.cc: Likewise. * testsuite/20_util/from_chars/6.cc: Likewise. * testsuite/20_util/to_chars/long_double.cc: Likewise. Tested x86_64-linux. Committed to trunk. I'll also backport to gcc-11. --wp6Jbi03zwpgbrwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit f1a68574b1f8d2961d3a676dbcf0cc24b6368578 Author: Jonathan Wakely Date: Tue Apr 20 12:46:11 2021 libstdc++: Define __cpp_lib_to_chars for C++20 [PR 100146] This defines the feature test macro when uselocale is available, because the floating-point std::from_chars support currently depends on that. Co-authored-by: Jakub Jelinek libstdc++-v3/ChangeLog: PR libstdc++/100146 * include/std/charconv (__cpp_lib_to_chars): Define conditionally. * include/std/version (__cpp_lib_to_chars): Likewise.. * testsuite/20_util/from_chars/4.cc: Only check feature test macro, not _GLIBCXX_HAVE_USELOCALE. * testsuite/20_util/from_chars/5.cc: Likewise. * testsuite/20_util/from_chars/6.cc: Likewise. * testsuite/20_util/to_chars/long_double.cc: Likewise. diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 851b1e5cac2..6e407f31e30 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -44,8 +44,9 @@ #include // for std::errc #include -// FIXME: Define when floating point is supported: -// #define __cpp_lib_to_chars 201611L +#if _GLIBCXX_HAVE_USELOCALE +# define __cpp_lib_to_chars 201611L +#endif namespace std _GLIBCXX_VISIBILITY(default) { diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index cb25148fca5..d9f6a3c3dfd 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -161,7 +161,9 @@ #endif #define __cpp_lib_shared_ptr_weak_type 201606 #define __cpp_lib_string_view 201803L -// #define __cpp_lib_to_chars 201611L +#if _GLIBCXX_HAVE_USELOCALE +# define __cpp_lib_to_chars 201611L +#endif #define __cpp_lib_unordered_map_try_emplace 201411 #define __cpp_lib_variant 201606L #endif diff --git a/libstdc++-v3/testsuite/20_util/from_chars/4.cc b/libstdc++-v3/testsuite/20_util/from_chars/4.cc index 1482b5dfb6e..7cee4dcbc23 100644 --- a/libstdc++-v3/testsuite/20_util/from_chars/4.cc +++ b/libstdc++-v3/testsuite/20_util/from_chars/4.cc @@ -28,9 +28,7 @@ // Test std::from_chars floating-point conversions. -// As of July 2020 __cpp_lib_to_chars is not defined, but std::from_chars -// works for floating-point types when _GLIBCXX_HAVE_USELOCALE is defined. -#if __cpp_lib_to_chars >= 201611L || _GLIBCXX_HAVE_USELOCALE +#if __cpp_lib_to_chars >= 201611L void test01() { @@ -363,7 +361,7 @@ test06() int main() { -#if __cpp_lib_to_chars >= 201611L || _GLIBCXX_HAVE_USELOCALE +#if __cpp_lib_to_chars >= 201611L test01(); test02(); test03(); diff --git a/libstdc++-v3/testsuite/20_util/from_chars/5.cc b/libstdc++-v3/testsuite/20_util/from_chars/5.cc index dd5f9229f68..fa86ab7383c 100644 --- a/libstdc++-v3/testsuite/20_util/from_chars/5.cc +++ b/libstdc++-v3/testsuite/20_util/from_chars/5.cc @@ -25,9 +25,7 @@ // Test std::from_chars error handling. -// As of July 2020 __cpp_lib_to_chars is not defined, but std::from_chars -// works for floating-point types when _GLIBCXX_HAVE_USELOCALE is defined. -#if __cpp_lib_to_chars >= 201611L || _GLIBCXX_HAVE_USELOCALE +#if __cpp_lib_to_chars >= 201611L void test01() { @@ -160,7 +158,7 @@ test04() int main() { -#if __cpp_lib_to_chars >= 201611L || _GLIBCXX_HAVE_USELOCALE +#if __cpp_lib_to_chars >= 201611L test01(); test02(); test03(); diff --git a/libstdc++-v3/testsuite/20_util/from_chars/6.cc b/libstdc++-v3/testsuite/20_util/from_chars/6.cc index 58e0f1fc932..139a1811db0 100644 --- a/libstdc++-v3/testsuite/20_util/from_chars/6.cc +++ b/libstdc++-v3/testsuite/20_util/from_chars/6.cc @@ -27,7 +27,7 @@ void test01() { -#if __cpp_lib_to_chars >= 201611L || _GLIBCXX_HAVE_USELOCALE +#if __cpp_lib_to_chars >= 201611L #if _GLIBCXX_USE_C99_FENV_TR1 double d; std::fesetround(FE_DOWNWARD); diff --git a/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc b/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc index 22d42067d65..8cf45ad5e94 100644 --- a/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc +++ b/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc @@ -69,7 +69,7 @@ test01() // Verifies correctness of the hexadecimal form [BEGIN,END) for VALUE by // round-tripping it through from_chars (if available). auto verify_via_from_chars = [] (char *begin, char *end, long double value) { -#if __cpp_lib_to_chars >= 201611L || _GLIBCXX_HAVE_USELOCALE +#if __cpp_lib_to_chars >= 201611L long double roundtrip; auto result = from_chars(begin, end, roundtrip, chars_format::hex); VERIFY( result.ec == errc{} ); --wp6Jbi03zwpgbrwy--