From patchwork Fri Apr 26 15:03:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 89052 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E31FA3858C50 for ; Fri, 26 Apr 2024 15:06:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 65D123858401 for ; Fri, 26 Apr 2024 15:04:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65D123858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 65D123858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714143854; cv=none; b=bfMzqXiVHxA0NHZiFEHH0qjicILO8CAgjSHVLQpqLTZSn8L5LfE9uD/1ZUwYjYBXRxlaTlSppCkCrBTdcWPM0X2EFB40wSKS8o1iYPnSvKOarSNcQukY7ZCvAea22l/lJ+iJVZJWMEP2QASuEEYn/niwerJfg6tGwAOHk+b/aMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714143854; c=relaxed/simple; bh=0PasAmJtLCFZ6RLtnHkiKXiDdWRzFy6bicmuRXWsPs8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NilvsPYALfhfO735jBnUMd547NPYRDsfPcgVqMaImc3B7jUiQ8AEPYwevyhjO3UneMRQ0uwV6qfpkvN3/QnnBXx5J3Jy5DcIxrDGd10ZgmFsANjLNvM2rIFRRLt9/1e7oyjUFalJa1bMStQYNOgcsxMBB/wrcO9rcx01MlM7h+Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714143849; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aVwTOdOSCjMb7WWxWIXkRo5rWu6e0i4VJbKD3uZ7j5k=; b=XziQ053LEIQ1rxEZbm69yxBFGFQYloSfDaVPjXqzSUwJW6G8/sO04qjj1kXD6d4FNpMx41 VdTt9lW8RfhJVhjGbrRPZTTKFIpwfGNntYb2Js1eeBmX+yUwRrptwOaWzKAcUdxghfD8A0 9bHEAhbfGW/8eXXI4k/5/IXnqOWfgbk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-4vzwVixrOoSgYT7N7-khEw-1; Fri, 26 Apr 2024 11:04:07 -0400 X-MC-Unique: 4vzwVixrOoSgYT7N7-khEw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C610F104B503; Fri, 26 Apr 2024 15:04:06 +0000 (UTC) Received: from localhost (unknown [10.42.28.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9666E1C060D1; Fri, 26 Apr 2024 15:04:06 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Do not apply localized formatting to NaN and inf [PR114863] Date: Fri, 26 Apr 2024 16:03:37 +0100 Message-ID: <20240426150406.2631526-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. I'm going to push this to gcc-13 and gcc-14 too (approved by Jakub on IRC). -- >8 -- 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. --- 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); }