From patchwork Fri Sep 9 17:24:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1121 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp816690wrt; Fri, 9 Sep 2022 10:26:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR6VRg6fH/zMcEI2RUm6DEFktJ4xUYqM09ZOqvNaPwUcHUbaT7u1VaJDhzmRYbGLLJuoIx3Y X-Received: by 2002:a17:907:80d:b0:73d:a576:dfbd with SMTP id wv13-20020a170907080d00b0073da576dfbdmr10677320ejb.402.1662744406919; Fri, 09 Sep 2022 10:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662744406; cv=none; d=google.com; s=arc-20160816; b=Wyarq2HTGBrtiyZHYjtosek5+Kn14yTJqtaxEP/ze8DWKAZ6GGph/TawgVK9OukyVc sN67FfKMEsyng9mFRusZF3+X9nmDoMN9+ShDnRtJc32bzK9kSgra7TYPz2Hpdht/DicW +eiPmkHPBI3fVcLUDVPCThQhrpfdU9TmRPWJzQgARmM3UPfR89AcxIgj5yD4lmG8jEdV 9xTANWn/TQwWsuRnwKz13VDM2rgTHbpZuI8lt67I9pFy/N7vycWNDzVgyEbMgQAUNPLQ qrgiSgS4W7Ihcrh9quo9agUAikEDTnCuuHNuC1YqbJzgo5Om8OJez/7mI64bRDdK2pPa Y4mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=urz4iCWtcS1MvyORO2fnTc+0ZDGthQbhL/ZSGU3w3uk=; b=R/VzPMf8WiU7k8ELHngJ+/5YCzKGTMoPROh6R425RWB/Lk+OiwdHYgMjmwiUsz5Fn0 QTrAxpOER96vQyj9f9WpxpSUx3VpWciyKCJ8FwiXc0ZxBiKLDh5oAI6C9YCmH4hBnO5X seRGt7zmUz/mhPIwJqhWBhOGCjq8sqFdh+h72Ptir2G1Pze7xSJvjz5fz7470qdMHSbJ Z+/M96SKwacG13H3VThCI7yv8XDvKUJtG5rltNw7mDnBOkl9SGjTqIOR3IZf3XG/uogA RlnmYm871n7HFpEoQewO8cldvSxaVizUWG57cy7wNMiBieViWHyprcGpgoRifBXGL14Y UYIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ycIsXnx5; 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 hf15-20020a1709072c4f00b00738346168dcsi924294ejc.811.2022.09.09.10.26.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 10:26:46 -0700 (PDT) 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=ycIsXnx5; 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 7D0A838515DF for ; Fri, 9 Sep 2022 17:26:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D0A838515DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662744375; bh=urz4iCWtcS1MvyORO2fnTc+0ZDGthQbhL/ZSGU3w3uk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ycIsXnx589fO1GktwXk9gWsRt/zxmUl9ZgYLetaHL/VNMR0v0xkgYtACcc2MwVBFn jv+jk9G34LGfwdKg3irQSnK2L2YbEQESsjd3x8XSF80T7jyfCQLo8iul0VmRhBdk7u n4DIrEmGcvGVWTQQPZPImrGZ+LCI1VEwW5rHbtvQ= 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 C2FEF3858435 for ; Fri, 9 Sep 2022 17:24:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2FEF3858435 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-641-rl6SGOFxNyeqO74A388Tww-1; Fri, 09 Sep 2022 13:24:49 -0400 X-MC-Unique: rl6SGOFxNyeqO74A388Tww-1 Received: by mail-qv1-f70.google.com with SMTP id n15-20020ad444af000000b004a2a341ad71so1668453qvt.15 for ; Fri, 09 Sep 2022 10:24:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=urz4iCWtcS1MvyORO2fnTc+0ZDGthQbhL/ZSGU3w3uk=; b=qgdl5zgXyZNaCCDA8SgLDNvr9z8lO6/Jxy7SUDVjexpVg5lj1xhRXEXKqb5THLtgHa K0itSl34+IfMY/o0MPM0VfmhEtf9zu9sfy2nYsMPFOWllRCLeA5DlEyoWg2BtLKm8xGX 42oT2rQ18zYvk1jBIWMJEnVFijgB3xGzKnWYRh9WbNaTGhQqaGDkot6C/eR3VSL5NJx6 hN8jX3LYkBgWae6n1l1OTUVAkjfa3KUCpb36jgQ8zvyjcazCVzURfp7nOcU6cfHlC88e SykP+rbivbyxfx6Osw+qlB0gD14DVq8xrjTHkMJH7KQQ2uaEoG6J9MxeYAfcMK+rsg8q HfEA== X-Gm-Message-State: ACgBeo1NMBOeUGG/GzzB0Ac8x307bX7rvwv4Bq6kJZ/QlCBTOaMIwNC8 tEqu3cHe6w0Aw0+00N0cEkY6LdPXO1stsMHpfTrPY+kTT4x5C5gN76KmIbJP5T5WidrCB1LvUq2 nBC1yoNgCkZAJXqBQ8cH4KORNw6B2vb4JEyU4igcVUms6hcGUsq2NYB0EGsw6Ld9YltQ= X-Received: by 2002:ac8:7fc4:0:b0:344:5b83:de4c with SMTP id b4-20020ac87fc4000000b003445b83de4cmr13361591qtk.671.1662744289048; Fri, 09 Sep 2022 10:24:49 -0700 (PDT) X-Received: by 2002:ac8:7fc4:0:b0:344:5b83:de4c with SMTP id b4-20020ac87fc4000000b003445b83de4cmr13361566qtk.671.1662744288703; Fri, 09 Sep 2022 10:24:48 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f5-20020a05622a1a0500b003445bb107basm820250qtb.75.2022.09.09.10.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 10:24:48 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] libstdc++: Fix zip_view's operator- for integer-class difference type [PR106766] Date: Fri, 9 Sep 2022 13:24:44 -0400 Message-Id: <20220909172446.1546805-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.3.518.g79f2338b37 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743513878972966971?= X-GMAIL-MSGID: =?utf-8?q?1743513878972966971?= make_unsigned_t can't give us the unsigned version of an integer-class difference type, so use __make_unsigned_like_t / __to_unsigned_like instead. PR libstdc++/106766 libstdc++-v3/ChangeLog: * include/std/ranges (zip_view::_Iterator::operator-): Use __to_unsigned_like instead of make_unsigned_t. (zip_view::_Sentinel::operator-): Likewise. * testsuite/std/ranges/zip/1.cc (test04): New test. --- libstdc++-v3/include/std/ranges | 8 ++++---- libstdc++-v3/testsuite/std/ranges/zip/1.cc | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 2b5cb0531f0..2b8fec3c386 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -4657,8 +4657,8 @@ namespace views::__adaptor return ranges::min({difference_type(std::get<_Is>(__x._M_current) - std::get<_Is>(__y._M_current))...}, ranges::less{}, - [](difference_type __i) -> make_unsigned_t { - return __i < 0 ? -__i : __i; + [](difference_type __i) { + return __detail::__to_unsigned_like(__i < 0 ? -__i : __i); }); }(make_index_sequence{}); } @@ -4726,8 +4726,8 @@ namespace views::__adaptor return [&](index_sequence<_Is...>) { return ranges::min({_Ret(std::get<_Is>(__x._M_current) - std::get<_Is>(__y._M_end))...}, ranges::less{}, - [](_Ret __i) -> make_unsigned_t<_Ret> { - return __i < 0 ? -__i : __i; + [](_Ret __i) { + return __detail::__to_unsigned_like(__i < 0 ? -__i : __i); }); }(make_index_sequence{}); } diff --git a/libstdc++-v3/testsuite/std/ranges/zip/1.cc b/libstdc++-v3/testsuite/std/ranges/zip/1.cc index 0113efdb537..f868c97cb69 100644 --- a/libstdc++-v3/testsuite/std/ranges/zip/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/zip/1.cc @@ -102,10 +102,24 @@ test03() return true; } +constexpr bool +test04() +{ + // PR libstdc++/106766 + auto r = views::zip(views::iota(__int128(0), __int128(1))); + auto i = r.begin(); + auto s = r.end(); + VERIFY( s - i == 1 ); + VERIFY( i + 1 - i == 1 ); + + return true; +} + int main() { static_assert(test01()); static_assert(test02()); static_assert(test03()); + static_assert(test04()); }