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 ESMTP id 8A899385803B for ; Wed, 5 May 2021 20:23:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8A899385803B Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-52-oAQ6tB0POqeIJvG6QjOEMw-1; Wed, 05 May 2021 16:23:17 -0400 X-MC-Unique: oAQ6tB0POqeIJvG6QjOEMw-1 Received: by mail-qt1-f198.google.com with SMTP id b6-20020ac85bc60000b02901c2752ed3d4so1852364qtb.15 for ; Wed, 05 May 2021 13:23:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=C97tVNXpdBltZak80TY2isZmCuQ6JmBFwBIACJJyEAU=; b=GI/Zlay5+iAUnZMKIJCIMSlqr5k/lrssdVko/Y2GohxcXwTvyMNPNQ10FrYc603PoR vtvP6obaoZvWLm42fYG0jv/pIWE20+uBcIgeD3p7neoPl6IM8WeGpRMdVB2yeQZRYAtw JLrfzV5F6r55RUY0CIqRQ92L9uV0KYqWLF1cofojvsLrQexOK/ktGvG+rk59HhH5rIfW ecRxkyC81kOJ5mm/NX3MWoW6cm3WaUEHFcprjEKGnFptV3YIaZUYQyMeXeClgaPA5dUo QAS9WvPGEuBTSybFQSMIdK/CkjILgJnj/WhgCTD4KP45qW1jSf8S7xSthsFf1TG11Y/J /lqA== X-Gm-Message-State: AOAM532CWQzZRlc2avoEZjrNGOgdXGAI7Lzhi2k/oE//9VSygxY0TPXe t1Uw1D1qwjP//XhvH/oQM7acK61DljSiSh4Xu8xkmIRodO0GXNJzXVKnxfGQ0bYRuKdjrsbv3Ig C6Eid21XZQrYJmKk= X-Received: by 2002:a05:622a:210:: with SMTP id b16mr365610qtx.377.1620246196597; Wed, 05 May 2021 13:23:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvlfAPRiDYkD7Oo618fTZgdcA9Xt56//Kmp9fdsGXUd3pYqG7i5kbSdZ9Tv4L7F/EGs/aKEw== X-Received: by 2002:a05:622a:210:: with SMTP id b16mr365583qtx.377.1620246196143; Wed, 05 May 2021 13:23:16 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id s25sm316439qkj.34.2021.05.05.13.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 13:23:15 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base Date: Wed, 5 May 2021 16:23:11 -0400 Message-Id: <20210505202312.1609984-1-ppalka@redhat.com> X-Mailer: git-send-email 2.31.1.442.g7e39198978 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-16.4 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 20:23:21 -0000 Tested on x86_64-pc-linux-gnu, does this look OK for trunk/10/11? libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (move_iterator::base): Make the const& overload return a const reference and remove its constraint as per LWG 3391. Make unconditionally noexcept. (counted_iterator::base): Likewise. * testsuite/24_iterators/move_iterator/lwg3391.cc: New test. * testsuite/24_iterators/move_iterator/move_only.cc: Adjust has_member_base concept to decay-copy the result of base(). --- libstdc++-v3/include/bits/stl_iterator.h | 13 ++----- .../24_iterators/move_iterator/lwg3391.cc | 37 +++++++++++++++++++ .../24_iterators/move_iterator/move_only.cc | 8 +++- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 049f83cff90..2409cd71f86 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1409,11 +1409,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION base() const { return _M_current; } #else - constexpr iterator_type - base() const & -#if __cpp_lib_concepts - requires copy_constructible -#endif + constexpr const iterator_type& + base() const & noexcept { return _M_current; } constexpr iterator_type @@ -2141,10 +2138,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } - constexpr _It - base() const & - noexcept(is_nothrow_copy_constructible_v<_It>) - requires copy_constructible<_It> + constexpr const _It& + base() const & noexcept { return _M_current; } constexpr _It diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc new file mode 100644 index 00000000000..18e015777cd --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2021 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 +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Verify LWG 3391 changes. + +#include +#include + +#include + +using __gnu_test::test_range; +using __gnu_test::input_iterator_wrapper_nocopy; + +void +test01() +{ + extern test_range rx; + auto v = rx | std::views::take(5); + std::ranges::begin(v) != std::ranges::end(v); +} diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc index 639adfab0e2..5537dfbf3cd 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc @@ -43,7 +43,13 @@ template<> struct std::iterator_traits static_assert(std::input_iterator); template - concept has_member_base = requires (T t) { std::forward(t).base(); }; + concept has_member_base = requires (T t) { + // LWG 3391 made the const& overload of move_iterator::base() + // unconstrained and return a const reference. So rather than checking + // whether base() is valid (which is now trivially true in an unevaluated + // context), the below now checks whether decay-copying base() is valid. + [](auto){}(std::forward(t).base()); + }; using move_only_move_iterator = std::move_iterator; -- 2.31.1.442.g7e39198978