[committed,1/3] libstdc++: Fix std::span constraint for sizeof(size_t) < sizeof(int) [PR108221]
Message ID | 20230110114657.636853-1-jwakely@redhat.com |
---|---|
State | Repeat Merge |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2698430wrt; Tue, 10 Jan 2023 03:50:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXvboy3xYiCrMexlvTTgOgLRgdRqK7z8/sEYatwiQD3/Moy9+gsJW9jL4aZj0VGr7dVdGSsU X-Received: by 2002:a17:906:8e91:b0:7c1:5248:4f3a with SMTP id ru17-20020a1709068e9100b007c152484f3amr54094879ejc.56.1673351406341; Tue, 10 Jan 2023 03:50:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673351406; cv=none; d=google.com; s=arc-20160816; b=mIO+0ePiXVNlZ5semWwl/SOj5t32wu6+V5lYdAGuYMIt2uBrVZmy9gtf1A+nkE5gDA DsPnkhn/HVqOu2XCr0+A5GuV7HoDzRrgwp2Kf4lJ/QYnz4hefKW1j99uTfhwFqy/gDxJ mle4psJ+97YSMMDVLDf7+9yFgds3rpUongmHKzR5MKI7j5h5ZWnJiD7EtZ1DUslpx7eP p+ebnGEHyAF7e3HQKKKG1CFoVBZW+itYZzh1OJF5T8D1nYbl/0OsLDvfPdfD4HCPRcDW w6Ay52feLrdbDmITrXsFjTMYJnA9Eaw+71GB41YnPINfjHLz/8oMpdqlKLgVGMKA1sa7 MmEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ljGqe42JxiPvjAYxxyM3xzdk1M9v2YSPTpKA2IvtjPk=; b=Kj9hB/6e7rKkP77MHhu87wrBwwWpBzoafgPVVVq08Z3w9rXwDLTwDtJemUyg8OQ7AP Ops31k1JkZEwkKJsNXHviM24h7/9z+XUI4/WKlQuH+rdi7i/JXFmjeVOpRrzkab/cA94 OSyhlX4IxcoGH2gONADaZUjLSFyAEZXdggnLl2bu+LdzSGVFiMo77VQY+jazuStzJ807 Iw5lFqfrtiLoMxBvoJ6Q/fCyWc0XmmhGd/7/yM9QKVKcg9+bw9HF7ZySQkjOiqy3aZ8q MWHYynHpJ7Sf3uosVOPe9RACGHNmr+EaW4GAWztMthR4h23lmXY2oeTLmPvM9q5WZvaQ cAqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MngeKtPg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xa14-20020a170906fd8e00b00787b9cd2fe3si11020558ejb.844.2023.01.10.03.50.06 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 03:50:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MngeKtPg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 21B29385B50B for <ouuuleilei@gmail.com>; Tue, 10 Jan 2023 11:49:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21B29385B50B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673351367; bh=ljGqe42JxiPvjAYxxyM3xzdk1M9v2YSPTpKA2IvtjPk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MngeKtPgbwdhHxa4MKocyZ/LV538xnoWItVGRk+KWLJdwB6wlPrOW/E5XFlZVBgy1 cRg/vJy3B+OKOO3aZEhbVeAJ+/F0IaP/RkTbXy0S+GYaj0AOgWDmEwwULUfUH7VyqI TsG9J1Qa9hmzPzZt+05jdSzyHgEx3PTO/6eKNufI= 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 AAA833858281 for <gcc-patches@gcc.gnu.org>; Tue, 10 Jan 2023 11:47:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AAA833858281 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-149-_IIYwdI4MumDYQiPD9yMew-1; Tue, 10 Jan 2023 06:46:58 -0500 X-MC-Unique: _IIYwdI4MumDYQiPD9yMew-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 129E829DD989; Tue, 10 Jan 2023 11:46:58 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB5322166B26; Tue, 10 Jan 2023 11:46:57 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 1/3] libstdc++: Fix std::span constraint for sizeof(size_t) < sizeof(int) [PR108221] Date: Tue, 10 Jan 2023 11:46:55 +0000 Message-Id: <20230110114657.636853-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jonathan Wakely <jwakely@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754636124221833726?= X-GMAIL-MSGID: =?utf-8?q?1754636124221833726?= |
Series |
[committed,1/3] libstdc++: Fix std::span constraint for sizeof(size_t) < sizeof(int) [PR108221]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jonathan Wakely
Jan. 10, 2023, 11:46 a.m. UTC
Tested x86_64-linux. Pushed to trunk. -- >8 -- The default constructor has a constraint that is always false if arithmetic on size_t values promotes to int. Rewrite the constraint exactly as written in the standard, which works correctly. libstdc++-v3/ChangeLog: PR libstdc++/108221 * include/std/span (span::span()): Un-simplify constraint to work for size_t of lesser rank than int. --- libstdc++-v3/include/std/span | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Tue, Jan 10, 2023 at 11:46:55AM +0000, Jonathan Wakely via Gcc-patches wrote: > Tested x86_64-linux. Pushed to trunk. > > -- >8 -- > > The default constructor has a constraint that is always false if > arithmetic on size_t values promotes to int. Rewrite the constraint > exactly as written in the standard, which works correctly. > > libstdc++-v3/ChangeLog: > > PR libstdc++/108221 > * include/std/span (span::span()): Un-simplify constraint to > work for size_t of lesser rank than int. > --- > libstdc++-v3/include/std/span | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span > index 251fed91abf..b336332b190 100644 > --- a/libstdc++-v3/include/std/span > +++ b/libstdc++-v3/include/std/span > @@ -145,7 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > constexpr > span() noexcept > - requires ((_Extent + 1u) <= 1u) > + requires (_Extent == dynamic_extent || _Extent == 0) > : _M_ptr(nullptr), _M_extent(0) > { } If it would be C++23 only, you could use ((_Extent + 1uz) <= 1uz). As this is evaluated at compile time only, it is unfortunate it is 3 operations compared to former 2, but not a big deal. If this was in code that would be emitted at runtime, GCC already optimizes (x == -1uz || x == 0) or (x == 0 || x == -1uz) to ((x + 1uz) <= 1uz) Jakub
On Tue, 10 Jan 2023, 12:26 Jakub Jelinek via Libstdc++, < libstdc++@gcc.gnu.org> wrote: > On Tue, Jan 10, 2023 at 11:46:55AM +0000, Jonathan Wakely via Gcc-patches > wrote: > > Tested x86_64-linux. Pushed to trunk. > > > > -- >8 -- > > > > The default constructor has a constraint that is always false if > > arithmetic on size_t values promotes to int. Rewrite the constraint > > exactly as written in the standard, which works correctly. > > > > libstdc++-v3/ChangeLog: > > > > PR libstdc++/108221 > > * include/std/span (span::span()): Un-simplify constraint to > > work for size_t of lesser rank than int. > > --- > > libstdc++-v3/include/std/span | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/libstdc++-v3/include/std/span > b/libstdc++-v3/include/std/span > > index 251fed91abf..b336332b190 100644 > > --- a/libstdc++-v3/include/std/span > > +++ b/libstdc++-v3/include/std/span > > @@ -145,7 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > > > constexpr > > span() noexcept > > - requires ((_Extent + 1u) <= 1u) > > + requires (_Extent == dynamic_extent || _Extent == 0) > > : _M_ptr(nullptr), _M_extent(0) > > { } > > If it would be C++23 only, you could use ((_Extent + 1uz) <= 1uz). > That would still promote _Extent and 1uz to int before the addition, and so would not wrap to zero when _Extent == -1uz size_t(_Extent + 1) <= 1 would work, but I'm just going to KISS and do what the standard says. As this is evaluated at compile time only, it is unfortunate it is > 3 operations compared to former 2, but not a big deal. If this was > in code that would be emitted at runtime, GCC already optimizes > (x == -1uz || x == 0) > or > (x == 0 || x == -1uz) > to > ((x + 1uz) <= 1uz) > > Jakub > >
diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index 251fed91abf..b336332b190 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -145,7 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr span() noexcept - requires ((_Extent + 1u) <= 1u) + requires (_Extent == dynamic_extent || _Extent == 0) : _M_ptr(nullptr), _M_extent(0) { }