From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 483A13858D33 for ; Thu, 18 Apr 2024 21:58:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 483A13858D33 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 483A13858D33 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=1713477525; cv=none; b=VP19bJzI8mXRtHvtjRTv5h5lglWFsIE/cq6odQrtb6Fm4+fq05i3EZUbV/XhnCWLcf+ZOcg0n0rZfPrXnK2nrklUf7ZMN6uTm7lKjXbILrbxvj3lZxamCXTDzAqc7wm82nQ14p7I6JwW4hGyi7Tdw9VSDZp80QIZHUxYI+6O2Zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713477525; c=relaxed/simple; bh=bBZgVNWhRFt9Gep+qFaSXWhj6a5OTlgckqAvw3/Y47U=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=SRj/7CAB3Hq/TdleX5eEBX/dUeW+1j8zIo9LNGcdRbY/CI2UZXtelOLP1ZQque4WVHfpLgg5mEGy0g+GnafShFl6D5svW3efdMoWY4Yjp0jp9gNLPoOF7iKXNWz0r6zAxtgPyrcTKOvIV/9A4No/G0T3P6RE8u+CPRL3auIO7u0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713477522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nouxgoE4KHO3L4uyqnkuPhaPKcLEBkTGbT+r0rOtO5w=; b=bN+CFu+VU/sDSejbNS4qw04GR+j5aXFo3DKQetG6GP2i2vzYylf5aqwrLyDszVN8fCQJLq J7zU94Xm7lzUrG1oA99X4+PK4VHu3CQC61CUhDaa5KHdfRlr8FPwBgrp2e7C8VvQYTsJjb Uh3TtKRhX63pnOez+iRC2TiZbEI4jzs= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-QZKeKTA4PAu06vfxPxcZjA-1; Thu, 18 Apr 2024 17:58:41 -0400 X-MC-Unique: QZKeKTA4PAu06vfxPxcZjA-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3c704fc4b32so1948859b6e.1 for ; Thu, 18 Apr 2024 14:58:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713477521; x=1714082321; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nouxgoE4KHO3L4uyqnkuPhaPKcLEBkTGbT+r0rOtO5w=; b=nwVPXwihzcKmf4RE7gT4sYlBSoKKavqLTLqN85nNIB/Skx/K30g3/T/v2UArNuj7xg le5XyZ12uPa4CJJ60RQPQHC9MJJRlJPyxHF2LFgbTakRD7AthgXA5S4B0/qB9GuzyBCl T70EfebIqDVBdj9u7eqZZV8js2s7sUj5ODfAXholE/z6Ui+4gDhf7L1PD8VPJSbEjEs6 SA3jcTg+mer+pb6w9yRFe9zcFA/TUCCHUvXaGPE4p7rNwQtvh7FC+8uLL6Vj6s9/Gp1J y3LicxWJZfmloJWER3c03OluXtVLHWDBqzIPSXXzm6dlu4CiPd6NSID9hDwus7Fm6f4w nRrA== X-Gm-Message-State: AOJu0YxNtl1WdpL5apNRBZ+8ibm2Exp6YhVoIS9dBZ7IhwxYw78zkO7/ zW4JPFan1/AlP/aZw6338Ie4qTBE1hp544GKfD0+iiFZ2t759X3nFSsu0qwtrbW5feToGz+so1a FmB1q9F0rukc37tNuGm42MOLYbryDBioI02aL5MbKEZx77sCxtFm4 X-Received: by 2002:a05:6808:18a8:b0:3c7:4508:c85d with SMTP id bi40-20020a05680818a800b003c74508c85dmr449987oib.5.1713477520766; Thu, 18 Apr 2024 14:58:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH77zXQIsYXcV1AAMaiZL+ABHa7+OxicQILMDwWlUoBDmh+YZY3rjiEm8HC2qfISwSK8mddNw== X-Received: by 2002:a05:6808:18a8:b0:3c7:4508:c85d with SMTP id bi40-20020a05680818a800b003c74508c85dmr449970oib.5.1713477520410; Thu, 18 Apr 2024 14:58:40 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 1-20020a05620a04c100b0078ef8c994bcsm1009973qks.105.2024.04.18.14.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 14:58:40 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 18 Apr 2024 17:58:39 -0400 (EDT) To: "Michael Levine (BLOOMBERG/ 919 3RD A)" cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Fix std::ranges::iota is not included in numeric [PR108760] In-Reply-To: <662013D8000158270C340001@message.bloomberg.net> Message-ID: References: <662013D8000158270C340001@message.bloomberg.net> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 List-Id: On Wed, 17 Apr 2024, Michael Levine (BLOOMBERG/ 919 3RD A) wrote: > This patch fixes GCC Bug 108760: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108760 > Before this patch, using std::ranges::iota required including when it should have been sufficient to only include . > > When the patch is applied, the following code will compile: https://godbolt.org/z/33EPeqd1b > > I added a test case for this change as well. > > I built my local version of gcc using the following configuration: $ ../gcc/configure --disable-bootstrap --prefix="$(pwd)/_pfx/" --enable-languages=c,c++,lto > > and I tested my changes by running: $ make check-c++ -jN -k Nice, thanks for the patch! > > I ran this on the following OS: > > Virtualization: wsl > Operating System: Ubuntu 20.04.6 LTS > Kernel: Linux 5.15.146.1-microsoft-standard-WSL2 > Architecture: x86-64 > From bd04070c281572ed7a3b48e3d33543e25b8c8afe Mon Sep 17 00:00:00 2001 > From: Michael Levine > Date: Fri, 23 Feb 2024 14:13:13 -0500 > Subject: [PATCH 1/2] Fix the bug > > Signed-off-by: Michael Levine > --- > libstdc++-v3/include/bits/ranges_algo.h | 52 ---------------------- > libstdc++-v3/include/bits/stl_numeric.h | 57 ++++++++++++++++++++++++- > 2 files changed, 56 insertions(+), 53 deletions(-) > > diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h > index 62faff173bd..d258be0b93f 100644 > --- a/libstdc++-v3/include/bits/ranges_algo.h > +++ b/libstdc++-v3/include/bits/ranges_algo.h > @@ -3521,58 +3521,6 @@ namespace ranges > > #endif // __glibcxx_ranges_contains > > -#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 > - > - template > - struct out_value_result > - { > - [[no_unique_address]] _Out out; > - [[no_unique_address]] _Tp value; > - > - template > - requires convertible_to > - && convertible_to > - constexpr > - operator out_value_result<_Out2, _Tp2>() const & > - { return {out, value}; } > - > - template > - requires convertible_to<_Out, _Out2> > - && convertible_to<_Tp, _Tp2> > - constexpr > - operator out_value_result<_Out2, _Tp2>() && > - { return {std::move(out), std::move(value)}; } > - }; > - > - template > - using iota_result = out_value_result<_Out, _Tp>; > - > - struct __iota_fn > - { > - template _Sent, weakly_incrementable _Tp> > - requires indirectly_writable<_Out, const _Tp&> > - constexpr iota_result<_Out, _Tp> > - operator()(_Out __first, _Sent __last, _Tp __value) const > - { > - while (__first != __last) > - { > - *__first = static_cast(__value); > - ++__first; > - ++__value; > - } > - return {std::move(__first), std::move(__value)}; > - } > - > - template _Range> > - constexpr iota_result, _Tp> > - operator()(_Range&& __r, _Tp __value) const > - { return (*this)(ranges::begin(__r), ranges::end(__r), std::move(__value)); } > - }; > - > - inline constexpr __iota_fn iota{}; > - > -#endif // __glibcxx_ranges_iota > - > #if __glibcxx_ranges_find_last >= 202207L // C++ >= 23 > > struct __find_last_fn > diff --git a/libstdc++-v3/include/bits/stl_numeric.h b/libstdc++-v3/include/bits/stl_numeric.h > index fe911154ab7..1b06c26dc02 100644 > --- a/libstdc++-v3/include/bits/stl_numeric.h > +++ b/libstdc++-v3/include/bits/stl_numeric.h > @@ -59,7 +59,7 @@ > #include > #include > #include // For _GLIBCXX_MOVE > - > +#include // For _Range as used by std::ranges::iota > > namespace std _GLIBCXX_VISIBILITY(default) > { > @@ -102,6 +102,61 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > } > #endif > > +namespace ranges > +{ > +#if __glibcxx_ranges_iota >= 202202L // C++ >= 23 > + > + template > + struct out_value_result > + { > + [[no_unique_address]] _Out out; > + [[no_unique_address]] _Tp value; > + > + template > + requires convertible_to > + && convertible_to > + constexpr > + operator out_value_result<_Out2, _Tp2>() const & > + { return {out, value}; } > + > + template > + requires convertible_to<_Out, _Out2> > + && convertible_to<_Tp, _Tp2> > + constexpr > + operator out_value_result<_Out2, _Tp2>() && > + { return {std::move(out), std::move(value)}; } > + }; IIUC out_value_result should continue to be available from , so we probably don't want to move it to (or one of its internal headers). Better would be to move it to I think. > + > + template > + using iota_result = out_value_result<_Out, _Tp>; > + > + struct __iota_fn > + { > + template _Sent, weakly_incrementable _Tp> > + requires indirectly_writable<_Out, const _Tp&> > + constexpr iota_result<_Out, _Tp> > + operator()(_Out __first, _Sent __last, _Tp __value) const > + { > + while (__first != __last) > + { > + *__first = static_cast(__value); > + ++__first; > + ++__value; > + } > + return {std::move(__first), std::move(__value)}; > + } > + > + template _Range> > + constexpr iota_result, _Tp> > + operator()(_Range&& __r, _Tp __value) const > + { return (*this)(ranges::begin(__r), ranges::end(__r), std::move(__value)); } > + }; > + > + inline constexpr __iota_fn iota{}; > + > +#endif // __glibcxx_ranges_iota And it might be cleaner to move ranges::iota directly into instead (and then include directly from to bring in and out_value_result) since has other users besides which would otherwise get unnecessarily bloated. > +} > + > _GLIBCXX_END_NAMESPACE_VERSION > > _GLIBCXX_BEGIN_NAMESPACE_ALGO > -- > 2.25.1 > > > From c52c8d79fb3c7dc9d2512d1635712ffcd3dea07c Mon Sep 17 00:00:00 2001 > From: Michael Levine > Date: Tue, 16 Apr 2024 16:45:37 -0400 > Subject: [PATCH 2/2] Added a test to verify that the bug has been fixed > > Signed-off-by: Michael Levine > --- > .../testsuite/std/ranges/iota/108760.cc | 41 +++++++++++++++++++ > 1 file changed, 41 insertions(+) > create mode 100644 libstdc++-v3/testsuite/std/ranges/iota/108760.cc > > diff --git a/libstdc++-v3/testsuite/std/ranges/iota/108760.cc b/libstdc++-v3/testsuite/std/ranges/iota/108760.cc > new file mode 100644 > index 00000000000..4f71383687c > --- /dev/null > +++ b/libstdc++-v3/testsuite/std/ranges/iota/108760.cc > @@ -0,0 +1,41 @@ > +// Copyright (C) 2020-2024 Free Software Foundation, Inc. > +// > +// This file is part of the GNU ISO C++ Library. This library is free > +// software; you can redistribute it and/or modify it under the > +// terms of the GNU General Public License as published by the > +// Free Software Foundation; either version 3, or (at your option) > +// any later version. > + > +// This library is distributed in the hope that it will be useful, > +// but WITHOUT ANY WARRANTY; without even the implied warranty of > +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +// GNU General Public License for more details. > + > +// You should have received a copy of the GNU General Public License along > +// with this library; see the file COPYING3. If not see > +// . > + > +// Fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108760 > +// { dg-do run { target c++23 } } > + > +#include > +#include > + > +const int ARR_SIZE = 4; > + > +void > +test01() > +{ > + int expected_arr[ARR_SIZE] = {0, 1, 2, 3}; > + int input_arr[ARR_SIZE] = {0, 0, 0, 0}; > + std::ranges::iota(input_arr, 0); > + for (int i = 0; i < ARR_SIZE; i++) { > + VERIFY( input_arr[i] == expected_arr[i]); > + } > +} > + > +int > +main() > +{ > + test01(); > +} Instead of adding a new test, perhaps we should just move the existing test libstdc++-v3/testsuite/25_algorithms/iota/1.cc to libstdc++-v3/testsuite/26_numerics/iota/1.cc and change it to include instead of ? > -- > 2.25.1 >