public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] libstdc++: Fix long double to_chars testcase [PR98384]
Date: Thu,  7 Jan 2021 10:37:59 -0500	[thread overview]
Message-ID: <20210107153759.1939075-1-ppalka@redhat.com> (raw)

The testcase was failing to compile on some targets due to its use of
the non-standard functions nextupl and nextdownl.  This patch makes the
testcase instead use the C99 function nexttowardl in an equivalent
manner.

libstdc++-v3/ChangeLog:

	PR libstdc++/98384
	* testsuite/20_util/to_chars/long_double.cc: Use nexttowardl
	instead of the non-standard nextupl and nextdownl.
---
 .../testsuite/20_util/to_chars/long_double.cc | 25 +++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)

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 9d9ede7cf8a..4f72cb65400 100644
--- a/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc
+++ b/libstdc++-v3/testsuite/20_util/to_chars/long_double.cc
@@ -32,6 +32,17 @@
 
 using namespace std;
 
+namespace detail
+{
+  long double
+  nextupl(long double x)
+  { return nexttowardl(x, numeric_limits<long double>::infinity()); }
+
+  long double
+  nextdownl(long double x)
+  { return nexttowardl(x, -numeric_limits<long double>::infinity()); }
+}
+
 // The long double overloads of std::to_chars currently just go through printf
 // (except for the hexadecimal formatting).
 
@@ -40,8 +51,8 @@ void
 test01()
 {
   const long double hex_testcases[]
-    = { nextdownl(numeric_limits<long double>::max()),
-	nextupl(numeric_limits<long double>::min()),
+    = { detail::nextdownl(numeric_limits<long double>::max()),
+	detail::nextupl(numeric_limits<long double>::min()),
 	42.0L,
 	0x1.2p+0L,
 	0x1.23p+0L,
@@ -94,7 +105,7 @@ test01()
 
 	  {
 	    // Verify that the nearby values have a different shortest form.
-	    testcase = nextdownl(testcase);
+	    testcase = detail::nextdownl(testcase);
 	    result = to_chars(begin(to_chars_buffer), end(to_chars_buffer),
 			      testcase, chars_format::hex);
 	    VERIFY( result.ec == errc{} );
@@ -103,7 +114,7 @@ test01()
 	    sprintf(printf_buffer, "%La", testcase);
 	    VERIFY( !strcmp(to_chars_buffer, printf_buffer+strlen("0x")) );
 
-	    testcase = nextupl(nextupl(testcase));
+	    testcase = detail::nextupl(detail::nextupl(testcase));
 	    result = to_chars(begin(to_chars_buffer), end(to_chars_buffer),
 			      testcase, chars_format::hex);
 	    VERIFY( result.ec == errc{} );
@@ -112,7 +123,7 @@ test01()
 	    sprintf(printf_buffer, "%La", testcase);
 	    VERIFY( !strcmp(to_chars_buffer, printf_buffer+strlen("0x")) );
 
-	    testcase = nextdownl(testcase);
+	    testcase = detail::nextdownl(testcase);
 	  }
 
 	for (int precision = -1; precision < 50; precision++)
@@ -173,7 +184,7 @@ test02()
 	  *result.ptr = '\0';
 	  char nearby_buffer[50000];
 	    {
-	      const long double smaller = nextdownl(value);
+	      const long double smaller = detail::nextdownl(value);
 	      result = to_chars(begin(nearby_buffer), end(nearby_buffer),
 				smaller, fmt);
 	      VERIFY( result.ec == errc{} );
@@ -182,7 +193,7 @@ test02()
 	    }
 
 	    {
-	      long double larger = nextupl(value);
+	      long double larger = detail::nextupl(value);
 	      result = to_chars(begin(nearby_buffer), end(nearby_buffer),
 				larger, fmt);
 	      VERIFY( result.ec == errc{} );
-- 
2.30.0


             reply	other threads:[~2021-01-07 15:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07 15:37 Patrick Palka [this message]
2021-01-07 17:35 ` 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=20210107153759.1939075-1-ppalka@redhat.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).