From patchwork Thu Aug 1 21:32:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1968051 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O1xMjPqP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZj7r5l3yz1yZl for ; Fri, 2 Aug 2024 07:40:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51BDE3858D35 for ; Thu, 1 Aug 2024 21:40:54 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 47C273858CD9 for ; Thu, 1 Aug 2024 21:39:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47C273858CD9 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 47C273858CD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722548382; cv=none; b=ndPYr5GHtW4DQAd2Vp4V1HXp2I9n9Av5PIi3gSMtR4HarxBwVkYxTttAPEZvR94D+VD6ZCYA2XJ+Ucu2UvJHHhX6Wq9xQZUHH68DYY2diT51jC6H9xIfqEcpKyqQtgcVn+qFZr+2/Kb1sanCz/ZOXNhvn3v4BWWY9zbcsp/JC/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722548382; c=relaxed/simple; bh=aigTqyh7KY2t2v41i2b3ZpFX/l08wKmKVgLI9uRX8WY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=N61X3iciW10M9/Q8lU68gZl1Torvvcm5NnEFt5ImBpTmku/c3B0m8/EhfuLRRmcVJV0GCq/EktJmRliGeFlxqGzFQ3lhKC203mCXf5tQnDqrHhMC8IfA8RbIR0DzsaI/VpymjFrBiuYnTKyjcHjnVEPbgwbyG/eBEtMBInxLwsI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722548380; 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=Ax3WGl6vpSUGHhBZGRvRqw8sySqbBFOMuYfK8X1USss=; b=O1xMjPqPKhiLD2vSC/yKniR5NnY4hNcUuSkkECASzM/z21xUKuAzIrrGjNER5em4JJxXIp Tp/5W99bGSF1Qm0gK2WYDdfkut2OYaM73xHTW1c/oMShQjM5H8g/0ddaSgQ8dkFjwIXQp9 MD6F0HqYzJdit1TO6pRa+9cwJH+qjNs= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-Lrddv01FPjySL6ECZxJuoA-1; Thu, 01 Aug 2024 17:39:38 -0400 X-MC-Unique: Lrddv01FPjySL6ECZxJuoA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BBC9F1955D4B; Thu, 1 Aug 2024 21:39:37 +0000 (UTC) Received: from localhost (unknown [10.42.28.21]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BE791955D42; Thu, 1 Aug 2024 21:39:36 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Check ios::uppercase for ios::fixed floating-point output [PR114862] Date: Thu, 1 Aug 2024 22:32:29 +0100 Message-ID: <20240801213927.388966-4-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. -- >8 -- This is LWG 4084 which I filed recently. LWG seems to support making the change, so that std::num_put can use the %F format for floating-point numbers. libstdc++-v3/ChangeLog: PR libstdc++/114862 * src/c++98/locale_facets.cc (__num_base::_S_format_float): Check uppercase flag for fixed format. * testsuite/22_locale/num_put/put/char/lwg4084.cc: New test. --- libstdc++-v3/src/c++98/locale_facets.cc | 13 ++++-- .../22_locale/num_put/put/char/lwg4084.cc | 46 +++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc diff --git a/libstdc++-v3/src/c++98/locale_facets.cc b/libstdc++-v3/src/c++98/locale_facets.cc index fa469b1b872..02f53fd5ec1 100644 --- a/libstdc++-v3/src/c++98/locale_facets.cc +++ b/libstdc++-v3/src/c++98/locale_facets.cc @@ -84,17 +84,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__mod) *__fptr++ = __mod; - // [22.2.2.2.2] Table 58 + // C++11 [facet.num.put.virtuals] Table 88 + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 4084. std::fixed ignores std::uppercase + bool __upper = __flags & ios_base::uppercase; if (__fltfield == ios_base::fixed) - *__fptr++ = 'f'; + *__fptr++ = __upper ? 'F' : 'f'; else if (__fltfield == ios_base::scientific) - *__fptr++ = (__flags & ios_base::uppercase) ? 'E' : 'e'; + *__fptr++ = __upper ? 'E' : 'e'; #if _GLIBCXX_USE_C99_STDIO else if (__fltfield == (ios_base::fixed | ios_base::scientific)) - *__fptr++ = (__flags & ios_base::uppercase) ? 'A' : 'a'; + *__fptr++ = __upper ? 'A' : 'a'; #endif else - *__fptr++ = (__flags & ios_base::uppercase) ? 'G' : 'g'; + *__fptr++ = __upper ? 'G' : 'g'; *__fptr = '\0'; } diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc new file mode 100644 index 00000000000..b7c7da11f86 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/num_put/put/char/lwg4084.cc @@ -0,0 +1,46 @@ +// { dg-do run } +// LWG 4084. std::fixed ignores std::uppercase +// PR libstdc++/114862 std::uppercase not applying to nan's and inf's + +#include +#include +#include +#include + +void +test_nan() +{ + std::ostringstream out; + double nan = std::numeric_limits::quiet_NaN(); + out << std::fixed; + out << ' ' << nan << ' ' << -nan; + out << std::uppercase; + out << ' ' << nan << ' ' << -nan; + out << std::showpoint; + out << ' ' << nan << ' ' << -nan; + out << std::showpos; + out << ' ' << nan << ' ' << -nan; + VERIFY( out.str() == " nan -nan NAN -NAN NAN -NAN +NAN -NAN" ); +} + +void +test_inf() +{ + std::ostringstream out; + double inf = std::numeric_limits::infinity(); + out << std::fixed; + out << ' ' << inf << ' ' << -inf; + out << std::uppercase; + out << ' ' << inf << ' ' << -inf; + out << std::showpoint; + out << ' ' << inf << ' ' << -inf; + out << std::showpos; + out << ' ' << inf << ' ' << -inf; + VERIFY( out.str() == " inf -inf INF -INF INF -INF +INF -INF" ); +} + +int main() +{ + test_nan(); + test_inf(); +}