From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id C363338493E6; Tue, 10 Jan 2023 13:03:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C363338493E6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x633.google.com with SMTP id cf18so22064047ejb.5; Tue, 10 Jan 2023 05:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+7G1BYPo9a2tcIG6Ke+TK3IofRIAzbHbLIT+YIX4v98=; b=T8VooSQDsiZWN08CpAsmHN55bfwJB9HD1FEIfLQp1EsOhhdd9brwHLm+XbS4WfENFt onUArLlHLU3AJNBCGD+8tJOmFoklK/e00GkWZKTmA94YjPPEp/zI4z87Q/rUqEe8PvcG K8FaAdztdYrBF+waH2GjWoj6S9Ueo7lRuR+6TSooCKyCwK+VzcsLnddttxnhekG+UJst R/PXM+D75yhoYRUJkZT2agHsbdHs9JRS9yJOLOlwmm9eM4SU7nuDmsE+VIn6/HZSZGGA UjD6e/S0jjqfLoRzzeKTxvfkHNhqFZIk2q9bBtETUbk3AuNtTDv+IhwwAVzcP/zByEI0 CpuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+7G1BYPo9a2tcIG6Ke+TK3IofRIAzbHbLIT+YIX4v98=; b=7P/luhKpksPtAmJvGWxZmvCn9st1YzkzNs1B7ZiDaxGGtViQPO8mXLzoSxzzHnbdgy zeXcbauKNu8kI/V65lIjngTffABLn9xuu1D8gX6vojQv9j4F7YmtDkcVc0Zjw2p5BgGf ntiy2Pj0fr+zK0SqX33eGmeMxxANz+iuIEeSlwpuCS0FOdDvehFHYXvsd3xzUJYAHZUQ uKXKykt9UeJ+bdLS67mIOZaLILb8JcXuYw6kZZABP8HQxtaCW1Ls6feB167LoIHhDTet PWI8V7MfRHsq/HgHSlush8iB4bgW0hNcmfVFAPO0ieyeGkIJdCblUc/2RdeBSrrT8rUN i9LQ== X-Gm-Message-State: AFqh2kpWebZrAa4ChrG3HFWxU7KwoRfzhRoSuSfwC9tEaONBHHW3BQrM pbRVVVD4/DvUARvo/GpDw1/lKxc2wqAlh5h9qH0= X-Google-Smtp-Source: AMrXdXtQFjfUGSAkKTTtb+YkWDUcb9LAnzSfYTWSPC4x+L6ff/5KE2jtcLg3nlv/FUTZmW+Pgp15jYhDQNNm8nKL4/Y= X-Received: by 2002:a17:907:9247:b0:84d:3f40:4bdb with SMTP id kb7-20020a170907924700b0084d3f404bdbmr510143ejb.416.1673355827424; Tue, 10 Jan 2023 05:03:47 -0800 (PST) MIME-Version: 1.0 References: <20230110114657.636853-1-jwakely@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Tue, 10 Jan 2023 13:03:35 +0000 Message-ID: Subject: Re: [committed 1/3] libstdc++: Fix std::span constraint for sizeof(size_t) < sizeof(int) [PR108221] To: Jakub Jelinek Cc: Jonathan Wakely , "libstdc++" , gcc-patches Content-Type: multipart/alternative; boundary="000000000000ad323f05f1e88383" X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: --000000000000ad323f05f1e88383 Content-Type: text/plain; charset="UTF-8" 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 > > --000000000000ad323f05f1e88383--