From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 5A118384AB7C; Fri, 26 Apr 2024 15:03:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A118384AB7C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714143817; bh=thwjyTBYDchPMPkRjSGDcQJS4Am1NCsRK5c+MKHBlfU=; h=From:To:Subject:Date:From; b=JHmRQ2QB+71XkP4PjnQt8lI6RasAjIVvH9TSpBShLw/voG6x60lLcccGIuDOaAWKH 02DBPsJ0XG2OkFW69sHimZZsHeH8HQhQJ1+f370T0w6nXBxpx9xoZ3tFeJUF2Y3tTs cMUhPuHj7dkybhD1q0sj9RUFOrRtiQ1hPtXzil0U= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r15-5] libstdc++: Do not apply localized formatting to NaN and inf [PR114863] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 7d5479a2ecf6309281de10b747a7423169a2ff95 X-Git-Newrev: a0bc71e480132a528a4869c1cd7863f709768c53 Message-Id: <20240426150337.5A118384AB7C@sourceware.org> Date: Fri, 26 Apr 2024 15:03:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a0bc71e480132a528a4869c1cd7863f709768c53 commit r15-5-ga0bc71e480132a528a4869c1cd7863f709768c53 Author: Jonathan Wakely Date: Fri Apr 26 11:42:26 2024 +0100 libstdc++: Do not apply localized formatting to NaN and inf [PR114863] We don't want to add grouping to strings like "-inf", and there is no radix character to replace either. libstdc++-v3/ChangeLog: PR libstdc++/114863 * include/std/format (__formatter_fp::format): Only use _M_localized for finite values. * testsuite/std/format/functions/format.cc: Check localized formatting of NaN and initiny. Diff: --- libstdc++-v3/include/std/format | 2 +- libstdc++-v3/testsuite/std/format/functions/format.cc | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 22dcb5f24bd..48deba2bcb2 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -1734,7 +1734,7 @@ namespace __format } #endif - if (_M_spec._M_localized) + if (_M_spec._M_localized && __builtin_isfinite(__v)) { __wstr = _M_localize(__str, __expc, __fc.locale()); if (!__wstr.empty()) diff --git a/libstdc++-v3/testsuite/std/format/functions/format.cc b/libstdc++-v3/testsuite/std/format/functions/format.cc index 4499397aaf9..78cc1ab482a 100644 --- a/libstdc++-v3/testsuite/std/format/functions/format.cc +++ b/libstdc++-v3/testsuite/std/format/functions/format.cc @@ -248,6 +248,14 @@ test_locale() s = std::format(cloc, "{:05L}", -1.0); // PR libstdc++/110968 VERIFY( s == "-0001" ); + // PR libstdc++/114863 grouping applied to nan and inf + double inf = std::numeric_limits::infinity(); + s = std::format(eloc, "{0:Le} {0:Lf} {0:Lg}", -inf); + VERIFY( s == "-inf -inf -inf" ); + double nan = std::numeric_limits::quiet_NaN(); + s = std::format(eloc, "{0:Le} {0:Lf} {0:Lg}", -nan); + VERIFY( s == "-nan -nan -nan" ); + // Restore std::locale::global(cloc); }