From patchwork Tue Dec 6 21:40:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 61614 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 89822380FAC4 for ; Tue, 6 Dec 2022 21:41:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89822380FAC4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670362899; bh=uKjiKtl+JKG67kidzAi0QYfkCsyPXC+sOJWUmOOFQ7M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=TXs+D9lXZZyJokkq/UttQn/OKeEmb9uZiHWpTkKBIvbJJ1mTSaqUER60KN6zapMtB WNfvNu1Ydx3YkqkW3hjvFYOymIj7yH+NVkslt8oNk6NtlaFfWZTQikL0mhRS0cuPO4 XV9aDzwBCCQZH7Xn5AskcHyZNr85f7lq3mvjzqco= 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 ESMTPS id BBA333894C3A for ; Tue, 6 Dec 2022 21:40:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BBA333894C3A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-414-BruLtsEpPK-mKQ_td7iF0g-1; Tue, 06 Dec 2022 16:40:57 -0500 X-MC-Unique: BruLtsEpPK-mKQ_td7iF0g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F17A0101A528; Tue, 6 Dec 2022 21:40:56 +0000 (UTC) Received: from localhost (unknown [10.33.36.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAE8A1121314; Tue, 6 Dec 2022 21:40:56 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add casts for integer-like difference type [PR107871] Date: Tue, 6 Dec 2022 21:40:54 +0000 Message-Id: <20221206214054.239631-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-linux. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: PR libstdc++/107871 * include/std/format (_Iter_sink::_M_overflow): Add cast to size_t. (_Iter_sink::_M_make_span): Use typedef instead of decltype. * testsuite/std/format/functions/107871.cc: New test. --- libstdc++-v3/include/std/format | 8 ++++---- .../testsuite/std/format/functions/107871.cc | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/std/format/functions/107871.cc diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 6d6a770eb8c..1072e2c17db 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -2481,12 +2481,12 @@ namespace __format auto __s = this->_M_used(); if (_M_max < 0) // No maximum. _M_out = ranges::copy(__s, std::move(_M_out)).out; - else if (_M_count < size_t(_M_max)) + else if (_M_count < static_cast(_M_max)) { auto __max = _M_max - _M_count; span<_CharT> __first; if (__max < __s.size()) - __first = __s.first(__max); + __first = __s.first(static_cast(__max)); else __first = __s; _M_out = ranges::copy(__first, std::move(_M_out)).out; @@ -2564,11 +2564,11 @@ namespace __format if (__n > 0) { - if constexpr (!is_integral_v + if constexpr (!is_integral_v> || sizeof(__n) > sizeof(size_t)) { // __int128 or __detail::__max_diff_type - auto __m = (decltype(__n))(size_t)-1; + auto __m = iter_difference_t<_OutIter>((size_t)-1); if (__n > __m) __n = __m; } diff --git a/libstdc++-v3/testsuite/std/format/functions/107871.cc b/libstdc++-v3/testsuite/std/format/functions/107871.cc new file mode 100644 index 00000000000..1fb558e7ac6 --- /dev/null +++ b/libstdc++-v3/testsuite/std/format/functions/107871.cc @@ -0,0 +1,14 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +struct O { + using difference_type = std::ranges::__detail::__max_diff_type; + O& operator=(const char&); + O& operator*(); + O& operator++(); + O& operator++(int); +}; + +auto str = std::format_to_n(O{}, 4, "{}", " "); // PR libstdc++/107871