From patchwork Thu Feb 10 16:56:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 51014 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5818F3858401 for ; Thu, 10 Feb 2022 16:59:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5818F3858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644512387; bh=LFzatZbE2ZvGSvo08BYOXe7v9SbUQ+V/dRWuBFC5yag=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YmX2gBvH8c+F0i+qyj0fxzIZX+pvA4ExMu4CJ9p3GW7wNlD/9XtTWKaapfgvf+t83 l8bdi/G6nWxfCZItHn8kJ5ab57hokzMMcKy8t2S8F+oNABrIxNP3WRziPJP3Q4uuWH kmqR5ou+X+XfvjUkYO/rUqLVumOZ3IMkfON3xxdc= 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 F344D3858C60 for ; Thu, 10 Feb 2022 16:56:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F344D3858C60 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-47-J55OKUToPzCxQuU8KFJ5og-1; Thu, 10 Feb 2022 11:56:28 -0500 X-MC-Unique: J55OKUToPzCxQuU8KFJ5og-1 Received: by mail-qk1-f199.google.com with SMTP id bl5-20020a05620a1a8500b005088d061be4so3959382qkb.21 for ; Thu, 10 Feb 2022 08:56:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LFzatZbE2ZvGSvo08BYOXe7v9SbUQ+V/dRWuBFC5yag=; b=FiCtqXABHzWBXr/Vpyng2XdE9psNqZGcxW3cQR/CBZetZSGt684EdSzVgtpv6aR+dC phIbO4POJNtLgp/z6IANOaN79/qo4+mQNey6gH3HMEmGdFiJy3JQnmKHptC8tjUUiw4Z rZ/W02YzXOMFlzCWlFDj6zr70IpONE1CJmzTxqJkvQ0rLOWxPoh1QgFCM9sv4HT4JU83 gAUhhDm5Y8BOEw5ORu+uEnhb+c6QisM5pr9daSGLoS79PvhxDYxL0yl3s/ufd5sPXKbi ER+1txk81L9nedCBBNWMqFOrzDE43K2rea2ixf8TGiZd5A79W8z+QmkxcfmStHW9fuzB rtyg== X-Gm-Message-State: AOAM533NDBWsRMYzhk26auoULpKc6nZjlOfC7fSCJU1nXVJEePv76dWA CskximmzNh9mhYOmpQxUad5kKc8sJ2m90Yk+VwV+pIjryhXV8k3PPCciDsmEraP09R2h0sGFxjz x2w1u3lUoTO4n+fB03oZShmsBNtuYmS33mnRmKu8cceSbXZDZgjO2NRp1ch+J61GiSiE= X-Received: by 2002:ac8:5d90:: with SMTP id d16mr5456515qtx.142.1644512187331; Thu, 10 Feb 2022 08:56:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIqxAFISTR3XxUcx3iueLgESpJJ9lfs/OwU58m8zEBKr1N8TUw8gTrdbXjBofjzQX3u3oHqA== X-Received: by 2002:ac8:5d90:: with SMTP id d16mr5456481qtx.142.1644512186659; Thu, 10 Feb 2022 08:56:26 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id x18sm11474453qtw.93.2022.02.10.08.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 08:56:26 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3, 11 backport] libstdc++: Implement P2325 changes to default-constructibility of views Date: Thu, 10 Feb 2022 11:56:22 -0500 Message-Id: <20220210165624.2953676-1-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.102.g2b9c120970 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 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=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested on x86_64-pc-linux-gnu, does this look OK for the 11 branch? The backport to the 10 branch hasn't been started yet, I figured it'd be good to first get the 11 backport right then base the 10 backport on the 11 one. NB: This backport of r12-1606 to the 11 branch deliberately omits parts of P2325R3 so as to maximize backward compatibility with pre-P2325R3 code. In particular, we don't remove the default ctors for back_insert_iterator, front_insert_iterator, ostream_iterator, ref_view and basic_istream_view. This implements the wording changes of P2325R3 "Views should not be required to be default constructible". Changes are relatively straightforward, besides perhaps those to __box (which now stands for copyable-box instead of semiregular-box) and __non_propagating_cache. For __box, this patch implements the recommended practice to also avoid std::optional when the boxed type is nothrow_move/copy_constructible. For __non_propagating_cache, now that it's used by split_view::_M_current, we need to add assignment from a value of the underlying type to the subset of the std::optional API implemented for the cache (needed by split_view::begin()). Hence the new __non_propagating_cache::operator= overload. In passing, this fixes the undesirable list-init in the constructors of the partial specialization of __box as reported in PR100475 comment #7. PR libstdc++/103904 libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (weakly_incrementable): Remove default_initializable requirement. * include/bits/ranges_base.h (ranges::view): Likewise. * include/bits/ranges_util.h (subrange): Constrain the default ctor. * include/bits/stl_iterator.h (common_iterator): Constrain the default ctor. (counted_iterator): Likewise. * include/std/ranges (__detail::__box::operator=): Handle self-assignment in the primary template. (__detail::__box): In the partial specialization: adjust constraints as per P2325. Add specialized operator= for the case when the wrapped type is not copyable. Constrain the default ctor. Avoid list-initialization. (single_view): Constraint the default ctor. (iota_view): Relax semiregular constraint to copyable. Constrain the default ctor. (iota_view::_Iterator): Constraint the default ctor. (basic_istream_view): Remove the default ctor. Remove NSDMIs. Remove redundant checks for empty _M_stream. (basic_istream_view::_Iterator): Likewise. (ref_view): Remove the default ctor. Remove NSDMIs. (ref_view::_Iterator): Constrain the default ctor. (__detail::__non_propagating_cache::operator=): Define overload for assigning from a value of the underlying type. (filter_view): Likewise. (filter_view::_Iterator): Likewise. (transform_view): Likewise. (transform_view::_Iterator): Likewise. (take_view): Likewise. (take_view::_Iterator): Likewise. (take_while_view): Likewise. (take_while_view::_Iterator): Likewise. (drop_while_view): Likewise. (drop_while_view::_Iterator): Likewise. (join_view): Likewise. (split_view::_OuterIter::__current): Adjust after changing the type of _M_current. (split_view::_M_current): Wrap it in a __non_propagating_cache. (split_view::split_view): Constrain the default ctor. (common_view): Constrain the default ctor. (reverse_view): Likewise. (elements_view): Likewise. * include/std/span (enable_view>): Define this partial specialization to true unconditionally. * include/std/version (__cpp_lib_ranges): Adjust value. * testsuite/std/ranges/adaptors/detail/semiregular_box.cc: Rename to ... * testsuite/std/ranges/adaptors/detail/copyable_box.cc: ... this. (test02): Adjust now that __box is copyable-box not semiregular-box. (test03): New test. * testsuite/std/ranges/p2325.cc: New test. * testsuite/std/ranges/single_view.cc (test06): New test. * testsuite/std/ranges/view.cc: Adjust now that view doesn't require default_initializable. (cherry picked from commit 4b4f5666b4c2f3aab2a9f3d53d394e390b9b682d) --- libstdc++-v3/include/bits/iterator_concepts.h | 3 +- libstdc++-v3/include/bits/ranges_base.h | 3 +- libstdc++-v3/include/bits/ranges_util.h | 2 +- libstdc++-v3/include/bits/stl_iterator.h | 3 +- libstdc++-v3/include/std/ranges | 136 +++++++++---- libstdc++-v3/include/std/span | 3 +- libstdc++-v3/include/std/version | 2 +- .../{semiregular_box.cc => copyable_box.cc} | 51 ++++- libstdc++-v3/testsuite/std/ranges/p2325.cc | 180 ++++++++++++++++++ .../testsuite/std/ranges/single_view.cc | 15 ++ libstdc++-v3/testsuite/std/ranges/view.cc | 2 +- 11 files changed, 348 insertions(+), 52 deletions(-) rename libstdc++-v3/testsuite/std/ranges/adaptors/detail/{semiregular_box.cc => copyable_box.cc} (70%) create mode 100644 libstdc++-v3/testsuite/std/ranges/p2325.cc diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index 11748e5ed7b..c273056c204 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -594,8 +594,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Requirements on types that can be incremented with ++. template - concept weakly_incrementable = default_initializable<_Iter> - && movable<_Iter> + concept weakly_incrementable = movable<_Iter> && requires(_Iter __i) { typename iter_difference_t<_Iter>; diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index a63ef8eb7f4..48a9d0d95bb 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -619,8 +619,7 @@ namespace ranges /// [range.view] The ranges::view concept. template concept view - = range<_Tp> && movable<_Tp> && default_initializable<_Tp> - && enable_view<_Tp>; + = range<_Tp> && movable<_Tp> && enable_view<_Tp>; // [range.refinements] diff --git a/libstdc++-v3/include/bits/ranges_util.h b/libstdc++-v3/include/bits/ranges_util.h index abbf48bf157..ebcd233fdb1 100644 --- a/libstdc++-v3/include/bits/ranges_util.h +++ b/libstdc++-v3/include/bits/ranges_util.h @@ -219,7 +219,7 @@ namespace ranges [[no_unique_address]] _Size<__size_type> _M_size = {}; public: - subrange() = default; + subrange() requires default_initializable<_It> = default; constexpr subrange(__detail::__convertible_to_non_slicing<_It> auto __i, _Sent __s) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index f7309e6bca8..549bc26dee5 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1741,6 +1741,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr common_iterator() noexcept(is_nothrow_default_constructible_v<_It>) + requires default_initializable<_It> : _M_it(), _M_index(0) { } @@ -2118,7 +2119,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // iterator_concept defined in __counted_iter_concept // iterator_category defined in __counted_iter_cat - constexpr counted_iterator() = default; + constexpr counted_iterator() requires default_initializable<_It> = default; constexpr counted_iterator(_It __i, iter_difference_t<_It> __n) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index e46d9a059d2..bf6cfae2a6e 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -113,10 +113,13 @@ namespace ranges noexcept(is_nothrow_copy_constructible_v<_Tp>) requires (!copyable<_Tp>) { - if ((bool)__that) - this->emplace(*__that); - else - this->reset(); + if (this != std::__addressof(__that)) + { + if ((bool)__that) + this->emplace(*__that); + else + this->reset(); + } return *this; } @@ -125,37 +128,42 @@ namespace ranges noexcept(is_nothrow_move_constructible_v<_Tp>) requires (!movable<_Tp>) { - if ((bool)__that) - this->emplace(std::move(*__that)); - else - this->reset(); + if (this != std::__addressof(__that)) + { + if ((bool)__that) + this->emplace(std::move(*__that)); + else + this->reset(); + } return *this; } }; - // For types which are already semiregular, this specialization of the - // semiregular wrapper stores the object directly without going through + // For types which are already copyable, this specialization of the + // copyable wrapper stores the object directly without going through // std::optional. It provides just the subset of the primary template's // API that we currently use. - template<__boxable _Tp> requires semiregular<_Tp> + template<__boxable _Tp> + requires copyable<_Tp> || (is_nothrow_move_constructible_v<_Tp> + && is_nothrow_copy_constructible_v<_Tp>) struct __box<_Tp> { private: [[no_unique_address]] _Tp _M_value = _Tp(); public: - __box() = default; + __box() requires default_initializable<_Tp> = default; constexpr explicit __box(const _Tp& __t) noexcept(is_nothrow_copy_constructible_v<_Tp>) - : _M_value{__t} + : _M_value(__t) { } constexpr explicit __box(_Tp&& __t) noexcept(is_nothrow_move_constructible_v<_Tp>) - : _M_value{std::move(__t)} + : _M_value(std::move(__t)) { } template @@ -166,6 +174,38 @@ namespace ranges : _M_value(std::forward<_Args>(__args)...) { } + __box(const __box&) = default; + __box(__box&&) = default; + __box& operator=(const __box&) requires copyable<_Tp> = default; + __box& operator=(__box&&) requires copyable<_Tp> = default; + + // When _Tp is nothrow_copy_constructible but not copy_assignable, + // copy assignment is implemented via destroy-then-copy-construct. + constexpr __box& + operator=(const __box& __that) noexcept + { + static_assert(is_nothrow_copy_constructible_v<_Tp>); + if (this != std::__addressof(__that)) + { + _M_value.~_Tp(); + std::construct_at(std::__addressof(_M_value), *__that); + } + return *this; + } + + // Likewise for move assignment. + constexpr __box& + operator=(__box&& __that) noexcept + { + static_assert(is_nothrow_move_constructible_v<_Tp>); + if (this != std::__addressof(__that)) + { + _M_value.~_Tp(); + std::construct_at(std::__addressof(_M_value), std::move(*__that)); + } + return *this; + } + constexpr bool has_value() const noexcept { return true; }; @@ -193,7 +233,7 @@ namespace ranges class single_view : public view_interface> { public: - single_view() = default; + single_view() requires default_initializable<_Tp> = default; constexpr explicit single_view(const _Tp& __t) @@ -305,7 +345,7 @@ namespace ranges template requires std::__detail::__weakly_eq_cmp_with<_Winc, _Bound> - && semiregular<_Winc> + && copyable<_Winc> class iota_view : public view_interface> { private: @@ -334,7 +374,7 @@ namespace ranges using value_type = _Winc; using difference_type = __detail::__iota_diff_t<_Winc>; - _Iterator() = default; + _Iterator() requires default_initializable<_Winc> = default; constexpr explicit _Iterator(_Winc __value) @@ -531,7 +571,7 @@ namespace ranges [[no_unique_address]] _Bound _M_bound = _Bound(); public: - iota_view() = default; + iota_view() requires default_initializable<_Winc> = default; constexpr explicit iota_view(_Winc __value) @@ -670,8 +710,6 @@ namespace views using difference_type = ptrdiff_t; using value_type = _Val; - _Iterator() = default; - constexpr explicit _Iterator(basic_istream_view* __parent) noexcept : _M_parent(__parent) @@ -1140,6 +1178,16 @@ namespace views::__adaptor return *this; } + constexpr __non_propagating_cache& + operator=(_Tp __val) + { + this->_M_reset(); + std::construct_at(std::__addressof(this->_M_payload._M_payload), + std::in_place, std::move(__val)); + this->_M_payload._M_engaged = true; + return *this; + } + constexpr _Tp& operator*() noexcept { return this->_M_get(); } @@ -1317,7 +1365,7 @@ namespace views::__adaptor using value_type = range_value_t<_Vp>; using difference_type = range_difference_t<_Vp>; - _Iterator() = default; + _Iterator() requires default_initializable<_Vp_iter> = default; constexpr _Iterator(filter_view* __parent, _Vp_iter __current) @@ -1429,7 +1477,9 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - filter_view() = default; + filter_view() requires (default_initializable<_Vp> + && default_initializable<_Pred>) + = default; constexpr filter_view(_Vp __base, _Pred __pred) @@ -1578,7 +1628,7 @@ namespace views::__adaptor = remove_cvref_t>>; using difference_type = range_difference_t<_Base>; - _Iterator() = default; + _Iterator() requires default_initializable<_Base_iter> = default; constexpr _Iterator(_Parent* __parent, _Base_iter __current) @@ -1793,7 +1843,9 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - transform_view() = default; + transform_view() requires (default_initializable<_Vp> + && default_initializable<_Fp>) + = default; constexpr transform_view(_Vp __base, _Fp __fun) @@ -1928,7 +1980,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - take_view() = default; + take_view() requires default_initializable<_Vp> = default; constexpr take_view(_Vp base, range_difference_t<_Vp> __count) @@ -2112,7 +2164,9 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - take_while_view() = default; + take_while_view() requires (default_initializable<_Vp> + && default_initializable<_Pred>) + = default; constexpr take_while_view(_Vp base, _Pred __pred) @@ -2200,7 +2254,7 @@ namespace views::__adaptor _M_cached_begin; public: - drop_view() = default; + drop_view() requires default_initializable<_Vp> = default; constexpr drop_view(_Vp __base, range_difference_t<_Vp> __count) @@ -2316,7 +2370,9 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - drop_while_view() = default; + drop_while_view() requires (default_initializable<_Vp> + && default_initializable<_Pred>) + = default; constexpr drop_while_view(_Vp __base, _Pred __pred) @@ -2506,7 +2562,9 @@ namespace views::__adaptor = common_type_t, range_difference_t>>; - _Iterator() = default; + _Iterator() requires (default_initializable<_Outer_iter> + && default_initializable<_Inner_iter>) + = default; constexpr _Iterator(_Parent* __parent, _Outer_iter __outer) @@ -2659,7 +2717,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - join_view() = default; + join_view() requires default_initializable<_Vp> = default; constexpr explicit join_view(_Vp __base) @@ -2826,7 +2884,7 @@ namespace views::__adaptor if constexpr (forward_range<_Vp>) return _M_current; else - return _M_parent->_M_current; + return *_M_parent->_M_current; } constexpr auto& @@ -2835,7 +2893,7 @@ namespace views::__adaptor if constexpr (forward_range<_Vp>) return _M_current; else - return _M_parent->_M_current; + return *_M_parent->_M_current; } _Parent* _M_parent = nullptr; @@ -3083,12 +3141,14 @@ namespace views::__adaptor // XXX: _M_current is "present only if !forward_range" [[no_unique_address]] __detail::__maybe_present_t, - iterator_t<_Vp>> _M_current; + __detail::__non_propagating_cache>> _M_current; _Vp _M_base = _Vp(); public: - split_view() = default; + split_view() requires (default_initializable<_Vp> + && default_initializable<_Pattern>) + = default; constexpr split_view(_Vp __base, _Pattern __pattern) @@ -3219,7 +3279,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - common_view() = default; + common_view() requires default_initializable<_Vp> = default; constexpr explicit common_view(_Vp __r) @@ -3348,7 +3408,7 @@ namespace views::__adaptor _Vp _M_base = _Vp(); public: - reverse_view() = default; + reverse_view() requires default_initializable<_Vp> = default; constexpr explicit reverse_view(_Vp __r) @@ -3490,7 +3550,7 @@ namespace views::__adaptor class elements_view : public view_interface> { public: - elements_view() = default; + elements_view() requires default_initializable<_Vp> = default; constexpr explicit elements_view(_Vp base) @@ -3611,7 +3671,7 @@ namespace views::__adaptor = remove_cvref_t>>; using difference_type = range_difference_t<_Base>; - _Iterator() = default; + _Iterator() requires default_initializable> = default; constexpr explicit _Iterator(iterator_t<_Base> current) diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index 503b71fc8bd..af0d24b29f2 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -450,8 +450,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Opt-in to view concept template inline constexpr bool - enable_view> - = _Extent == 0 || _Extent == dynamic_extent; + enable_view> = true; } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index c591398e877..b565e8d976a 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -247,7 +247,7 @@ #define __cpp_lib_optional 202106L #define __cpp_lib_polymorphic_allocator 201902L #if __cpp_lib_concepts -# define __cpp_lib_ranges 201911L +# define __cpp_lib_ranges 202106L #endif #if __cpp_lib_atomic_wait || _GLIBCXX_HAVE_POSIX_SEMAPHORE # define __cpp_lib_semaphore 201907L diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/copyable_box.cc similarity index 70% rename from libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc rename to libstdc++-v3/testsuite/std/ranges/adaptors/detail/copyable_box.cc index ed694e04fd1..fa6d4d56816 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/copyable_box.cc @@ -82,9 +82,10 @@ test01() } static_assert(test01()); -template +template struct A { - A() requires make_semiregular; + A(const A&) = default; + A& operator=(const A&) requires make_copyable; A(int, int); A(std::initializer_list) = delete; }; @@ -93,9 +94,51 @@ void test02() { // PR libstdc++/100475 - static_assert(std::semiregular>); + static_assert(std::copyable>); __box> x2(std::in_place, 0, 0); - static_assert(!std::semiregular>); + static_assert(!std::copyable>); __box> x1(std::in_place, 0, 0); } + +constexpr bool +test03() +{ + // Verify correctness of the non-defaulted operator= for the partial + // specialization of __box. + struct B { + constexpr B(int* p) : p(p) { } + constexpr ~B() { ++*p; }; + B(const B&) = default; + B& operator=(const B&) = delete; + int* p; + }; + static_assert(!std::copyable); + static_assert(std::is_nothrow_copy_constructible_v); + static_assert(sizeof(__box) == sizeof(B)); + + int m = 0; + __box x(std::in_place, &m); + __glibcxx_assert(m == 0); + x = x; + __glibcxx_assert(m == 0); + x = std::move(x); + __glibcxx_assert(m == 0); + + int n = 0; + __box y(std::in_place, &n); + auto z = x; + x = y; + __glibcxx_assert(m == 1); + __glibcxx_assert(n == 0); + __glibcxx_assert(x->p == &n); + __glibcxx_assert(y->p == &n); + y = std::move(z); + __glibcxx_assert(m == 1); + __glibcxx_assert(n == 1); + __glibcxx_assert(y->p == &m); + __glibcxx_assert(z->p == &m); + + return true; +} +static_assert(test03()); diff --git a/libstdc++-v3/testsuite/std/ranges/p2325.cc b/libstdc++-v3/testsuite/std/ranges/p2325.cc new file mode 100644 index 00000000000..72ba5c4a35d --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/p2325.cc @@ -0,0 +1,180 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } +// P2325R3 "Views should not be required to be default constructible" + +// Parts of P2325R3 are deliberately omitted in libstdc++ 11, in particular the +// removal of default ctors for back_/front_insert_iterator, ostream_iterator, +// ref_view and basic_istream_view/::iterator, so as to maximize backward +// compatibility with pre-P2325R3 code. So most static_asserts in this test fail, +// see the xfails at the end of this file. + +#include +#include +#include +#include +#include +#include + +using namespace std; + +template void f(); +template requires weakly_incrementable || ranges::view void f(); + +void +test01() +{ + // Verify neither std::weakly_incrementable nor ranges::view require + // default_initializable. + f(); // { dg-error "ambiguous" } +} + +void +test02() +{ + // Verify these iterators are not default constructible. + static_assert(!default_initializable>>); + static_assert(!default_initializable>>); + static_assert(!default_initializable>>); + static_assert(!default_initializable>); + + using iter = ostream_iterator; + + // Verify common_iterator is conditionally default constructible. + static_assert(!default_initializable>); + static_assert(default_initializable>); + + // Verify counted_iterator is conditionally default constructible. + static_assert(!default_initializable>); + static_assert(default_initializable>); +} + +void +test03() +{ + using iter = ostream_iterator; + + // Verify iota_view is conditionally default constructible. + static_assert(!default_initializable>); + static_assert(!default_initializable>().begin())>); + static_assert(default_initializable>); + static_assert(default_initializable>().begin())>); + + // Verify subrange is conditionally default constructible. + static_assert(!default_initializable>); + static_assert(default_initializable>); + + // Verify single_view is conditionally default constructible. + static_assert(!default_initializable>); + static_assert(default_initializable>); +} + +void +test04() +{ + // Verify basic_istream_view is not default constructible. + using type = ranges::basic_istream_view>; + static_assert(!default_initializable); + static_assert(!default_initializable().begin())>); +} + +void +test05() +{ + // Verify ref_view is not default constructible. + static_assert(!default_initializable>); +} + +template +void +test06() +{ + auto f1 = [] (auto) { return true; }; + auto f2 = [i=0] (auto) { return true; }; + static_assert(default_initializable); + static_assert(!default_initializable); + + struct S { S() = delete; }; + static_assert(!default_initializable()) | adaptor(f1))>); + static_assert(!default_initializable()) | adaptor(f2))>); +} + +// Verify filter_view, transform_view, take_while_view and drop_while_view are +// conditionally default constructible. +template void test06(); +template void test06(); +template void test06(); +template void test06(); + +void +test07() +{ + // Verify join_view is conditionally default constructible. + struct S { S() = delete; }; + using type1 = ranges::join_view>>; + static_assert(!default_initializable); + using type2 = ranges::join_view>>; + static_assert(default_initializable); +} + +void +test08() +{ + // Verify split_view is conditionally default constructible. + using type1 = ranges::split_view, ranges::single_view>; + static_assert(!default_initializable); + using type2 = ranges::split_view, ranges::ref_view>; + static_assert(!default_initializable); + using type3 = ranges::split_view, ranges::ref_view>; + static_assert(!default_initializable); + using type4 = ranges::split_view, ranges::single_view>; + static_assert(default_initializable); +} + +void +test09() +{ + // Verify common_view is conditionally default constructible. + using type1 = ranges::common_view>>; + static_assert(!default_initializable); + using type2 = ranges::common_view>; + static_assert(default_initializable); +} + +void +test10() +{ + // Verify reverse_view is conditionally default constructible. + using type1 = ranges::reverse_view>; + static_assert(!default_initializable); + using type2 = ranges::reverse_view>; + static_assert(default_initializable); +} + +void +test11() +{ + // Verify elements_view is conditionally default constructible. + using type1 = ranges::elements_view[2]>, 0>; + static_assert(!default_initializable); + using type2 = ranges::elements_view>, 0>; + static_assert(default_initializable); +} + +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 35 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 36 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 37 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 38 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 43 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 47 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 57 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 58 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 63 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 67 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 76 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 84 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 124 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 126 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 128 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 138 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 148 } +// { dg-bogus "static assertion failed" "" { xfail *-*-* } 158 } diff --git a/libstdc++-v3/testsuite/std/ranges/single_view.cc b/libstdc++-v3/testsuite/std/ranges/single_view.cc index f530cc07565..dd86d351beb 100644 --- a/libstdc++-v3/testsuite/std/ranges/single_view.cc +++ b/libstdc++-v3/testsuite/std/ranges/single_view.cc @@ -73,10 +73,25 @@ test04() std::as_const(s).data(); } +void +test06() +{ + // PR libstdc++/100475 comment #7 + struct S { + S() = default; + S(std::initializer_list) = delete; + S(const S&) {} + }; + S obj; + auto x = std::views::single(obj); + auto y = std::views::single(std::move(obj)); +} + int main() { test01(); test02(); test03(); test04(); + test06(); } diff --git a/libstdc++-v3/testsuite/std/ranges/view.cc b/libstdc++-v3/testsuite/std/ranges/view.cc index d8972ab3e46..dd8258220ed 100644 --- a/libstdc++-v3/testsuite/std/ranges/view.cc +++ b/libstdc++-v3/testsuite/std/ranges/view.cc @@ -31,7 +31,7 @@ static_assert(std::ranges::view>); static_assert(std::ranges::view>); -static_assert(!std::ranges::view>); +static_assert(std::ranges::view>); // Changed with P2325R3 static_assert(std::ranges::view); static_assert(std::ranges::view); From patchwork Thu Feb 10 16:56:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 51012 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FED33858401 for ; Thu, 10 Feb 2022 16:57:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FED33858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644512241; bh=h7cuISH0p5GPcRNPbhnfJWQ+lN64vFYh9Gc4ykOzZnE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uWjbMK3fCncF4SvMRvprAaPayADwub6mRKy0lfAWD7ZOLO9SEZEC4m2PAlBU9f5Tm hjlye3elbU69LbrSxDjBDgmzZVYhwVPhao7e7wweSMTmY1CgIBR9IB6x37aKfqRlTN ziUXS3BMzakCEUSWaVA7IgVus67Fo/bMOkZzaQ+k= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 1C77E3858C2C for ; Thu, 10 Feb 2022 16:56:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C77E3858C2C Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-QnLIFVqLNX2LKDEvKOFBtQ-1; Thu, 10 Feb 2022 11:56:28 -0500 X-MC-Unique: QnLIFVqLNX2LKDEvKOFBtQ-1 Received: by mail-qv1-f72.google.com with SMTP id 14-20020a05621420ee00b00423846005d4so4356843qvk.15 for ; Thu, 10 Feb 2022 08:56:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h7cuISH0p5GPcRNPbhnfJWQ+lN64vFYh9Gc4ykOzZnE=; b=7C/DYP6eYBTcOHL/5iTV/ii+ePP8H7UA8O4SvMLHRM64TCGtBLhcV/F402ExyEghuY M8go0YTZXcL5c1z77yZjjKpg+z2oenqWE/xVEj+hPsea+sx2wT6gy/Bi/KaETGfgqdO6 rr4ssAsiNpww3vT7EBL5reawWBNipFIiNIiO1R/BKtzrzLGdO75n8QeRLkiLIcmY9AuM Z/jcZyG28qd+F8A0YqDU3Be5DphGWS5IlEoW3jRJ7yvdN4vHgRUAPSX5gWArJyRieTab K16IU4i1VrD1dhoSeJ/OVfsE9m60/Dk7bkYALYYFv0SNU2ghPNvFxOErcEAgVP/YkcDi 0k4w== X-Gm-Message-State: AOAM531n0H2IghaD+NzpT2uF6Gw1i3ksYWDkIubFHNEWjKQTM4OOmylZ vv8JgMwP2Pu4TCuayBsbk+TYESIvEci1kyFlgBAIMma/c4TQbfCkJMliJrgPxcYsoBdsHfbhk9+ sAHtgu2HTpxogo8PPqwbfXU20PMlkHZdn3NJocz5yRt1QduGqCI8Y3GJb+0UlJXKhO24= X-Received: by 2002:a05:6214:1c8f:: with SMTP id ib15mr5758742qvb.75.1644512188180; Thu, 10 Feb 2022 08:56:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPjdbF1lhLLnRTJllns7G06YBiKZy4SsuVD6XW0dXi2jriQWA96xPTcpSB7aCXX2u8TUym1Q== X-Received: by 2002:a05:6214:1c8f:: with SMTP id ib15mr5758724qvb.75.1644512187948; Thu, 10 Feb 2022 08:56:27 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id x18sm11474453qtw.93.2022.02.10.08.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 08:56:27 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3, 11 backport] libstdc++: Sync __cpp_lib_ranges macro defined in ranges_cmp.h Date: Thu, 10 Feb 2022 11:56:23 -0500 Message-Id: <20220210165624.2953676-2-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.102.g2b9c120970 In-Reply-To: <20220210165624.2953676-1-ppalka@redhat.com> References: <20220210165624.2953676-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 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=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" r12-1606 bumped the value of __cpp_lib_ranges defined in , but this macro is also defined in , so it needs to be updated there as well. PR libstdc++/103904 libstdc++-v3/ChangeLog: * include/bits/ranges_cmp.h (__cpp_lib_ranges): Adjust value. (cherry picked from commit 12bdd39755a25d237b7776153cbe03e171396fc5) --- libstdc++-v3/include/bits/ranges_cmp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/ranges_cmp.h b/libstdc++-v3/include/bits/ranges_cmp.h index f859a33b2c1..1d7da30dddf 100644 --- a/libstdc++-v3/include/bits/ranges_cmp.h +++ b/libstdc++-v3/include/bits/ranges_cmp.h @@ -57,7 +57,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef __cpp_lib_concepts // Define this here, included by all the headers that need to define it. -#define __cpp_lib_ranges 201911L +#define __cpp_lib_ranges 202106L namespace ranges { From patchwork Thu Feb 10 16:56:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 51013 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16A953858427 for ; Thu, 10 Feb 2022 16:58:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16A953858427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644512330; bh=jZ1Zoi8TgwAr0mt07a+pv6umtJMQS/o4h/16h+ZLntU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gCXO8+gM7/fn587E1Yhmekf7VDyqW4f6LTMmcbRe6QWbkyYSVCyfhnK5TJXXphckd aILfjEuihtwflWzYT0h/OR/edZlw55oUnkjk3Dijr/2YKs2fbRVYYyVgH63DzmfNf4 AcyLzwq7Uy+sgGZPByqXDSPwVRsTBlbp2EJMBeoM= 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 7179C3858C39 for ; Thu, 10 Feb 2022 16:56:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7179C3858C39 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-lNn8gQnXNOqgx8Q31KmvYA-1; Thu, 10 Feb 2022 11:56:30 -0500 X-MC-Unique: lNn8gQnXNOqgx8Q31KmvYA-1 Received: by mail-qt1-f200.google.com with SMTP id a28-20020ac84d9c000000b002d05c958a84so4891961qtw.0 for ; Thu, 10 Feb 2022 08:56:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jZ1Zoi8TgwAr0mt07a+pv6umtJMQS/o4h/16h+ZLntU=; b=Q+q4PMirGgPUEdfntyMghzlwwGKImJVsuFk3kDujSO53dESj+CbODPB5IkYxK9Ahnr CZTw3HYYaH2JxdzZHqjIVQzUATgg7g+sr9j3tJLVbuqK17KPEbqOPSSBrreFJZV0YxQK wZVXadVnVUXUBKkTbLOD6zWMUfacFcb+2uuKVNeJq0Nm/ryDmyTx+kzcwBswvHnhGmHQ 7JqL0gPtsABD8qDB7SgOQcvXesudkvtL6EDzIsVAJeDep0ybItPI49VozyUFQX6aFGwn DV7mYVVSqj5ojlo6iZGnLjD4wUCOfifkZp7XwyJYQLxT7tA+o90J9xEN74sOZRct794Q GHlA== X-Gm-Message-State: AOAM5319aLvcU+DbrkToWokuAoTCi9wMrIbCE5S5JjgGUTxa8qOA9sNQ tbP10nYolkTdjhTqGallCOoV3r9Qf1ekqAV9NbFmZERgU/Bv090VKlPqQYVuiLi+BjCEV/ATpMp 4u+mn8QQ4OkzvHdCiFLMknJRGp5b52L2pjWxfZxh5iAlHAOXNPV4pZBBjTPKtGiCCkrw= X-Received: by 2002:a05:6214:b6d:: with SMTP id ey13mr5381513qvb.40.1644512189653; Thu, 10 Feb 2022 08:56:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXgnV62MyJH+5RNfg0oyEXbXh07PVkmnKXgTeBXs5mcj6NpJHePxeiTnbeVptd/DIHXThVVQ== X-Received: by 2002:a05:6214:b6d:: with SMTP id ey13mr5381501qvb.40.1644512189452; Thu, 10 Feb 2022 08:56:29 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id x18sm11474453qtw.93.2022.02.10.08.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 08:56:29 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3, 11 backport] libstdc++: invalid default init in _CachedPosition [PR101231] Date: Thu, 10 Feb 2022 11:56:24 -0500 Message-Id: <20220210165624.2953676-3-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.102.g2b9c120970 In-Reply-To: <20220210165624.2953676-1-ppalka@redhat.com> References: <20220210165624.2953676-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 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=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The primary template for _CachedPosition is a dummy implementation for non-forward ranges, the iterators for which generally can't be cached. Because this implementation doesn't actually cache anything, _M_has_value is defined to be false and so calls to _M_get (which are always guarded by _M_has_value) are unreachable. Still, to suppress a "control reaches end of non-void function" warning I made _M_get return {}, but after P2325 input iterators are no longer necessarily default constructible so this workaround now breaks valid programs. This patch fixes this by instead using __builtin_unreachable to squelch the warning. PR libstdc++/103904 PR libstdc++/101231 libstdc++-v3/ChangeLog: * include/std/ranges (_CachedPosition::_M_get): For non-forward ranges, just call __builtin_unreachable. * testsuite/std/ranges/istream_view.cc (test05): New test. (cherry picked from commit 1af937eb6246ad7f63ebff03590e9eede33aca81) --- libstdc++-v3/include/std/ranges | 2 +- libstdc++-v3/testsuite/std/ranges/istream_view.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index bf6cfae2a6e..a4228ba9aa0 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1221,7 +1221,7 @@ namespace views::__adaptor _M_get(const _Range&) const { __glibcxx_assert(false); - return {}; + __builtin_unreachable(); } constexpr void diff --git a/libstdc++-v3/testsuite/std/ranges/istream_view.cc b/libstdc++-v3/testsuite/std/ranges/istream_view.cc index af76a1ab39e..f5c0c2a6bb0 100644 --- a/libstdc++-v3/testsuite/std/ranges/istream_view.cc +++ b/libstdc++-v3/testsuite/std/ranges/istream_view.cc @@ -83,6 +83,17 @@ test04() static_assert(!std::forward_iterator); } +void +test05() +{ + // PR libstdc++/101231 + auto words = std::istringstream{"42"}; + auto is = ranges::istream_view(words); + auto r = is | views::filter([](auto) { return true; }); + for (auto x : r) + ; +} + void test06() { @@ -99,5 +110,6 @@ main() test02(); test03(); test04(); + test05(); test06(); }