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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0485A384AB6F for ; Fri, 26 Apr 2024 15:04:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0485A384AB6F 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 0485A384AB6F 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=1714143855; cv=none; b=win4ZRgAhEMl9ZK13U3d1ZLBs5q2sHy+RrKjOFgtqYFOCAd+eNM6OxCrAVwg1ABpiID2y+Vlu+05GRfhoka3eEsy/oGArWla4zSC16V0LN+e1UJS3FC+FT+LtABAa4MyGfnFgsAYBthYtKvUR9yMALR2ERTCl7G48KSje4bbJ9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714143855; c=relaxed/simple; bh=0PasAmJtLCFZ6RLtnHkiKXiDdWRzFy6bicmuRXWsPs8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bbFKgEB2uTzdYNo8LD/yig8++h7jJ+z4re3WQZ5zKduWzz1AgG9ALu7HK4eUdh/dnZ6cilg6E0raQ25WSxfa4YRjh/lpZnL6XycaOczjc4D/DlKN9phgnXPWX53u6yNv6KBq/IOpstrGugLQHTc5ommMAoLdPkXI1/tKy22DpX0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714143853; 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=ixduUqYoQ7sTkRzRtkJT6IF/a03pDE0g0g1f4ou/2AW14lxvZFkZeLq8Ib3nXEP6MXNATV pqER3hAsYOwvz88j21gnRlWi2o3xNXXBvAxkwnjBOURX3P+bqiDKa7xhjkDbQBoTCtjTaN KVgrWLY3IUKHunIgZ/5j/gFMTcVPxAA= 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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); } -- 2.44.0