From patchwork Wed Aug 4 11:55:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1513397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=FANpteCA; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gfqvk54YDz9sRN for ; Wed, 4 Aug 2021 21:56:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89F5B3940CE2 for ; Wed, 4 Aug 2021 11:56:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89F5B3940CE2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1628078175; bh=n7j53miNO8rZwGwPq5BKP8cs8qsd5UkGwkgy7VOp6qA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FANpteCAa1AgmxoAAY2XuW6C4ujzwEePOATa5mb1BhVRUJ3XqDEzueuEU52ObFcR+ K+U1NVGbpUEcKUOWHmJQiH2ntZcCSBQYuQKJC65w4HbHHtf+rD4qF/l/MPgs1aMG6P smGp2YSk1onyVUcCo2pK68qjbRnEXvXdB5lKp/IA= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 776FD385382D for ; Wed, 4 Aug 2021 11:55:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 776FD385382D Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-DsxABvnrMW2skmOIGTlVdg-1; Wed, 04 Aug 2021 07:55:44 -0400 X-MC-Unique: DsxABvnrMW2skmOIGTlVdg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20557107ACF5; Wed, 4 Aug 2021 11:55:43 +0000 (UTC) Received: from localhost (unknown [10.33.36.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C20460854; Wed, 4 Aug 2021 11:55:42 +0000 (UTC) Date: Wed, 4 Aug 2021 12:55:41 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 1/2] libstdc++: Add [[nodiscard]] to iterators and related utilities Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.2 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This adds [[nodiscard]] throughout , as proposed by P2377R0 (with some minor corrections). The attribute is added for all modes from C++11 up, using [[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't be used directly. commit 240b01b0215f9e46ecf04267c8a3faeb19d4fe3c Author: Jonathan Wakely Date: Tue Aug 3 18:06:27 2021 libstdc++: Add [[nodiscard]] to iterators and related utilities This adds [[nodiscard]] throughout , as proposed by P2377R0 (with some minor corrections). The attribute is added for all modes from C++11 up, using [[__nodiscard__]] or _GLIBCXX_NODISCARD where C++17 [[nodiscard]] can't be used directly. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (iter_move): Add [[nodiscard]]. * include/bits/range_access.h (begin, end, cbegin, cend) (rbegin, rend, crbegin, crend, size, data, ssize): Likewise. * include/bits/ranges_base.h (ranges::begin, ranges::end) (ranges::cbegin, ranges::cend, ranges::rbegin, ranges::rend) (ranges::crbegin, ranges::crend, ranges::size, ranges::ssize) (ranges::empty, ranges::data, ranges::cdata): Likewise. * include/bits/stl_iterator.h (reverse_iterator, __normal_iterator) (back_insert_iterator, front_insert_iterator, insert_iterator) (move_iterator, move_sentinel, common_iterator) (counted_iterator): Likewise. * include/bits/stl_iterator_base_funcs.h (distance, next, prev): Likewise. * include/bits/stream_iterator.h (istream_iterator) (ostream_iterartor): Likewise. * include/bits/streambuf_iterator.h (istreambuf_iterator) (ostreambuf_iterator): Likewise. * include/std/ranges (views::single, views::iota, views::all) (views::filter, views::transform, views::take, views::take_while) (views::drop, views::drop_while, views::join, views::lazy_split) (views::split, views::counted, views::common, views::reverse) (views::elements): Likewise. * testsuite/20_util/rel_ops.cc: Use -Wno-unused-result. * testsuite/24_iterators/move_iterator/greedy_ops.cc: Likewise. * testsuite/24_iterators/normal_iterator/greedy_ops.cc: Likewise. * testsuite/24_iterators/reverse_iterator/2.cc: Likewise. * testsuite/24_iterators/reverse_iterator/greedy_ops.cc: Likewise. * testsuite/21_strings/basic_string/range_access/char/1.cc: Cast result to void. * testsuite/21_strings/basic_string/range_access/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/range_access/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc: Likewise. * testsuite/23_containers/array/range_access.cc: Likewise. * testsuite/23_containers/deque/range_access.cc: Likewise. * testsuite/23_containers/forward_list/range_access.cc: Likewise. * testsuite/23_containers/list/range_access.cc: Likewise. * testsuite/23_containers/map/range_access.cc: Likewise. * testsuite/23_containers/multimap/range_access.cc: Likewise. * testsuite/23_containers/multiset/range_access.cc: Likewise. * testsuite/23_containers/set/range_access.cc: Likewise. * testsuite/23_containers/unordered_map/range_access.cc: Likewise. * testsuite/23_containers/unordered_multimap/range_access.cc: Likewise. * testsuite/23_containers/unordered_multiset/range_access.cc: Likewise. * testsuite/23_containers/unordered_set/range_access.cc: Likewise. * testsuite/23_containers/vector/range_access.cc: Likewise. * testsuite/24_iterators/customization_points/iter_move.cc: Likewise. * testsuite/24_iterators/istream_iterator/sentinel.cc: Likewise. * testsuite/24_iterators/istreambuf_iterator/sentinel.cc: Likewise. * testsuite/24_iterators/move_iterator/dr2061.cc: Likewise. * testsuite/24_iterators/operations/prev_neg.cc: Likewise. * testsuite/24_iterators/ostreambuf_iterator/2.cc: Likewise. * testsuite/24_iterators/range_access/range_access.cc: Likewise. * testsuite/24_iterators/range_operations/100768.cc: Likewise. * testsuite/26_numerics/valarray/range_access2.cc: Likewise. * testsuite/28_regex/range_access.cc: Likewise. * testsuite/experimental/string_view/range_access/char/1.cc: Likewise. * testsuite/experimental/string_view/range_access/wchar_t/1.cc: Likewise. * testsuite/ext/vstring/range_access.cc: Likewise. * testsuite/std/ranges/adaptors/take.cc: Likewise. * testsuite/std/ranges/p2259.cc: Likewise. diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index 9c28ebfb345..739017aaaad 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -120,6 +120,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __type = typename __result<_Tp>::type; template + [[nodiscard]] constexpr __type<_Tp> operator()(_Tp&& __e) const noexcept(_S_noexcept<_Tp>()) diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h index 71ad28c3ab0..ab2d4f8652c 100644 --- a/libstdc++-v3/include/bits/range_access.h +++ b/libstdc++-v3/include/bits/range_access.h @@ -47,6 +47,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto begin(_Container& __cont) -> decltype(__cont.begin()) { return __cont.begin(); } @@ -57,6 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto begin(const _Container& __cont) -> decltype(__cont.begin()) { return __cont.begin(); } @@ -67,6 +69,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto end(_Container& __cont) -> decltype(__cont.end()) { return __cont.end(); } @@ -77,6 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto end(const _Container& __cont) -> decltype(__cont.end()) { return __cont.end(); } @@ -86,6 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template + [[__nodiscard__]] inline _GLIBCXX14_CONSTEXPR _Tp* begin(_Tp (&__arr)[_Nm]) noexcept { return __arr; } @@ -96,6 +101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template + [[__nodiscard__]] inline _GLIBCXX14_CONSTEXPR _Tp* end(_Tp (&__arr)[_Nm]) noexcept { return __arr + _Nm; } @@ -115,6 +121,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline constexpr auto cbegin(const _Container& __cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont)) @@ -126,6 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline constexpr auto cend(const _Container& __cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont)) @@ -137,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rbegin(_Container& __cont) -> decltype(__cont.rbegin()) { return __cont.rbegin(); } @@ -147,6 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rbegin(const _Container& __cont) -> decltype(__cont.rbegin()) { return __cont.rbegin(); } @@ -157,6 +167,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rend(_Container& __cont) -> decltype(__cont.rend()) { return __cont.rend(); } @@ -167,6 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto rend(const _Container& __cont) -> decltype(__cont.rend()) { return __cont.rend(); } @@ -177,6 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*> rbegin(_Tp (&__arr)[_Nm]) noexcept { return reverse_iterator<_Tp*>(__arr + _Nm); } @@ -187,6 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __arr Array. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*> rend(_Tp (&__arr)[_Nm]) noexcept { return reverse_iterator<_Tp*>(__arr); } @@ -197,6 +211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il initializer_list. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator rbegin(initializer_list<_Tp> __il) noexcept { return reverse_iterator(__il.end()); } @@ -207,6 +222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il initializer_list. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator rend(initializer_list<_Tp> __il) noexcept { return reverse_iterator(__il.begin()); } @@ -217,6 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont)) { return std::rbegin(__cont); } @@ -227,6 +244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto crend(const _Container& __cont) -> decltype(std::rend(__cont)) { return std::rend(__cont); } @@ -241,6 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[nodiscard]] constexpr auto size(const _Container& __cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size()) @@ -250,6 +269,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @brief Return the size of an array. */ template + [[nodiscard]] constexpr size_t size(const _Tp (&)[_Nm]) noexcept { return _Nm; } @@ -286,6 +306,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[nodiscard]] constexpr auto data(_Container& __cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data()) @@ -296,6 +317,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __cont Container. */ template + [[nodiscard]] constexpr auto data(const _Container& __cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data()) @@ -306,6 +328,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __array Array. */ template + [[nodiscard]] constexpr _Tp* data(_Tp (&__array)[_Nm]) noexcept { return __array; } @@ -315,6 +338,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __il Initializer list. */ template + [[nodiscard]] constexpr const _Tp* data(initializer_list<_Tp> __il) noexcept { return __il.begin(); } @@ -322,6 +346,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L #define __cpp_lib_ssize 201902L template + [[nodiscard]] constexpr auto ssize(const _Container& __cont) noexcept(noexcept(__cont.size())) @@ -332,6 +357,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[nodiscard]] constexpr ptrdiff_t ssize(const _Tp (&)[_Num]) noexcept { return _Num; } diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index 9d749c8d9b7..614b6edf9df 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -110,6 +110,7 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires is_array_v> || __member_begin<_Tp> || __adl_begin<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -161,6 +162,7 @@ namespace ranges template<__maybe_borrowed_range _Tp> requires is_bounded_array_v> || __member_end<_Tp> || __adl_end<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -192,6 +194,7 @@ namespace ranges struct _CBegin { template + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_Begin{}(__cust_access::__as_const<_Tp>(__e)))) @@ -204,6 +207,7 @@ namespace ranges struct _CEnd final { template + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_End{}(__cust_access::__as_const<_Tp>(__e)))) @@ -263,6 +267,7 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_rbegin<_Tp> || __adl_rbegin<_Tp> || __reversable<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) @@ -321,6 +326,7 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_rend<_Tp> || __adl_rend<_Tp> || __reversable<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) @@ -337,6 +343,7 @@ namespace ranges struct _CRBegin { template + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_RBegin{}(__cust_access::__as_const<_Tp>(__e)))) @@ -349,6 +356,7 @@ namespace ranges struct _CREnd { template + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_REnd{}(__cust_access::__as_const<_Tp>(__e)))) @@ -408,6 +416,7 @@ namespace ranges template requires is_bounded_array_v> || __member_size<_Tp> || __adl_size<_Tp> || __sentinel_size<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -428,6 +437,7 @@ namespace ranges // 3403. Domain of ranges::ssize(E) doesn't match ranges::size(E) template requires requires (_Tp& __t) { _Size{}(__t); } + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(_Size{}(__t))) { @@ -487,6 +497,7 @@ namespace ranges template requires __member_empty<_Tp> || __size0_empty<_Tp> || __eq_iter_empty<_Tp> + [[nodiscard]] constexpr bool operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>()) { @@ -528,6 +539,7 @@ namespace ranges public: template<__maybe_borrowed_range _Tp> requires __member_data<_Tp> || __begin_data<_Tp> + [[nodiscard]] constexpr auto operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>()) { @@ -541,6 +553,7 @@ namespace ranges struct _CData { template + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(_Data{}(__cust_access::__as_const<_Tp>(__e)))) @@ -782,6 +795,7 @@ namespace ranges struct __distance_fn final { template _Sent> + [[nodiscard]] constexpr iter_difference_t<_It> operator()(_It __first, _Sent __last) const { @@ -800,6 +814,7 @@ namespace ranges } template + [[nodiscard]] constexpr range_difference_t<_Range> operator()(_Range&& __r) const { @@ -817,6 +832,7 @@ namespace ranges struct __next_fn final { template + [[nodiscard]] constexpr _It operator()(_It __x) const { @@ -825,6 +841,7 @@ namespace ranges } template + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n) const { @@ -833,6 +850,7 @@ namespace ranges } template _Sent> + [[nodiscard]] constexpr _It operator()(_It __x, _Sent __bound) const { @@ -841,6 +859,7 @@ namespace ranges } template _Sent> + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n, _Sent __bound) const { @@ -856,6 +875,7 @@ namespace ranges struct __prev_fn final { template + [[nodiscard]] constexpr _It operator()(_It __x) const { @@ -864,6 +884,7 @@ namespace ranges } template + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n) const { @@ -872,6 +893,7 @@ namespace ranges } template + [[nodiscard]] constexpr _It operator()(_It __x, iter_difference_t<_It> __n, _It __bound) const { diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 7fe727d8093..3773d600b8f 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -223,6 +223,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /** * @return @c current, the %iterator used for underlying work. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR iterator_type base() const { return current; } @@ -237,6 +238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @c *x remains valid after @c x has been modified or * destroyed. This is a bug: http://gcc.gnu.org/PR51823 */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reference operator*() const { @@ -249,6 +251,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * This requires that @c --current is dereferenceable. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR pointer operator->() const #if __cplusplus > 201703L && __cpp_concepts >= 201907L @@ -318,6 +321,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reverse_iterator operator+(difference_type __n) const { return reverse_iterator(current - __n); } @@ -340,6 +344,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reverse_iterator operator-(difference_type __n) const { return reverse_iterator(current + __n); } @@ -362,11 +367,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The underlying iterator must be a Random Access Iterator. */ + _GLIBCXX_NODISCARD _GLIBCXX17_CONSTEXPR reference operator[](difference_type __n) const { return *(*this + __n); } #if __cplusplus > 201703L && __cpp_lib_concepts + [[nodiscard]] friend constexpr iter_rvalue_reference_t<_Iterator> iter_move(const reverse_iterator& __i) noexcept(is_nothrow_copy_constructible_v<_Iterator> @@ -415,36 +422,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ #if __cplusplus <= 201703L || ! defined __cpp_lib_concepts template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator==(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __x.base() == __y.base(); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator<(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y.base() < __x.base(); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator!=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__x == __y); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y < __x; } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator<=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__y < __x); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) @@ -454,24 +467,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 280. Comparison of reverse_iterator to const reverse_iterator. template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator==(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() == __y.base(); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator<(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() > __y.base(); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator!=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() != __y.base(); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -484,12 +501,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() >= __y.base(); } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR bool operator>=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) { return __x.base() <= __y.base(); } #else // C++20 template + [[nodiscard]] constexpr bool operator==(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -497,6 +516,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() == __y.base(); } template + [[nodiscard]] constexpr bool operator!=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -504,6 +524,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() != __y.base(); } template + [[nodiscard]] constexpr bool operator<(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -511,6 +532,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() > __y.base(); } template + [[nodiscard]] constexpr bool operator>(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -518,6 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() < __y.base(); } template + [[nodiscard]] constexpr bool operator<=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -525,6 +548,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() >= __y.base(); } template + [[nodiscard]] constexpr bool operator>=(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -533,6 +557,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _IteratorR> + [[nodiscard]] constexpr compare_three_way_result_t<_IteratorL, _IteratorR> operator<=>(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -556,6 +581,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 685. reverse_iterator/move_iterator difference has invalid signatures template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto operator-(const reverse_iterator<_IteratorL>& __x, const reverse_iterator<_IteratorR>& __y) @@ -564,6 +590,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> operator+(typename reverse_iterator<_Iterator>::difference_type __n, const reverse_iterator<_Iterator>& __x) @@ -583,6 +610,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 2285. make_reverse_iterator /// Generator function for reverse_iterator. template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator> make_reverse_iterator(_Iterator __i) { return reverse_iterator<_Iterator>(__i); } @@ -683,7 +711,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// Simply returns *this. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR back_insert_iterator& operator*() { return *this; } @@ -713,7 +741,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * types for you. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline back_insert_iterator<_Container> back_inserter(_Container& __x) { return back_insert_iterator<_Container>(__x); } @@ -784,7 +812,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// Simply returns *this. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR front_insert_iterator& operator*() { return *this; } @@ -814,7 +842,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * types for you. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline front_insert_iterator<_Container> front_inserter(_Container& __x) { return front_insert_iterator<_Container>(__x); } @@ -914,7 +942,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// Simply returns *this. - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR insert_iterator& operator*() { return *this; } @@ -946,11 +974,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ #if __cplusplus > 201703L && defined __cpp_lib_concepts template + [[nodiscard]] constexpr insert_iterator<_Container> inserter(_Container& __x, std::__detail::__range_iter_t<_Container> __i) { return insert_iterator<_Container>(__x, __i); } #else template + _GLIBCXX_NODISCARD inline insert_iterator<_Container> inserter(_Container& __x, typename _Container::iterator __i) { return insert_iterator<_Container>(__x, __i); } @@ -1090,6 +1120,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template requires requires (_IteratorL __lhs, _IteratorR __rhs) { { __lhs == __rhs } -> std::convertible_to; } + [[nodiscard]] constexpr bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1097,6 +1128,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() == __rhs.base(); } template + [[nodiscard]] constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL> operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1105,7 +1137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #else // Forward iterator requirements template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1113,7 +1145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() == __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator==(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1121,7 +1153,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() == __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1129,7 +1161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() != __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1138,6 +1170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Random access iterator requirements template + _GLIBCXX_NODISCARD inline bool operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1145,7 +1178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() < __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator<(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1153,6 +1186,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() < __rhs.base(); } template + _GLIBCXX_NODISCARD inline bool operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1160,7 +1194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() > __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator>(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1168,6 +1202,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() > __rhs.base(); } template + _GLIBCXX_NODISCARD inline bool operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1175,7 +1210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() <= __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator<=(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1183,6 +1218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() <= __rhs.base(); } template + _GLIBCXX_NODISCARD inline bool operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) @@ -1190,7 +1226,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() >= __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool operator>=(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1205,7 +1241,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template #if __cplusplus >= 201103L // DR 685. - _GLIBCXX20_CONSTEXPR + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline auto operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept @@ -1218,7 +1254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() - __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline typename __normal_iterator<_Iterator, _Container>::difference_type operator-(const __normal_iterator<_Iterator, _Container>& __lhs, const __normal_iterator<_Iterator, _Container>& __rhs) @@ -1226,7 +1262,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __lhs.base() - __rhs.base(); } template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline __normal_iterator<_Iterator, _Container> operator+(typename __normal_iterator<_Iterator, _Container>::difference_type __n, const __normal_iterator<_Iterator, _Container>& __i) @@ -1284,6 +1320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr _Sent base() const noexcept(is_nothrow_copy_constructible_v<_Sent>) @@ -1397,19 +1434,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #if __cplusplus <= 201703L + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR iterator_type base() const { return _M_current; } #else + [[nodiscard]] constexpr const iterator_type& base() const & noexcept { return _M_current; } + [[nodiscard]] constexpr iterator_type base() && { return std::move(_M_current); } #endif + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference operator*() const #if __cplusplus > 201703L && __cpp_lib_concepts @@ -1418,6 +1459,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return static_cast(*_M_current); } #endif + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR pointer operator->() const { return _M_current; } @@ -1458,6 +1500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __tmp; } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR move_iterator operator+(difference_type __n) const { return move_iterator(_M_current + __n); } @@ -1469,6 +1512,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR move_iterator operator-(difference_type __n) const { return move_iterator(_M_current - __n); } @@ -1480,6 +1524,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference operator[](difference_type __n) const #if __cplusplus > 201703L && __cpp_lib_concepts @@ -1490,20 +1535,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L && __cpp_lib_concepts template _Sent> + [[nodiscard]] friend constexpr bool operator==(const move_iterator& __x, const move_sentinel<_Sent>& __y) { return __x.base() == __y.base(); } template _Sent> + [[nodiscard]] friend constexpr iter_difference_t<_Iterator> operator-(const move_sentinel<_Sent>& __x, const move_iterator& __y) { return __x.base() - __y.base(); } template _Sent> + [[nodiscard]] friend constexpr iter_difference_t<_Iterator> operator-(const move_iterator& __x, const move_sentinel<_Sent>& __y) { return __x.base() - __y.base(); } + [[nodiscard]] friend constexpr iter_rvalue_reference_t<_Iterator> iter_move(const move_iterator& __i) noexcept(noexcept(ranges::iter_move(__i._M_current))) @@ -1518,6 +1567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator==(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1529,12 +1579,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_lib_three_way_comparison template _IteratorR> + [[__nodiscard__]] constexpr compare_three_way_result_t<_IteratorL, _IteratorR> operator<=>(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __x.base() <=> __y.base(); } #else template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator!=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1542,6 +1594,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1551,6 +1604,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() < __y.base(); } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1560,6 +1614,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return !(__y < __x); } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1569,6 +1624,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __y < __x; } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1586,36 +1642,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // prefer them to greedy unconstrained function templates. template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator==(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __x.base() == __y.base(); } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator!=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return !(__x == __y); } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __x.base() < __y.base(); } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator<=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return !(__y < __x); } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) { return __y < __x; } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR bool operator>=(const move_iterator<_Iterator>& __x, const move_iterator<_Iterator>& __y) @@ -1624,6 +1686,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 685. template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR auto operator-(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) @@ -1631,12 +1694,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __x.base() - __y.base(); } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> operator+(typename move_iterator<_Iterator>::difference_type __n, const move_iterator<_Iterator>& __x) { return __x + __n; } template + [[__nodiscard__]] inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator> make_move_iterator(_Iterator __i) { return move_iterator<_Iterator>(std::move(__i)); } @@ -1857,6 +1922,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } + [[nodiscard]] decltype(auto) operator*() { @@ -1864,6 +1930,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_it; } + [[nodiscard]] decltype(auto) operator*() const requires __detail::__dereferenceable { @@ -1871,6 +1938,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_it; } + [[nodiscard]] decltype(auto) operator->() const requires __detail::__common_iter_has_arrow<_It> { @@ -1916,6 +1984,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _Sent2> requires sentinel_for<_Sent, _It2> + [[nodiscard]] friend bool operator==(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) @@ -1938,6 +2007,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _Sent2> requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2> + [[nodiscard]] friend bool operator==(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) @@ -1961,6 +2031,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _It2, sized_sentinel_for<_It> _Sent2> requires sized_sentinel_for<_Sent, _It2> + [[nodiscard]] friend iter_difference_t<_It2> operator-(const common_iterator& __x, const common_iterator<_It2, _Sent2>& __y) @@ -1982,6 +2053,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } + [[nodiscard]] friend iter_rvalue_reference_t<_It> iter_move(const common_iterator& __i) noexcept(noexcept(ranges::iter_move(std::declval()))) @@ -2132,18 +2204,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr const _It& base() const & noexcept { return _M_current; } + [[nodiscard]] constexpr _It base() && noexcept(is_nothrow_move_constructible_v<_It>) { return std::move(_M_current); } + [[nodiscard]] constexpr iter_difference_t<_It> count() const noexcept { return _M_length; } + [[nodiscard]] constexpr decltype(auto) operator*() noexcept(noexcept(*_M_current)) @@ -2152,6 +2228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_current; } + [[nodiscard]] constexpr decltype(auto) operator*() const noexcept(noexcept(*_M_current)) @@ -2161,6 +2238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *_M_current; } + [[nodiscard]] constexpr auto operator->() const noexcept requires contiguous_iterator<_It> @@ -2214,11 +2292,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __tmp; } + [[nodiscard]] constexpr counted_iterator operator+(iter_difference_t<_It> __n) const requires random_access_iterator<_It> { return counted_iterator(_M_current + __n, _M_length - __n); } + [[nodiscard]] friend constexpr counted_iterator operator+(iter_difference_t<_It> __n, const counted_iterator& __x) requires random_access_iterator<_It> @@ -2234,21 +2314,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr counted_iterator operator-(iter_difference_t<_It> __n) const requires random_access_iterator<_It> { return counted_iterator(_M_current - __n, _M_length + __n); } template _It2> + [[nodiscard]] friend constexpr iter_difference_t<_It2> operator-(const counted_iterator& __x, const counted_iterator<_It2>& __y) { return __y._M_length - __x._M_length; } + [[nodiscard]] friend constexpr iter_difference_t<_It> operator-(const counted_iterator& __x, default_sentinel_t) { return -__x._M_length; } + [[nodiscard]] friend constexpr iter_difference_t<_It> operator-(default_sentinel_t, const counted_iterator& __y) { return __y._M_length; } @@ -2263,6 +2347,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + [[nodiscard]] constexpr decltype(auto) operator[](iter_difference_t<_It> __n) const noexcept(noexcept(_M_current[__n])) @@ -2273,21 +2358,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template _It2> + [[nodiscard]] friend constexpr bool operator==(const counted_iterator& __x, const counted_iterator<_It2>& __y) { return __x._M_length == __y._M_length; } + [[nodiscard]] friend constexpr bool operator==(const counted_iterator& __x, default_sentinel_t) { return __x._M_length == 0; } template _It2> + [[nodiscard]] friend constexpr strong_ordering operator<=>(const counted_iterator& __x, const counted_iterator<_It2>& __y) { return __y._M_length <=> __x._M_length; } + [[nodiscard]] friend constexpr iter_rvalue_reference_t<_It> iter_move(const counted_iterator& __i) noexcept(noexcept(ranges::iter_move(__i._M_current))) diff --git a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h index fa8474f23c6..e5afab7f4fd 100644 --- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h +++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h @@ -133,6 +133,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER * and are constant time. For other %iterator classes they are linear time. */ template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR typename iterator_traits<_InputIterator>::difference_type distance(_InputIterator __first, _InputIterator __last) @@ -209,6 +210,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER #if __cplusplus >= 201103L template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR _InputIterator next(_InputIterator __x, typename iterator_traits<_InputIterator>::difference_type __n = 1) @@ -220,6 +222,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER } template + _GLIBCXX_NODISCARD inline _GLIBCXX17_CONSTEXPR _BidirectionalIterator prev(_BidirectionalIterator __x, typename iterator_traits<_BidirectionalIterator>::difference_type __n = 1) diff --git a/libstdc++-v3/include/bits/stream_iterator.h b/libstdc++-v3/include/bits/stream_iterator.h index d07474d4996..d74c158f342 100644 --- a/libstdc++-v3/include/bits/stream_iterator.h +++ b/libstdc++-v3/include/bits/stream_iterator.h @@ -89,6 +89,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~istream_iterator() = default; #endif + _GLIBCXX_NODISCARD const _Tp& operator*() const { @@ -98,6 +99,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _M_value; } + _GLIBCXX_NODISCARD const _Tp* operator->() const { return std::__addressof((operator*())); } @@ -143,17 +145,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Return true if the iterators refer to the same stream, /// or are both at end-of-stream. + _GLIBCXX_NODISCARD friend bool operator==(const istream_iterator& __x, const istream_iterator& __y) { return __x._M_equal(__y); } +#if __cpp_impl_three_way_comparison < 201907L /// Return true if the iterators refer to different streams, /// or if one is at end-of-stream and the other is not. + _GLIBCXX_NODISCARD friend bool operator!=(const istream_iterator& __x, const istream_iterator& __y) { return !__x._M_equal(__y); } +#endif #if __cplusplus > 201703L && __cpp_lib_concepts + [[nodiscard]] friend bool operator==(const istream_iterator& __i, default_sentinel_t) { return !__i._M_stream; } @@ -231,6 +238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } + _GLIBCXX_NODISCARD ostream_iterator& operator*() { return *this; } diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index cda596af40f..0a77d1a3da4 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -141,6 +141,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Return the current character pointed to by iterator. This returns /// streambuf.sgetc(). It cannot be assigned. NB: The result of /// operator*() on an end of stream is undefined. + _GLIBCXX_NODISCARD char_type operator*() const { @@ -189,6 +190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 110 istreambuf_iterator::equal not const // NB: there is also number 111 (NAD) relevant to this function. /// Return true both iterators are end or both are not end. + _GLIBCXX_NODISCARD bool equal(const istreambuf_iterator& __b) const { return _M_at_eof() == __b._M_at_eof(); } @@ -215,6 +217,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #if __cplusplus > 201703L && __cpp_lib_concepts + [[nodiscard]] friend bool operator==(const istreambuf_iterator& __i, default_sentinel_t __s) { return __i._M_at_eof(); } @@ -222,16 +225,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template + _GLIBCXX_NODISCARD inline bool operator==(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) { return __a.equal(__b); } +#if __cpp_impl_three_way_comparison < 201907L template + _GLIBCXX_NODISCARD inline bool operator!=(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) { return !__a.equal(__b); } +#endif /// Provides output iterator semantics for streambufs. template @@ -288,6 +295,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } /// Return *this. + _GLIBCXX_NODISCARD ostreambuf_iterator& operator*() { return *this; } @@ -303,6 +311,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return *this; } /// Return true if previous operator=() failed. + _GLIBCXX_NODISCARD bool failed() const _GLIBCXX_USE_NOEXCEPT { return _M_failed; } diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 5bdcd445a9e..03a3778bb52 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -645,6 +645,7 @@ namespace views struct _Single { template + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const noexcept(noexcept(single_view>(std::forward<_Tp>(__e)))) @@ -656,11 +657,13 @@ namespace views struct _Iota { template + [[nodiscard]] constexpr auto operator()(_Tp&& __e) const { return iota_view(std::forward<_Tp>(__e)); } template + [[nodiscard]] constexpr auto operator()(_Tp&& __e, _Up&& __f) const { return iota_view(std::forward<_Tp>(__e), std::forward<_Up>(__f)); } @@ -1123,6 +1126,7 @@ namespace views::__adaptor requires view> || __detail::__can_ref_view<_Range> || __detail::__can_subrange<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const noexcept(_S_noexcept<_Range>()) @@ -1549,6 +1553,7 @@ namespace views::__adaptor { template requires __detail::__can_filter_view<_Range, _Pred> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const { @@ -1926,6 +1931,7 @@ namespace views::__adaptor { template requires __detail::__can_transform_view<_Range, _Fp> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Fp&& __f) const { @@ -2107,6 +2113,7 @@ namespace views::__adaptor { template requires __detail::__can_take_view<_Range, _Tp> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Tp&& __n) const { @@ -2234,6 +2241,7 @@ namespace views::__adaptor { template requires __detail::__can_take_while_view<_Range, _Pred> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const { @@ -2354,6 +2362,7 @@ namespace views::__adaptor { template requires __detail::__can_drop_view<_Range, _Tp> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Tp&& __n) const { @@ -2442,6 +2451,7 @@ namespace views::__adaptor { template requires __detail::__can_drop_while_view<_Range, _Pred> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pred&& __p) const { @@ -2804,6 +2814,7 @@ namespace views::__adaptor { template requires __detail::__can_join_view<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { @@ -3255,6 +3266,7 @@ namespace views::__adaptor { template requires __detail::__can_lazy_split_view<_Range, _Pattern> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pattern&& __f) const { @@ -3463,6 +3475,7 @@ namespace views::__adaptor { template requires __detail::__can_split_view<_Range, _Pattern> + [[nodiscard]] constexpr auto operator()(_Range&& __r, _Pattern&& __f) const { @@ -3484,6 +3497,7 @@ namespace views::__adaptor struct _Counted { template + [[nodiscard]] constexpr auto operator()(_Iter __i, iter_difference_t<_Iter> __n) const { @@ -3605,6 +3619,7 @@ namespace views::__adaptor template requires __detail::__already_common<_Range> || __detail::__can_common_view<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { @@ -3727,6 +3742,7 @@ namespace views::__adaptor requires __detail::__is_reverse_view> || __detail::__is_reversible_subrange> || __detail::__can_reverse_view<_Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { @@ -4125,6 +4141,7 @@ namespace views::__adaptor { template requires __detail::__can_elements_view<_Nm, _Range> + [[nodiscard]] constexpr auto operator()(_Range&& __r) const { diff --git a/libstdc++-v3/testsuite/20_util/rel_ops.cc b/libstdc++-v3/testsuite/20_util/rel_ops.cc index 4726462e64e..dd2c14650ae 100644 --- a/libstdc++-v3/testsuite/20_util/rel_ops.cc +++ b/libstdc++-v3/testsuite/20_util/rel_ops.cc @@ -17,6 +17,8 @@ // with this library; see the file COPYING3. If not see // . +// { dg-options "-Wno-unused-result" } + // 20.2.1 Operators #include diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc index 90574d2a811..d37b1cb4c4e 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/char/1.cc @@ -25,6 +25,6 @@ void test01() { std::string s("Hello, World!"); - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc index beab3110ca2..56169150089 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/range_access/wchar_t/1.cc @@ -26,7 +26,7 @@ test01() { #ifdef _GLIBCXX_USE_WCHAR_T std::wstring ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); + (void) std::begin(ws); + (void) std::end(ws); #endif } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc index 856aafde552..4a3595663b8 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/char/1.cc @@ -25,10 +25,10 @@ void test01() { std::string_view s("Hello, World!"); - std::begin(s); - std::end(s); - std::rbegin(s); - std::rend(s); + (void) std::begin(s); + (void) std::end(s); + (void) std::rbegin(s); + (void) std::rend(s); } void diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc index c6d83c47bfd..f8ecd1a84cd 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc @@ -25,10 +25,10 @@ void test01() { std::wstring_view ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); - std::rbegin(ws); - std::rend(ws); + (void) std::begin(ws); + (void) std::end(ws); + (void) std::rbegin(ws); + (void) std::rend(ws); } void diff --git a/libstdc++-v3/testsuite/23_containers/array/range_access.cc b/libstdc++-v3/testsuite/23_containers/array/range_access.cc index 38116888a6c..807ccdb2b01 100644 --- a/libstdc++-v3/testsuite/23_containers/array/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/array/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::array a{{1, 2, 3}}; - std::begin(a); - std::end(a); + (void) std::begin(a); + (void) std::end(a); } diff --git a/libstdc++-v3/testsuite/23_containers/deque/range_access.cc b/libstdc++-v3/testsuite/23_containers/deque/range_access.cc index fed56a48414..990fc0d573b 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::deque d{1, 2, 3}; - std::begin(d); - std::end(d); + (void) std::begin(d); + (void) std::end(d); } diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc b/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc index 0b70ff02131..6398240e126 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::forward_list fl{1, 2, 3}; - std::begin(fl); - std::end(fl); + (void) std::begin(fl); + (void) std::end(fl); } diff --git a/libstdc++-v3/testsuite/23_containers/list/range_access.cc b/libstdc++-v3/testsuite/23_containers/list/range_access.cc index de845d446f0..15047ec755d 100644 --- a/libstdc++-v3/testsuite/23_containers/list/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/list/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::list l{1, 2, 3}; - std::begin(l); - std::end(l); + (void) std::begin(l); + (void) std::end(l); } diff --git a/libstdc++-v3/testsuite/23_containers/map/range_access.cc b/libstdc++-v3/testsuite/23_containers/map/range_access.cc index dc0bdbb9a74..3c6b00128ca 100644 --- a/libstdc++-v3/testsuite/23_containers/map/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/map/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::map m{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(m); - std::end(m); + (void) std::begin(m); + (void) std::end(m); } diff --git a/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc b/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc index 32ffa3b2651..020a7a9e627 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::multimap mm{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(mm); - std::end(mm); + (void) std::begin(mm); + (void) std::end(mm); } diff --git a/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc b/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc index 2d08ba40a59..7e66bfa24aa 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::multiset ms{1, 2, 3}; - std::begin(ms); - std::end(ms); + (void) std::begin(ms); + (void) std::end(ms); } diff --git a/libstdc++-v3/testsuite/23_containers/set/range_access.cc b/libstdc++-v3/testsuite/23_containers/set/range_access.cc index 35703e2a7be..66099b39df4 100644 --- a/libstdc++-v3/testsuite/23_containers/set/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/set/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::set s{1, 2, 3}; - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc index edb06d06894..ad20c1da942 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_map um{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(um); - std::end(um); + (void) std::begin(um); + (void) std::end(um); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc index e19e825a042..4bb126e34f9 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_multimap umm{{1, 1.0}, {2, 2.0}, {3, 3.0}}; - std::begin(umm); - std::end(umm); + (void) std::begin(umm); + (void) std::end(umm); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc index 574012bee32..899b74af35c 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_multiset ums{1, 2, 3}; - std::begin(ums); - std::end(ums); + (void) std::begin(ums); + (void) std::end(ums); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc index 033653a37ec..4f9e8857113 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc @@ -25,6 +25,6 @@ void test01() { std::unordered_set us{1, 2, 3}; - std::begin(us); - std::end(us); + (void) std::begin(us); + (void) std::end(us); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/range_access.cc b/libstdc++-v3/testsuite/23_containers/vector/range_access.cc index a36975cac72..0dd761b71f1 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/range_access.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/range_access.cc @@ -25,10 +25,10 @@ void test01() { std::vector v{1.0, 2.0, 3.0}; - std::begin(v); - std::end(v); + (void) std::begin(v); + (void) std::end(v); std::vector vb{true, false, true}; - std::begin(vb); - std::end(vb); + (void) std::begin(vb); + (void) std::end(vb); } diff --git a/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc b/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc index a43448581f3..40a084b918c 100644 --- a/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc +++ b/libstdc++-v3/testsuite/24_iterators/customization_points/iter_move.cc @@ -51,7 +51,7 @@ constexpr bool test_X(int i, int j) { X x1{i}, x2{j}; - std::ranges::iter_move(&x1); // no-op + (void) std::ranges::iter_move(&x1); // no-op x1 = std::ranges::iter_move(&x2); return x1.value == j && x2.value == -1; } diff --git a/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc b/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc index 7e1fd173877..f8f16375bf0 100644 --- a/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc +++ b/libstdc++-v3/testsuite/24_iterators/istream_iterator/sentinel.cc @@ -43,9 +43,9 @@ test02() VERIFY( iter != std::default_sentinel ); VERIFY( std::default_sentinel != iter ); - *iter++; - *iter++; - *iter++; + (void) *iter++; + (void) *iter++; + (void) *iter++; VERIFY( iter == std::default_sentinel ); VERIFY( std::default_sentinel == iter ); } diff --git a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc index 4961ddaf793..b7cdd44677d 100644 --- a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc +++ b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/sentinel.cc @@ -41,7 +41,7 @@ test02() VERIFY( iter != std::default_sentinel ); VERIFY( std::default_sentinel != iter ); - std::next(iter, 3); + (void) std::next(iter, 3); VERIFY( iter == std::default_sentinel ); VERIFY( std::default_sentinel == iter ); } diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc index 0af4b16b7f4..c9bd3d677e5 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/dr2061.cc @@ -23,6 +23,6 @@ void test01() { int a[] = { 1, 2, 3, 4 }; - std::make_move_iterator(a + 4); - std::make_move_iterator(a); + (void) std::make_move_iterator(a + 4); + (void) std::make_move_iterator(a); } diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc index 93b3d7dbcd4..ce50e34a5a6 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc @@ -1,4 +1,6 @@ // { dg-do compile { target c++11 } } +// { dg-options "-Wno-unused-result" } + // Copyright (C) 2010-2021 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free diff --git a/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc index 557dfacbf24..29ff7266d07 100644 --- a/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc +++ b/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc @@ -1,4 +1,6 @@ // { dg-do compile } +// { dg-options "-Wno-unused-result" } + // Copyright (C) 2010-2021 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -33,7 +35,7 @@ void test01() greedy_ops::C> iterator_type; iterator_type it(0); - + it == it; it != it; it < it; @@ -45,8 +47,8 @@ void test01() 1 + it; } -int main() -{ +int main() +{ test01(); return 0; } diff --git a/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc b/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc index 1d421bbcb2d..cafafc4b651 100644 --- a/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc +++ b/libstdc++-v3/testsuite/24_iterators/operations/prev_neg.cc @@ -37,6 +37,6 @@ void test02() { const Y array[1] = { }; - std::prev(array + 1); + (void) std::prev(array + 1); // { dg-error "forward_iterator" "" { target *-*-* } 223 } } diff --git a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc index 847f4352739..a962cd58236 100644 --- a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc +++ b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc @@ -45,7 +45,7 @@ void test02(void) VERIFY( !ostrb_it01.failed() ); ostrb_it01 = 'a'; VERIFY( !ostrb_it01.failed() ); - *ostrb_it01; + (void) *ostrb_it01; VERIFY( !ostrb_it01.failed() ); costreambuf_iter ostrb_it02(0); @@ -53,11 +53,11 @@ void test02(void) ostrb_it02++; ++ostrb_it02; VERIFY( ostrb_it02.failed() ); - *ostrb_it02; + (void) *ostrb_it02; VERIFY( ostrb_it02.failed() ); ostrb_it02 = 'a'; VERIFY( ostrb_it02.failed() ); - + // charT operator*() const // ostreambuf_iterator& operator++(); // ostreambuf_iterator& operator++(int); diff --git a/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc b/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc index b0b379c6ea5..e679f24e75b 100644 --- a/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc +++ b/libstdc++-v3/testsuite/24_iterators/range_access/range_access.cc @@ -25,8 +25,8 @@ void test01() { int arr[3] = {1, 2, 3}; - std::begin(arr); - std::end(arr); + (void) std::begin(arr); + (void) std::end(arr); static_assert( noexcept(std::begin(arr)), "LWG 2280" ); static_assert( noexcept(std::end(arr)), "LWG 2280" ); diff --git a/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc b/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc index bbcfcece5ff..d4deedd82f6 100644 --- a/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc +++ b/libstdc++-v3/testsuite/24_iterators/range_operations/100768.cc @@ -114,15 +114,15 @@ test01() // deleted overloads in namespace ns3 (because it is an associated namespace // and those functions are exact matches for the arguments). using namespace std::ranges; - advance(iter, 1); - advance(iter, 3, sentinel); - distance(iter, sentinel); - distance(range); - next(iter); - next(iter, -1); - next(iter, sentinel); - next(iter, 5, sentinel); - prev(iter); - prev(iter, 0); - prev(iter, 0, sentinel); + (void) advance(iter, 1); + (void) advance(iter, 3, sentinel); + (void) distance(iter, sentinel); + (void) distance(range); + (void) next(iter); + (void) next(iter, -1); + (void) next(iter, sentinel); + (void) next(iter, 5, sentinel); + (void) prev(iter); + (void) prev(iter, 0); + (void) prev(iter, 0, sentinel); } diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc index 633c1426b96..bd8b20d877d 100644 --- a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc @@ -17,6 +17,8 @@ // with this library; see the file COPYING3. If not see // . +// { dg-options "-Wno-unused-result" } + // 24.4.1.2 Reverse iterators #include diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc index 012f0082751..e5e6dd25027 100644 --- a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc @@ -1,4 +1,6 @@ // { dg-do compile } +// { dg-options "-Wno-unused-result" } + // Copyright (C) 2010-2021 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc b/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc index a7ce1332117..cf5418a61d1 100644 --- a/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc +++ b/libstdc++-v3/testsuite/26_numerics/valarray/range_access2.cc @@ -27,9 +27,9 @@ void test01() { std::valarray va{1.0, 2.0, 3.0}; - std::cbegin(va); - std::cend(va); + (void) std::cbegin(va); + (void) std::cend(va); const auto& cva = va; - std::cbegin(cva); - std::cend(cva); + (void) std::cbegin(cva); + (void) std::cend(cva); } diff --git a/libstdc++-v3/testsuite/28_regex/range_access.cc b/libstdc++-v3/testsuite/28_regex/range_access.cc index 46ef3c64391..6baefbfb673 100644 --- a/libstdc++-v3/testsuite/28_regex/range_access.cc +++ b/libstdc++-v3/testsuite/28_regex/range_access.cc @@ -26,6 +26,6 @@ void test01() { std::smatch sm; - std::begin(sm); - std::end(sm); + (void) std::begin(sm); + (void) std::end(sm); } diff --git a/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc b/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc index c750430d6af..1c456920e5b 100644 --- a/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc +++ b/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc @@ -25,6 +25,6 @@ void test01() { std::experimental::string_view s("Hello, World!"); - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); } diff --git a/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc b/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc index 1dd926333c3..f19e455a606 100644 --- a/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc @@ -26,7 +26,7 @@ test01() { #ifdef _GLIBCXX_USE_WCHAR_T std::experimental::wstring_view ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); + (void) std::begin(ws); + (void) std::end(ws); #endif } diff --git a/libstdc++-v3/testsuite/ext/vstring/range_access.cc b/libstdc++-v3/testsuite/ext/vstring/range_access.cc index 8219eeabed1..7b381ffd956 100644 --- a/libstdc++-v3/testsuite/ext/vstring/range_access.cc +++ b/libstdc++-v3/testsuite/ext/vstring/range_access.cc @@ -25,12 +25,12 @@ void test01() { __gnu_cxx::__vstring s("Hello, World!"); - std::begin(s); - std::end(s); + (void) std::begin(s); + (void) std::end(s); #ifdef _GLIBCXX_USE_WCHAR_T __gnu_cxx::__wvstring ws(L"Hello, World!"); - std::begin(ws); - std::end(ws); + (void) std::begin(ws); + (void) std::end(ws); #endif } diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc index 55f74824737..d79d451478d 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/take.cc @@ -62,7 +62,7 @@ test03() int x[] = {0,1,2,3,4,5}; auto is_odd = [] (int i) { return i%2 == 1; }; auto v = x | views::filter(is_odd) | views::take(3); - ranges::begin(v); + (void) ranges::begin(v); using R = decltype(v); static_assert(ranges::view); static_assert(!ranges::sized_range); diff --git a/libstdc++-v3/testsuite/std/ranges/p2259.cc b/libstdc++-v3/testsuite/std/ranges/p2259.cc index 0ec7e21f657..89234e246a0 100644 --- a/libstdc++-v3/testsuite/std/ranges/p2259.cc +++ b/libstdc++-v3/testsuite/std/ranges/p2259.cc @@ -64,7 +64,7 @@ test01() // Verify the changes to common_iterator. only_cxx20_input_range auto v6 = v0 | views::common; - *(v6.begin()++); + (void) *(v6.begin()++); // Verify the changes to iota_view. only_cxx20_input_range auto v8 = ranges::iota_view{v0.begin()}; @@ -77,7 +77,7 @@ test01() static_assert(std::contiguous_iterator); static_assert(std::same_as::iterator_category, std::random_access_iterator_tag>); - i10.operator->(); + (void) i10.operator->(); __iter_without_category auto i11 = std::counted_iterator{v0.begin(), 5}; } From patchwork Wed Aug 4 11:56:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1513404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=m6XV4Wxk; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gfr055Rrpz9sRN for ; Wed, 4 Aug 2021 22:00:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35800394341D for ; Wed, 4 Aug 2021 12:00:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35800394341D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1628078403; bh=Ovs4MqtKGYaf8oXHzjfAo761sT5c7Bcge5XZ1KArDP4=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=m6XV4WxkFOBKVLdJGWfiXMkmIon0rNf8kxu96dfgS8/hSGcSGBbCxxydAAzcNtAj6 W+8mfQ9gi4wEuV1Icc6sdKimpCOohk2+QFHTsz5y5X+ZI527RhLTkVqOCvtweuiv6u 1AKOZfHyBFKoEHRVG/sh7azJEylEaEN7WLO+8nYQ= 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 ESMTP id A7308393D021 for ; Wed, 4 Aug 2021 11:56:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A7308393D021 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-5CibSFGCMFutx-j39nNBpQ-1; Wed, 04 Aug 2021 07:56:38 -0400 X-MC-Unique: 5CibSFGCMFutx-j39nNBpQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C31C3CC63C; Wed, 4 Aug 2021 11:56:37 +0000 (UTC) Received: from localhost (unknown [10.33.36.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFB645FC23; Wed, 4 Aug 2021 11:56:36 +0000 (UTC) Date: Wed, 4 Aug 2021 12:56:36 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 2/2] libstdc++: Add [[nodiscard]] to sequence containers Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-15.1 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" ... and container adaptors. This adds the [[nodiscard]] attribute to functions with no side-effects for the sequence containers and their iterators, and the debug versions of those containers, and the container adaptors, Tested powerpc64le-linux, committed to trunk. commit 0d04fe49239d91787850036599164788f1c87785 Author: Jonathan Wakely Date: Tue Aug 3 20:50:52 2021 libstdc++: Add [[nodiscard]] to sequence containers ... and container adaptors. This adds the [[nodiscard]] attribute to functions with no side-effects for the sequence containers and their iterators, and the debug versions of those containers, and the container adaptors, Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/forward_list.h: Add [[nodiscard]] to functions with no side-effects. * include/bits/stl_bvector.h: Likewise. * include/bits/stl_deque.h: Likewise. * include/bits/stl_list.h: Likewise. * include/bits/stl_queue.h: Likewise. * include/bits/stl_stack.h: Likewise. * include/bits/stl_vector.h: Likewise. * include/debug/deque: Likewise. * include/debug/forward_list: Likewise. * include/debug/list: Likewise. * include/debug/safe_iterator.h: Likewise. * include/debug/vector: Likewise. * include/std/array: Likewise. * testsuite/23_containers/array/creation/3_neg.cc: Use -Wno-unused-result. * testsuite/23_containers/array/debug/back1_neg.cc: Cast result to void. * testsuite/23_containers/array/debug/back2_neg.cc: Likewise. * testsuite/23_containers/array/debug/front1_neg.cc: Likewise. * testsuite/23_containers/array/debug/front2_neg.cc: Likewise. * testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc: Likewise. * testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc: Likewise. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. * testsuite/23_containers/deque/cons/clear_allocator.cc: Cast result to void. * testsuite/23_containers/deque/debug/invalidation/4.cc: Likewise. * testsuite/23_containers/deque/types/1.cc: Use -Wno-unused-result. * testsuite/23_containers/list/types/1.cc: Cast result to void. * testsuite/23_containers/priority_queue/members/7161.cc: Likewise. * testsuite/23_containers/queue/members/7157.cc: Likewise. * testsuite/23_containers/vector/59829.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/types/1.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/types/2.cc: Likewise. * testsuite/23_containers/vector/types/1.cc: Use -Wno-unused-result. diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index e61746848f6..ab6d9389194 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -150,10 +150,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Fwd_list_iterator(_Fwd_list_node_base* __n) noexcept : _M_node(__n) { } + [[__nodiscard__]] reference operator*() const noexcept { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); } + [[__nodiscard__]] pointer operator->() const noexcept { return static_cast<_Node*>(this->_M_node)->_M_valptr(); } @@ -176,6 +178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list iterator equality comparison. */ + [[__nodiscard__]] friend bool operator==(const _Self& __x, const _Self& __y) noexcept { return __x._M_node == __y._M_node; } @@ -184,6 +187,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list iterator inequality comparison. */ + [[__nodiscard__]] friend bool operator!=(const _Self& __x, const _Self& __y) noexcept { return __x._M_node != __y._M_node; } @@ -229,10 +233,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Fwd_list_const_iterator(const iterator& __iter) noexcept : _M_node(__iter._M_node) { } + [[__nodiscard__]] reference operator*() const noexcept { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); } + [[__nodiscard__]] pointer operator->() const noexcept { return static_cast<_Node*>(this->_M_node)->_M_valptr(); } @@ -255,6 +261,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list const_iterator equality comparison. */ + [[__nodiscard__]] friend bool operator==(const _Self& __x, const _Self& __y) noexcept { return __x._M_node == __y._M_node; } @@ -263,6 +270,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /** * @brief Forward list const_iterator inequality comparison. */ + [[__nodiscard__]] friend bool operator!=(const _Self& __x, const _Self& __y) noexcept { return __x._M_node != __y._M_node; } @@ -698,6 +706,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write iterator that points before the first element * in the %forward_list. Iteration is done in ordinary element order. */ + [[__nodiscard__]] iterator before_begin() noexcept { return iterator(&this->_M_impl._M_head); } @@ -707,6 +716,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator before_begin() const noexcept { return const_iterator(&this->_M_impl._M_head); } @@ -715,6 +725,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write iterator that points to the first element * in the %forward_list. Iteration is done in ordinary element order. */ + [[__nodiscard__]] iterator begin() noexcept { return iterator(this->_M_impl._M_head._M_next); } @@ -724,6 +735,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator begin() const noexcept { return const_iterator(this->_M_impl._M_head._M_next); } @@ -733,6 +745,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] iterator end() noexcept { return iterator(nullptr); } @@ -742,6 +755,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator end() const noexcept { return const_iterator(nullptr); } @@ -751,6 +765,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_head._M_next); } @@ -760,6 +775,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %forward_list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbefore_begin() const noexcept { return const_iterator(&this->_M_impl._M_head); } @@ -769,6 +785,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %forward_list. Iteration is done in * ordinary element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(nullptr); } @@ -777,13 +794,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns true if the %forward_list is empty. (Thus begin() would * equal end().) */ - _GLIBCXX_NODISCARD bool + [[__nodiscard__]] + bool empty() const noexcept { return this->_M_impl._M_head._M_next == nullptr; } /** * Returns the largest possible number of elements of %forward_list. */ + [[__nodiscard__]] size_type max_size() const noexcept { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); } @@ -794,6 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the first * element of the %forward_list. */ + [[__nodiscard__]] reference front() { @@ -805,6 +825,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the first * element of the %forward_list. */ + [[__nodiscard__]] const_reference front() const { @@ -1425,6 +1446,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * if corresponding elements compare equal. */ template + [[__nodiscard__]] bool operator==(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly); @@ -1442,6 +1464,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * `<` and `>=` etc. */ template + [[nodiscard]] inline __detail::__synth3way_t<_Tp> operator<=>(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) @@ -1464,6 +1487,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * See std::lexicographical_compare() for how the determination is made. */ template + [[__nodiscard__]] inline bool operator<(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1472,6 +1496,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator== template + [[__nodiscard__]] inline bool operator!=(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1479,6 +1504,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator< template + [[__nodiscard__]] inline bool operator>(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1486,6 +1512,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator< template + [[__nodiscard__]] inline bool operator>=(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) @@ -1493,6 +1520,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator< template + [[__nodiscard__]] inline bool operator<=(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index fadb6615102..a954890ff20 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -83,6 +83,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Bit_reference(const _Bit_reference&) = default; #endif + _GLIBCXX_NODISCARD operator bool() const _GLIBCXX_NOEXCEPT { return !!(*_M_p & _M_mask); } @@ -100,10 +101,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER operator=(const _Bit_reference& __x) _GLIBCXX_NOEXCEPT { return *this = bool(__x); } + _GLIBCXX_NODISCARD bool operator==(const _Bit_reference& __x) const { return bool(*this) == bool(__x); } + _GLIBCXX_NODISCARD bool operator<(const _Bit_reference& __x) const { return !bool(*this) && bool(__x); } @@ -182,11 +185,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_offset = static_cast(__n); } + _GLIBCXX_NODISCARD friend _GLIBCXX20_CONSTEXPR bool operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return __x._M_p == __y._M_p && __x._M_offset == __y._M_offset; } #if __cpp_lib_three_way_comparison + [[nodiscard]] friend constexpr strong_ordering operator<=>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) noexcept @@ -196,6 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __x._M_offset <=> __y._M_offset; } #else + _GLIBCXX_NODISCARD friend bool operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { @@ -203,18 +209,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset); } + _GLIBCXX_NODISCARD friend bool operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return !(__x == __y); } + _GLIBCXX_NODISCARD friend bool operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return __y < __x; } + _GLIBCXX_NODISCARD friend bool operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return !(__y < __x); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { return !(__x < __y); } @@ -247,6 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_const_cast() const { return *this; } + _GLIBCXX_NODISCARD reference operator*() const { return reference(_M_p, 1UL << _M_offset); } @@ -295,10 +306,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return *this; } + _GLIBCXX_NODISCARD reference operator[](difference_type __i) const { return *(*this + __i); } + _GLIBCXX_NODISCARD friend iterator operator+(const iterator& __x, difference_type __n) { @@ -307,10 +320,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend iterator operator+(difference_type __n, const iterator& __x) { return __x + __n; } + _GLIBCXX_NODISCARD friend iterator operator-(const iterator& __x, difference_type __n) { @@ -343,6 +358,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_const_cast() const { return _Bit_iterator(_M_p, _M_offset); } + _GLIBCXX_NODISCARD const_reference operator*() const { return _Bit_reference(_M_p, 1UL << _M_offset); } @@ -391,10 +407,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return *this; } + _GLIBCXX_NODISCARD const_reference operator[](difference_type __i) const { return *(*this + __i); } + _GLIBCXX_NODISCARD friend const_iterator operator+(const const_iterator& __x, difference_type __n) { @@ -403,6 +421,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend const_iterator operator-(const const_iterator& __x, difference_type __n) { @@ -411,6 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend const_iterator operator+(difference_type __n, const const_iterator& __x) { return __x + __n; } @@ -827,60 +847,74 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { _M_assign_aux(__l.begin(), __l.end(), random_access_iterator_tag()); } #endif + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_start._M_p, 0); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_start._M_p, 0); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_start._M_p, 0); } + [[__nodiscard__]] const_iterator cend() const noexcept { return this->_M_impl._M_finish; } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } #endif + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return size_type(end() - begin()); } + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { @@ -893,6 +927,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ? __asize * int(_S_word_bit) : __isize); } + _GLIBCXX_NODISCARD size_type capacity() const _GLIBCXX_NOEXCEPT { return size_type(const_iterator(this->_M_impl._M_end_addr(), 0) @@ -902,10 +937,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER empty() const _GLIBCXX_NOEXCEPT { return begin() == end(); } + _GLIBCXX_NODISCARD reference operator[](size_type __n) { return begin()[__n]; } + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const { return begin()[__n]; } @@ -939,18 +976,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_reallocate(__n); } + _GLIBCXX_NODISCARD reference front() { return *begin(); } + _GLIBCXX_NODISCARD const_reference front() const { return *begin(); } + _GLIBCXX_NODISCARD reference back() { return *(end() - 1); } + _GLIBCXX_NODISCARD const_reference back() const { return *(end() - 1); } diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 20c73b4fc3c..6095498d440 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -176,10 +176,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_const_cast() const _GLIBCXX_NOEXCEPT { return iterator(_M_cur, _M_node); } + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { return *_M_cur; } + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { return _M_cur; } @@ -247,6 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER operator-=(difference_type __n) _GLIBCXX_NOEXCEPT { return *this += -__n; } + _GLIBCXX_NODISCARD reference operator[](difference_type __n) const _GLIBCXX_NOEXCEPT { return *(*this + __n); } @@ -264,6 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_last = _M_first + difference_type(_S_buffer_size()); } + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_cur == __y._M_cur; } @@ -272,6 +276,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // order to avoid ambiguous overload resolution when std::rel_ops // operators are in scope (for additional details, see libstdc++/3628) template + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) @@ -279,6 +284,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return __x._M_cur == __y._M_cur; } #if __cpp_lib_three_way_comparison + [[nodiscard]] friend strong_ordering operator<=>(const _Self& __x, const _Self& __y) noexcept { @@ -287,17 +293,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __x._M_cur <=> __y._M_cur; } #else + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return !(__x == __y); } template + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT { return !(__x == __y); } + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { @@ -306,6 +315,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } template + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) @@ -315,33 +325,39 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); } + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __y < __x; } template + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT { return __y < __x; } + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return !(__y < __x); } template + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT { return !(__y < __x); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return !(__x < __y); } template + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) @@ -349,6 +365,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return !(__x < __y); } #endif // three-way comparison + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { @@ -363,6 +380,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // operators but also operator- must accept mixed iterator/const_iterator // parameters. template + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __x, const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT @@ -373,6 +391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + (__y._M_last - __y._M_cur); } + _GLIBCXX_NODISCARD friend _Self operator+(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { @@ -381,6 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend _Self operator-(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { @@ -389,6 +409,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend _Self operator+(difference_type __n, const _Self& __x) _GLIBCXX_NOEXCEPT { return __x + __n; } @@ -1114,6 +1135,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif /// Get a copy of the memory allocation object. + _GLIBCXX_NODISCARD allocator_type get_allocator() const _GLIBCXX_NOEXCEPT { return _Base::get_allocator(); } @@ -1123,6 +1145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write iterator that points to the first element in the * %deque. Iteration is done in ordinary element order. */ + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return this->_M_impl._M_start; } @@ -1131,6 +1154,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) iterator that points to the first * element in the %deque. Iteration is done in ordinary element order. */ + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_start; } @@ -1140,6 +1164,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %deque. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } @@ -1149,6 +1174,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %deque. Iteration is done in * ordinary element order. */ + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish; } @@ -1158,6 +1184,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * last element in the %deque. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(this->_M_impl._M_finish); } @@ -1167,6 +1194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %deque. Iteration is done in * reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(this->_M_impl._M_finish); } @@ -1176,6 +1204,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * before the first element in the %deque. Iteration is done * in reverse element order. */ + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(this->_M_impl._M_start); } @@ -1185,6 +1214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %deque. Iteration is * done in reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(this->_M_impl._M_start); } @@ -1194,6 +1224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) iterator that points to the first * element in the %deque. Iteration is done in ordinary element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return this->_M_impl._M_start; } @@ -1203,6 +1234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %deque. Iteration is done in * ordinary element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return this->_M_impl._M_finish; } @@ -1212,6 +1244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %deque. Iteration is done in * reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(this->_M_impl._M_finish); } @@ -1221,6 +1254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %deque. Iteration is * done in reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(this->_M_impl._M_start); } @@ -1228,11 +1262,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // [23.2.1.2] capacity /** Returns the number of elements in the %deque. */ + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return this->_M_impl._M_finish - this->_M_impl._M_start; } /** Returns the size() of the largest possible %deque. */ + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { return _S_max_size(_M_get_Tp_allocator()); } @@ -1322,6 +1358,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -1340,6 +1377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -1400,6 +1438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the first * element of the %deque. */ + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -1411,6 +1450,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the first * element of the %deque. */ + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -1422,6 +1462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the last element of the * %deque. */ + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -1435,6 +1476,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the last * element of the %deque. */ + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { @@ -2242,6 +2284,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * and if corresponding elements compare equal. */ template + _GLIBCXX_NODISCARD inline bool operator==(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return __x.size() == __y.size() @@ -2260,6 +2303,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * `<` and `>=` etc. */ template + [[nodiscard]] inline __detail::__synth3way_t<_Tp> operator<=>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { @@ -2280,6 +2324,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * See std::lexicographical_compare() for how the determination is made. */ template + _GLIBCXX_NODISCARD inline bool operator<(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), @@ -2287,24 +2332,28 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER /// Based on operator== template + _GLIBCXX_NODISCARD inline bool operator!=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator<=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__x < __y); } diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index dbe05a9834b..9ae640ee692 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -205,10 +205,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return *this; } // Must downcast from _List_node_base to _List_node to get to value. + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { return *static_cast<_Node*>(_M_node)->_M_valptr(); } + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { return static_cast<_Node*>(_M_node)->_M_valptr(); } @@ -243,11 +245,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node == __y._M_node; } #if __cpp_impl_three_way_comparison < 201907L + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node != __y._M_node; } @@ -291,10 +295,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return iterator(const_cast<__detail::_List_node_base*>(_M_node)); } // Must downcast from List_node_base to _List_node to get to value. + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { return *static_cast<_Node*>(_M_node)->_M_valptr(); } + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { return static_cast<_Node*>(_M_node)->_M_valptr(); } @@ -329,11 +335,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node == __y._M_node; } #if __cpp_impl_three_way_comparison < 201907L + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT { return __x._M_node != __y._M_node; } @@ -941,6 +949,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write iterator that points to the first element in the * %list. Iteration is done in ordinary element order. */ + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_node._M_next); } @@ -950,6 +959,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * first element in the %list. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_node._M_next); } @@ -959,6 +969,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * element in the %list. Iteration is done in ordinary element * order. */ + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(&this->_M_impl._M_node); } @@ -968,6 +979,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(&this->_M_impl._M_node); } @@ -977,6 +989,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * element in the %list. Iteration is done in reverse element * order. */ + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } @@ -986,6 +999,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } @@ -995,6 +1009,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * before the first element in the %list. Iteration is done in * reverse element order. */ + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } @@ -1004,6 +1019,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * before the first element in the %list. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } @@ -1014,6 +1030,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * first element in the %list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_node._M_next); } @@ -1023,6 +1040,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(&this->_M_impl._M_node); } @@ -1032,6 +1050,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * the last element in the %list. Iteration is done in reverse * element order. */ + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } @@ -1041,6 +1060,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * before the first element in the %list. Iteration is done in reverse * element order. */ + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -1056,11 +1076,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } /** Returns the number of elements in the %list. */ + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return _M_node_count(); } /** Returns the size() of the largest possible %list. */ + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { return _Node_alloc_traits::max_size(_M_get_Node_allocator()); } @@ -1110,6 +1132,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write reference to the data at the first * element of the %list. */ + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { return *begin(); } @@ -1118,6 +1141,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) reference to the data at the first * element of the %list. */ + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { return *begin(); } @@ -1126,6 +1150,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read/write reference to the data at the last element * of the %list. */ + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -1138,6 +1163,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * Returns a read-only (constant) reference to the data at the last * element of the %list. */ + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { @@ -1991,6 +2017,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * equal, and if corresponding elements compare equal. */ template + _GLIBCXX_NODISCARD inline bool operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { @@ -2026,6 +2053,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * `<` and `>=` etc. */ template + [[nodiscard]] inline __detail::__synth3way_t<_Tp> operator<=>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { @@ -2046,6 +2074,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * See std::lexicographical_compare() for how the determination is made. */ template + _GLIBCXX_NODISCARD inline bool operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), @@ -2053,24 +2082,28 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// Based on operator== template + _GLIBCXX_NODISCARD inline bool operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x < __y); } diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h index 936cf0d2380..363868fe0a6 100644 --- a/libstdc++-v3/include/bits/stl_queue.h +++ b/libstdc++-v3/include/bits/stl_queue.h @@ -107,15 +107,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template + _GLIBCXX_NODISCARD friend bool operator==(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); template + _GLIBCXX_NODISCARD friend bool operator<(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); #if __cpp_lib_three_way_comparison template + [[nodiscard]] friend compare_three_way_result_t<_Seq1> operator<=>(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); #endif @@ -204,6 +207,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return c.empty(); } /** Returns the number of elements in the %queue. */ + _GLIBCXX_NODISCARD size_type size() const { return c.size(); } @@ -212,6 +216,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read/write reference to the data at the first * element of the %queue. */ + _GLIBCXX_NODISCARD reference front() { @@ -223,6 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the first * element of the %queue. */ + _GLIBCXX_NODISCARD const_reference front() const { @@ -234,6 +240,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read/write reference to the data at the last * element of the %queue. */ + _GLIBCXX_NODISCARD reference back() { @@ -245,6 +252,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the last * element of the %queue. */ + _GLIBCXX_NODISCARD const_reference back() const { @@ -340,6 +348,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * if their sequences compare equal. */ template + _GLIBCXX_NODISCARD inline bool operator==(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c == __y.c; } @@ -358,36 +367,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * determination. */ template + _GLIBCXX_NODISCARD inline bool operator<(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c < __y.c; } /// Based on operator== template + _GLIBCXX_NODISCARD inline bool operator!=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__x == __y); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __y < __x; } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator<=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__y < __x); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__x < __y); } #if __cpp_lib_three_way_comparison template + [[nodiscard]] inline compare_three_way_result_t<_Seq> operator<=>(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c <=> __y.c; } @@ -613,6 +628,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return c.empty(); } /** Returns the number of elements in the %queue. */ + _GLIBCXX_NODISCARD size_type size() const { return c.size(); } @@ -621,6 +637,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the first * element of the %queue. */ + _GLIBCXX_NODISCARD const_reference top() const { diff --git a/libstdc++-v3/include/bits/stl_stack.h b/libstdc++-v3/include/bits/stl_stack.h index 2a460d2751a..85137b9d428 100644 --- a/libstdc++-v3/include/bits/stl_stack.h +++ b/libstdc++-v3/include/bits/stl_stack.h @@ -200,6 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return c.empty(); } /** Returns the number of elements in the %stack. */ + _GLIBCXX_NODISCARD size_type size() const { return c.size(); } @@ -208,6 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read/write reference to the data at the first * element of the %stack. */ + _GLIBCXX_NODISCARD reference top() { @@ -219,6 +221,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Returns a read-only (constant) reference to the data at the first * element of the %stack. */ + _GLIBCXX_NODISCARD const_reference top() const { @@ -315,6 +318,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * equal. */ template + _GLIBCXX_NODISCARD inline bool operator==(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __x.c == __y.c; } @@ -333,36 +337,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * determination. */ template + _GLIBCXX_NODISCARD inline bool operator<(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __x.c < __y.c; } /// Based on operator== template + _GLIBCXX_NODISCARD inline bool operator!=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return !(__x == __y); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __y < __x; } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator<=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return !(__y < __x); } /// Based on operator< template + _GLIBCXX_NODISCARD inline bool operator>=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return !(__x < __y); } #if __cpp_lib_three_way_comparison template + [[nodiscard]] inline compare_three_way_result_t<_Seq> operator<=>(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return __x.c <=> __y.c; } diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 06abf01ab0e..296da43822a 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -807,6 +807,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %vector. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_start); } @@ -816,6 +817,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %vector. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_start); } @@ -825,6 +827,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * element in the %vector. Iteration is done in ordinary * element order. */ + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(this->_M_impl._M_finish); } @@ -834,6 +837,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %vector. Iteration is done in * ordinary element order. */ + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(this->_M_impl._M_finish); } @@ -843,6 +847,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * last element in the %vector. Iteration is done in reverse * element order. */ + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } @@ -852,6 +857,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %vector. Iteration is done in * reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } @@ -861,6 +867,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * before the first element in the %vector. Iteration is done * in reverse element order. */ + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } @@ -870,6 +877,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %vector. Iteration * is done in reverse element order. */ + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } @@ -880,6 +888,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * first element in the %vector. Iteration is done in ordinary * element order. */ + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(this->_M_impl._M_start); } @@ -889,6 +898,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * the last element in the %vector. Iteration is done in * ordinary element order. */ + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(this->_M_impl._M_finish); } @@ -898,6 +908,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to the last element in the %vector. Iteration is done in * reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } @@ -907,6 +918,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * to one before the first element in the %vector. Iteration * is done in reverse element order. */ + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -914,11 +926,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER // [23.2.4.2] capacity /** Returns the number of elements in the %vector. */ + _GLIBCXX_NODISCARD size_type size() const _GLIBCXX_NOEXCEPT { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); } /** Returns the size() of the largest possible %vector. */ + _GLIBCXX_NODISCARD size_type max_size() const _GLIBCXX_NOEXCEPT { return _S_max_size(_M_get_Tp_allocator()); } @@ -994,6 +1008,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns the total number of elements that the %vector can * hold before needing to allocate more memory. */ + _GLIBCXX_NODISCARD size_type capacity() const _GLIBCXX_NOEXCEPT { return size_type(this->_M_impl._M_end_of_storage @@ -1039,6 +1054,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -1057,6 +1073,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * out_of_range lookups are not defined. (For checked lookups * see at().) */ + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -1117,6 +1134,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the first * element of the %vector. */ + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -1128,6 +1146,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the first * element of the %vector. */ + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -1139,6 +1158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read/write reference to the data at the last * element of the %vector. */ + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -1150,6 +1170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a read-only (constant) reference to the data at the * last element of the %vector. */ + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { @@ -1164,10 +1185,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * Returns a pointer such that [data(), data() + size()) is a valid * range. For a non-empty %vector, data() == &front(). */ + _GLIBCXX_NODISCARD _Tp* data() _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } + _GLIBCXX_NODISCARD const _Tp* data() const _GLIBCXX_NOEXCEPT { return _M_data_ptr(this->_M_impl._M_start); } diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index 227d083da04..4257a1651bd 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -219,51 +219,63 @@ namespace __debug using _Base::get_allocator; // iterators: + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(_Base::begin(), this); } + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(_Base::end(), this); } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -335,6 +347,7 @@ namespace __debug using _Base::empty; // element access: + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -342,6 +355,7 @@ namespace __debug return _M_base()[__n]; } + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -351,6 +365,7 @@ namespace __debug using _Base::at; + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -358,6 +373,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -365,6 +381,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -372,6 +389,7 @@ namespace __debug return _Base::back(); } + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list index 16f0531dce7..9cc05e8129c 100644 --- a/libstdc++-v3/include/debug/forward_list +++ b/libstdc++-v3/include/debug/forward_list @@ -327,38 +327,47 @@ namespace __debug // iterators: + [[__nodiscard__]] iterator before_begin() noexcept { return { _Base::before_begin(), this }; } + [[__nodiscard__]] const_iterator before_begin() const noexcept { return { _Base::before_begin(), this }; } + [[__nodiscard__]] iterator begin() noexcept { return { _Base::begin(), this }; } + [[__nodiscard__]] const_iterator begin() const noexcept { return { _Base::begin(), this }; } + [[__nodiscard__]] iterator end() noexcept { return { _Base::end(), this }; } + [[__nodiscard__]] const_iterator end() const noexcept { return { _Base::end(), this }; } + [[__nodiscard__]] const_iterator cbegin() const noexcept { return { _Base::cbegin(), this }; } + [[__nodiscard__]] const_iterator cbefore_begin() const noexcept { return { _Base::cbefore_begin(), this }; } + [[__nodiscard__]] const_iterator cend() const noexcept { return { _Base::cend(), this }; } @@ -368,6 +377,7 @@ namespace __debug // element access: + [[__nodiscard__]] reference front() { @@ -375,6 +385,7 @@ namespace __debug return _Base::front(); } + [[__nodiscard__]] const_reference front() const { diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index 01fe43fc7df..83122f8248d 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -223,51 +223,63 @@ namespace __debug using _Base::get_allocator; // iterators: + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(_Base::begin(), this); } + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(_Base::end(), this); } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -356,6 +368,7 @@ namespace __debug #endif // element access: + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -363,6 +376,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -370,6 +384,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -377,6 +392,7 @@ namespace __debug return _Base::back(); } + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h index 8e138fd32e5..5584d06de5a 100644 --- a/libstdc++-v3/include/debug/safe_iterator.h +++ b/libstdc++-v3/include/debug/safe_iterator.h @@ -297,6 +297,7 @@ namespace __gnu_debug * @brief Iterator dereference. * @pre iterator is dereferenceable */ + _GLIBCXX_NODISCARD reference operator*() const _GLIBCXX_NOEXCEPT { @@ -310,6 +311,7 @@ namespace __gnu_debug * @brief Iterator dereference. * @pre iterator is dereferenceable */ + _GLIBCXX_NODISCARD pointer operator->() const _GLIBCXX_NOEXCEPT { @@ -463,6 +465,7 @@ namespace __gnu_debug typedef _Safe_iterator<_Iterator, _Sequence, iterator_category> _Self; + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -471,6 +474,7 @@ namespace __gnu_debug } template + _GLIBCXX_NODISCARD friend bool operator==(const _Self& __lhs, const _Safe_iterator<_IteR, _Sequence, iterator_category>& __rhs) @@ -481,6 +485,7 @@ namespace __gnu_debug } #if ! __cpp_lib_three_way_comparison + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -489,6 +494,7 @@ namespace __gnu_debug } template + _GLIBCXX_NODISCARD friend bool operator!=(const _Self& __lhs, const _Safe_iterator<_IteR, _Sequence, iterator_category>& __rhs) @@ -786,6 +792,7 @@ namespace __gnu_debug } // ------ Random access iterator requirements ------ + _GLIBCXX_NODISCARD reference operator[](difference_type __n) const _GLIBCXX_NOEXCEPT { @@ -819,6 +826,7 @@ namespace __gnu_debug } #if __cpp_lib_three_way_comparison + [[nodiscard]] friend auto operator<=>(const _Self& __lhs, const _Self& __rhs) noexcept { @@ -826,6 +834,7 @@ namespace __gnu_debug return __lhs.base() <=> __rhs.base(); } + [[nodiscard]] friend auto operator<=>(const _Self& __lhs, const _OtherSelf& __rhs) noexcept { @@ -833,6 +842,7 @@ namespace __gnu_debug return __lhs.base() <=> __rhs.base(); } #else + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -840,6 +850,7 @@ namespace __gnu_debug return __lhs.base() < __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator<(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -847,6 +858,7 @@ namespace __gnu_debug return __lhs.base() < __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -854,6 +866,7 @@ namespace __gnu_debug return __lhs.base() <= __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator<=(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -861,6 +874,7 @@ namespace __gnu_debug return __lhs.base() <= __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -868,6 +882,7 @@ namespace __gnu_debug return __lhs.base() > __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -875,6 +890,7 @@ namespace __gnu_debug return __lhs.base() > __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -882,6 +898,7 @@ namespace __gnu_debug return __lhs.base() >= __rhs.base(); } + _GLIBCXX_NODISCARD friend bool operator>=(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -894,6 +911,7 @@ namespace __gnu_debug // According to the resolution of DR179 not only the various comparison // operators but also operator- must accept mixed iterator/const_iterator // parameters. + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __lhs, const _OtherSelf& __rhs) _GLIBCXX_NOEXCEPT { @@ -901,6 +919,7 @@ namespace __gnu_debug return __lhs.base() - __rhs.base(); } + _GLIBCXX_NODISCARD friend difference_type operator-(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -908,6 +927,7 @@ namespace __gnu_debug return __lhs.base() - __rhs.base(); } + _GLIBCXX_NODISCARD friend _Self operator+(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { @@ -917,6 +937,7 @@ namespace __gnu_debug return _Safe_iterator(__x.base() + __n, __x._M_sequence); } + _GLIBCXX_NODISCARD friend _Self operator+(difference_type __n, const _Self& __x) _GLIBCXX_NOEXCEPT { @@ -926,6 +947,7 @@ namespace __gnu_debug return _Safe_iterator(__n + __x.base(), __x._M_sequence); } + _GLIBCXX_NODISCARD friend _Self operator-(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 79ccf527dd6..55271384922 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -303,51 +303,63 @@ namespace __debug using _Base::get_allocator; // iterators: + _GLIBCXX_NODISCARD iterator begin() _GLIBCXX_NOEXCEPT { return iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD const_iterator begin() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::begin(), this); } + _GLIBCXX_NODISCARD iterator end() _GLIBCXX_NOEXCEPT { return iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD const_iterator end() const _GLIBCXX_NOEXCEPT { return const_iterator(_Base::end(), this); } + _GLIBCXX_NODISCARD reverse_iterator rbegin() _GLIBCXX_NOEXCEPT { return reverse_iterator(end()); } + _GLIBCXX_NODISCARD const_reverse_iterator rbegin() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(end()); } + _GLIBCXX_NODISCARD reverse_iterator rend() _GLIBCXX_NOEXCEPT { return reverse_iterator(begin()); } + _GLIBCXX_NODISCARD const_reverse_iterator rend() const _GLIBCXX_NOEXCEPT { return const_reverse_iterator(begin()); } #if __cplusplus >= 201103L + [[__nodiscard__]] const_iterator cbegin() const noexcept { return const_iterator(_Base::begin(), this); } + [[__nodiscard__]] const_iterator cend() const noexcept { return const_iterator(_Base::end(), this); } + [[__nodiscard__]] const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } @@ -407,6 +419,7 @@ namespace __debug } #endif + _GLIBCXX_NODISCARD size_type capacity() const _GLIBCXX_NOEXCEPT { @@ -431,6 +444,7 @@ namespace __debug } // element access: + _GLIBCXX_NODISCARD reference operator[](size_type __n) _GLIBCXX_NOEXCEPT { @@ -438,6 +452,7 @@ namespace __debug return _M_base()[__n]; } + _GLIBCXX_NODISCARD const_reference operator[](size_type __n) const _GLIBCXX_NOEXCEPT { @@ -447,6 +462,7 @@ namespace __debug using _Base::at; + _GLIBCXX_NODISCARD reference front() _GLIBCXX_NOEXCEPT { @@ -454,6 +470,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD const_reference front() const _GLIBCXX_NOEXCEPT { @@ -461,6 +478,7 @@ namespace __debug return _Base::front(); } + _GLIBCXX_NODISCARD reference back() _GLIBCXX_NOEXCEPT { @@ -468,6 +486,7 @@ namespace __debug return _Base::back(); } + _GLIBCXX_NODISCARD const_reference back() const _GLIBCXX_NOEXCEPT { diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index ea8d3cb5f2e..3e12d35157c 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -127,65 +127,81 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { std::swap_ranges(begin(), end(), __other.begin()); } // Iterators. + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR iterator begin() noexcept { return iterator(data()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator begin() const noexcept { return const_iterator(data()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR iterator end() noexcept { return iterator(data() + _Nm); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator end() const noexcept { return const_iterator(data() + _Nm); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reverse_iterator rbegin() noexcept { return reverse_iterator(end()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reverse_iterator rend() noexcept { return reverse_iterator(begin()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator cbegin() const noexcept { return const_iterator(data()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_iterator cend() const noexcept { return const_iterator(data() + _Nm); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } // Capacity. + [[__nodiscard__]] constexpr size_type size() const noexcept { return _Nm; } + [[__nodiscard__]] constexpr size_type max_size() const noexcept { return _Nm; } - _GLIBCXX_NODISCARD constexpr bool + [[__nodiscard__]] + constexpr bool empty() const noexcept { return size() == 0; } // Element access. + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference operator[](size_type __n) noexcept { @@ -193,6 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _AT_Type::_S_ref(_M_elems, __n); } + [[__nodiscard__]] constexpr const_reference operator[](size_type __n) const noexcept { @@ -224,6 +241,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _AT_Type::_S_ref(_M_elems, 0)); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference front() noexcept { @@ -231,6 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *begin(); } + [[__nodiscard__]] constexpr const_reference front() const noexcept { @@ -240,6 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _AT_Type::_S_ref(_M_elems, 0); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR reference back() noexcept { @@ -247,6 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Nm ? *(end() - 1) : *end(); } + [[__nodiscard__]] constexpr const_reference back() const noexcept { @@ -257,10 +278,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _AT_Type::_S_ref(_M_elems, 0); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR pointer data() noexcept { return _AT_Type::_S_ptr(_M_elems); } + [[__nodiscard__]] _GLIBCXX17_CONSTEXPR const_pointer data() const noexcept { return _AT_Type::_S_ptr(_M_elems); } @@ -275,6 +298,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Array comparisons. template + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) @@ -282,6 +306,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_lib_three_way_comparison && __cpp_lib_concepts template + [[nodiscard]] constexpr __detail::__synth3way_t<_Tp> operator<=>(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) { @@ -304,12 +329,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #else template + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return !(__one == __two); } template + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b) @@ -319,18 +346,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return __two < __one; } template + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return !(__one > __two); } template + [[__nodiscard__]] _GLIBCXX20_CONSTEXPR inline bool operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) @@ -361,6 +391,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template + [[__nodiscard__]] constexpr _Tp& get(array<_Tp, _Nm>& __arr) noexcept { @@ -369,6 +400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[__nodiscard__]] constexpr _Tp&& get(array<_Tp, _Nm>&& __arr) noexcept { @@ -377,6 +409,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[__nodiscard__]] constexpr const _Tp& get(const array<_Tp, _Nm>& __arr) noexcept { @@ -385,6 +418,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[__nodiscard__]] constexpr const _Tp&& get(const array<_Tp, _Nm>&& __arr) noexcept { @@ -406,6 +440,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[nodiscard]] constexpr array, _Nm> to_array(_Tp (&__a)[_Nm]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) @@ -418,6 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[nodiscard]] constexpr array, _Nm> to_array(_Tp (&&__a)[_Nm]) noexcept(is_nothrow_move_constructible_v<_Tp>) diff --git a/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc b/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc index c286b35fd61..e3cb6990f59 100644 --- a/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/creation/3_neg.cc @@ -1,4 +1,4 @@ -// { dg-options "-std=gnu++2a" } +// { dg-options "-std=gnu++2a -Wno-unused-result" } // { dg-do compile { target c++2a } } // Copyright (C) 2019-2021 Free Software Foundation, Inc. diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc index d384b7b2ff4..01c7c45784e 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/back1_neg.cc @@ -23,7 +23,7 @@ void test01() { std::array a; - a.back(); + (void) a.back(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc index b27f5f0bb03..db195e86411 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/back2_neg.cc @@ -23,7 +23,7 @@ void test01() { constexpr std::array a; - a.back(); + (void) a.back(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc index e0d86f1c07f..700f8524950 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/front1_neg.cc @@ -23,7 +23,7 @@ void test01() { std::array a; - a.front(); + (void) a.front(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc index dcbe5b6dd2e..d84b301fbf8 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/front2_neg.cc @@ -23,7 +23,7 @@ void test01() { constexpr std::array a; - a.front(); + (void) a.front(); } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc index 299ba85a5cf..bc5db43e123 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc @@ -23,7 +23,7 @@ void test01() { std::array a; - a[0]; + (void) a[0]; } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc index 36d281af105..105952f36d9 100644 --- a/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc @@ -23,7 +23,7 @@ void test01() { constexpr std::array a; - a[0]; + (void) a[0]; } int main() diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc index 423594dd2b3..70742c14a7d 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc @@ -26,6 +26,6 @@ int n1 = std::get<1>(a); int n2 = std::get<1>(std::move(a)); int n3 = std::get<1>(ca); -// { dg-error "static assertion failed" "" { target *-*-* } 367 } -// { dg-error "static assertion failed" "" { target *-*-* } 375 } -// { dg-error "static assertion failed" "" { target *-*-* } 383 } +// { dg-error "static assertion failed" "" { target *-*-* } 398 } +// { dg-error "static assertion failed" "" { target *-*-* } 407 } +// { dg-error "static assertion failed" "" { target *-*-* } 416 } diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc index 29fdd46115b..12063f53bb9 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc @@ -5,12 +5,12 @@ // 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 // . @@ -22,12 +22,12 @@ using namespace std; using __gnu_cxx::new_allocator; template - class clear_alloc : public new_allocator + class clear_alloc : public new_allocator { public: template - struct rebind + struct rebind { typedef clear_alloc other; }; virtual void clear() throw() @@ -35,10 +35,10 @@ template clear_alloc() throw() { } - - clear_alloc(clear_alloc const&) throw() : new_allocator() + + clear_alloc(clear_alloc const&) throw() : new_allocator() { } - + template clear_alloc(clear_alloc const&) throw() { } @@ -51,7 +51,7 @@ template this->clear(); return new_allocator::allocate(n, hint); } - + void deallocate(T *ptr, typename new_allocator::size_type n) { this->clear(); @@ -64,14 +64,14 @@ template { Container* pic = new Container; int x = 230; - + while (x--) { pic->push_back(x); } - - pic->get_allocator(); - + + (void) pic->get_allocator(); + // The following has led to infinite recursions or cores. pic->clear(); diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc index 6ec8b620422..aa98b7f6608 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc @@ -58,7 +58,7 @@ void test04() before = v.begin(); at = before + 3; v.erase(at, v.end()); - *before; + (void) *before; // clear() before = v.begin(); diff --git a/libstdc++-v3/testsuite/23_containers/deque/types/1.cc b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc index a17b1d86ec9..144eb57e13a 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc @@ -18,6 +18,7 @@ // . // { dg-do compile } +// { dg-options "-Wno-unused-result" } #include #include diff --git a/libstdc++-v3/testsuite/23_containers/list/types/1.cc b/libstdc++-v3/testsuite/23_containers/list/types/1.cc index 1e649963b84..45222b93bce 100644 --- a/libstdc++-v3/testsuite/23_containers/list/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/types/1.cc @@ -25,7 +25,7 @@ int main() std::list l; const std::list cl; - l.size(); + (void) l.size(); l.insert(l.begin(), greedy_ops::X()); l.insert(l.begin(), 1, greedy_ops::X()); l.insert(l.begin(), cl.begin(), cl.end()); diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc index 951b667c555..3ab3d337f46 100644 --- a/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc @@ -32,7 +32,7 @@ test03() for (int i = 0; i < 3; ++i) pq.push(data[i]); - pq.top(); + (void) pq.top(); for (int i = 0; i < 2; ++i) pq.pop(); diff --git a/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc b/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc index b01201a968e..e3e5dda2ef0 100644 --- a/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc +++ b/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc @@ -29,7 +29,7 @@ test01() std::queue q; q.push(1); - q.front(); + (void) q.front(); q.pop(); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/59829.cc b/libstdc++-v3/testsuite/23_containers/vector/59829.cc index 16bfb6fb327..7a7f577a643 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/59829.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/59829.cc @@ -63,5 +63,5 @@ bool operator!=(Alloc l, Alloc r) { return false; } int main() { std::vector> a; - a.data(); + (void) a.data(); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc index 3d2fe29389d..7656f840448 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc @@ -46,10 +46,10 @@ int main() std::vector > v(5); const std::vector > w(1); - v[0]; - w[0]; - v.size(); - v.capacity(); + (void) v[0]; + (void) w[0]; + (void) v.size(); + (void) v.capacity(); v.resize(1); v.insert(v.begin(), N::X()); v.insert(v.begin(), 1, N::X()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc index 9e01e8f607d..7329712a2a1 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/2.cc @@ -48,10 +48,10 @@ int main() std::vector > v(5); const std::vector > w(1); - v[0]; - w[0]; - v.size(); - v.capacity(); + (void) v[0]; + (void) w[0]; + (void) v.size(); + (void) v.capacity(); v.resize(1); v.insert(v.begin(), N::X()); v.insert(v.begin(), 1, N::X()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc index 803f658eedd..7295a64a008 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc @@ -18,6 +18,7 @@ // . // { dg-do compile } +// { dg-options "-Wno-unused-result" } #include #include