From patchwork Thu Mar 14 16:58:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1912186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=jTtRZOnz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TwYZ52XWpz1yWn for ; Fri, 15 Mar 2024 04:01:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F30DF3857739 for ; Thu, 14 Mar 2024 17:01:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 18C503858C3A for ; Thu, 14 Mar 2024 17:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18C503858C3A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 18C503858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710435659; cv=none; b=LkzI003NMY/IjCORBEvbS8RYutUcqQ1+RdwfLT10Os0JpgCIq4/sDDwnYLrzOikE026zgzBqWHuXFLfK0pXdg8sd3ZfxIOUKtl6mnCaG7/9xPRzXBrua5Dinibk/lmmTr4J58N1iu9aZVk6IFXGTPOuvtSs28A/yQcSmsC9Vuvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710435659; c=relaxed/simple; bh=dihAgR73CVJLoYfAI/KJFGJNG0akmHVKybn3aVhhwjg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OimgUpat0QA/hfmU4GYiJI+HhokyFx3nxig5hUMHvmZ/BXhuxANn5azkMXYEC04wnj7CC6PEKujo9O7bYkPH980fpHaHNkBy2xwCRK55BQGzOl9dPZ1phK7JQyjOkyAOJlPw77Cxd8P1lTKsU8MPSI5GVONkrpmluJU7mv7xqQU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710435654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DA1jz41ymUhW+69m4i4kZBNS3HxNYQ9SzX34AMgcduE=; b=jTtRZOnzlNLfjfxs9bEtZBPJL81S1rnDbxtxtaOENzqwSb+SbFdhS9CtpkQLFH6dJs3IiY +mY36fN4m441z0q/xKjnLxZ3C2vbNDFeMr9bIV15yPHbAiH3DiFdzOp9v/PyYbmg6zLyUf 38kug4Op+ojKftzIH85RnsBx3agKSj4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-331-6421gD5nPRqNQOLP7vXzkA-1; Thu, 14 Mar 2024 13:00:52 -0400 X-MC-Unique: 6421gD5nPRqNQOLP7vXzkA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FCA68007B8; Thu, 14 Mar 2024 17:00:52 +0000 (UTC) Received: from localhost (unknown [10.42.28.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7295D1C060D4; Thu, 14 Mar 2024 17:00:51 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add nodiscard in Date: Thu, 14 Mar 2024 16:58:41 +0000 Message-ID: <20240314170050.2835263-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.0 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_DBL_SPAM, URIBL_SBL_A autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested aarch64-linux and x86_64-linux. Pushed to trunk. I forgot to update the commit log to remove the speculation, because Stephan Lavavej confirmed that MSVC doesn't mark those functions nodiscard because it would result in too many false positives. Although it might find some real bugs, it would also warn about a lot of perfectly correct code. -- >8 -- Add the [[nodiscard]] attribute to several functions in . These all have no side effects and are only called for their return value (e.g. std::count) or produce a result that must not be discarded for correctness (e.g. std::remove). I was intending to add the attribute to a number of other functions like std::copy_if, std::unique_copy, std::set_union, and std::set_difference. I stopped when I noticed that MSVC doesn't use it on those functions, which I suspect is because they're often used with an insert iterator (e.g. std::back_insert_iterator). In that case it doesn't matter if you discard the result, because you have the container to tell you how many elements were copied to the output range. libstdc++-v3/ChangeLog: * include/bits/stl_algo.h (find_end, all_of, none_of, any_of) (find_if_not, is_partitioned, partition_point, remove) (remove_if, unique, lower_bound, upper_bound, equal_range) (binary_search, includes, is_sorted, is_sorted_until, minmax) (minmax_element, is_permutation, clamp, find_if, find_first_of) (adjacent_find, count, count_if, search, search_n, min_element) (max_element): Add nodiscard attribute. * include/bits/stl_algobase.h (min, max, lower_bound, equal) (lexicographical_compare, lexicographical_compare_three_way) (mismatch): Likewise. * include/bits/stl_heap.h (is_heap, is_heap_until): Likewise. * testsuite/25_algorithms/equal/debug/1_neg.cc: Add dg-warning. * testsuite/25_algorithms/equal/debug/2_neg.cc: Likewise. * testsuite/25_algorithms/equal/debug/3_neg.cc: Likewise. * testsuite/25_algorithms/find_first_of/concept_check_1.cc: Likewise. * testsuite/25_algorithms/is_permutation/2.cc: Likewise. * testsuite/25_algorithms/lexicographical_compare/71545.cc: Likewise. * testsuite/25_algorithms/lower_bound/33613.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/irreflexive.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/25_algorithms/minmax/3.cc: Likewise. * testsuite/25_algorithms/search/78346.cc: Likewise. * testsuite/25_algorithms/search_n/58358.cc: Likewise. * testsuite/25_algorithms/unique/1.cc: Likewise. * testsuite/25_algorithms/unique/11480.cc: Likewise. * testsuite/25_algorithms/upper_bound/33613.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc: Likewise. * testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc: Likewise. * testsuite/ext/concept_checks.cc: Likewise. * testsuite/ext/is_heap/47709.cc: Likewise. * testsuite/ext/is_sorted/cxx0x.cc: Likewise. --- libstdc++-v3/include/bits/stl_algo.h | 102 +++++++++--------- libstdc++-v3/include/bits/stl_algobase.h | 32 +++--- libstdc++-v3/include/bits/stl_heap.h | 8 +- .../25_algorithms/equal/debug/1_neg.cc | 1 + .../25_algorithms/equal/debug/2_neg.cc | 1 + .../25_algorithms/equal/debug/3_neg.cc | 1 + .../find_first_of/concept_check_1.cc | 1 + .../25_algorithms/is_permutation/2.cc | 1 + .../lexicographical_compare/71545.cc | 1 + .../25_algorithms/lower_bound/33613.cc | 1 + .../lower_bound/debug/irreflexive.cc | 1 + .../lower_bound/debug/partitioned_neg.cc | 1 + .../lower_bound/debug/partitioned_pred_neg.cc | 1 + .../testsuite/25_algorithms/minmax/3.cc | 1 + .../testsuite/25_algorithms/search/78346.cc | 1 + .../testsuite/25_algorithms/search_n/58358.cc | 1 + .../testsuite/25_algorithms/unique/1.cc | 1 + .../testsuite/25_algorithms/unique/11480.cc | 2 +- .../25_algorithms/upper_bound/33613.cc | 1 + .../upper_bound/debug/partitioned_neg.cc | 1 + .../upper_bound/debug/partitioned_pred_neg.cc | 1 + libstdc++-v3/testsuite/ext/concept_checks.cc | 4 + libstdc++-v3/testsuite/ext/is_heap/47709.cc | 1 + libstdc++-v3/testsuite/ext/is_sorted/cxx0x.cc | 1 + 24 files changed, 95 insertions(+), 72 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 7a0cf6b6737..1a996aa61da 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -320,7 +320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * [__first1,__last1-(__last2-__first2)) */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -370,7 +370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, @@ -405,7 +405,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @p [__first,__last), and false otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { return __last == std::find_if_not(__first, __last, __pred); } @@ -423,7 +423,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @p [__first,__last), and false otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); } @@ -442,7 +442,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { return !std::none_of(__first, __last, __pred); } @@ -458,7 +458,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * such that @p __pred(*i) is false, or @p __last if no such iterator exists. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) @@ -483,7 +483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * do not. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) @@ -505,7 +505,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * and @p none_of(mid, __last, __pred) are both true. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _ForwardIterator partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) @@ -783,7 +783,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) @@ -817,7 +817,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) @@ -886,7 +886,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last) { @@ -917,7 +917,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * are still present, but their value is unspecified. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __binary_pred) @@ -1958,7 +1958,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * the function used for the initial sort. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val, _Compare __comp) @@ -2014,7 +2014,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @ingroup binary_search_algorithms */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val) @@ -2045,7 +2045,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * the function used for the initial sort. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val, _Compare __comp) @@ -2118,7 +2118,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * but does not actually call those functions. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val) @@ -2155,7 +2155,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * but does not actually call those functions. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val, _Compare __comp) @@ -2189,7 +2189,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * that, use std::find or a container's specialized find member functions. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val) @@ -2223,7 +2223,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * the function used for the initial sort. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val, _Compare __comp) @@ -2803,7 +2803,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * returned. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) @@ -2849,7 +2849,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, @@ -3186,7 +3186,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @return True if the elements are sorted, false otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { return std::is_sorted_until(__first, __last) == __last; } @@ -3201,7 +3201,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @return True if the elements are sorted, false otherwise. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -3232,7 +3232,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * for which the range [__first, i) is sorted. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) { @@ -3257,7 +3257,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * for which the range [__first, i) is sorted. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -3283,7 +3283,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * __b) otherwise. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline pair minmax(const _Tp& __a, const _Tp& __b) { @@ -3304,7 +3304,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * __b) otherwise. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline pair minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -3384,7 +3384,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * such that no other element in the range is larger. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -3412,7 +3412,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * such that no other element in the range is larger. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -3430,7 +3430,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) } template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline pair<_Tp, _Tp> minmax(initializer_list<_Tp> __l) { @@ -3442,7 +3442,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) } template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline pair<_Tp, _Tp> minmax(initializer_list<_Tp> __l, _Compare __comp) { @@ -3469,7 +3469,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) @@ -3563,7 +3563,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * otherwise, returns false. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -3592,7 +3592,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, @@ -3619,7 +3619,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @pre `_Tp` is LessThanComparable and `(__hi < __lo)` is false. */ template - constexpr const _Tp& + [[nodiscard]] constexpr const _Tp& clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi) { __glibcxx_assert(!(__hi < __lo)); @@ -3639,7 +3639,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @pre `__comp(__hi, __lo)` is false. */ template - constexpr const _Tp& + [[nodiscard]] constexpr const _Tp& clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi, _Compare __comp) { __glibcxx_assert(!__comp(__hi, __lo)); @@ -3861,7 +3861,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * such that @p __pred(*i) is true, or @p __last if no such iterator exists. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) @@ -3893,7 +3893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * otherwise returns @p __last1. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _InputIterator find_first_of(_InputIterator __first1, _InputIterator __last1, _ForwardIterator __first2, _ForwardIterator __last2) @@ -3935,7 +3935,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _InputIterator find_first_of(_InputIterator __first1, _InputIterator __last1, _ForwardIterator __first2, _ForwardIterator __last2, @@ -3967,7 +3967,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * or @p __last if no such iterator exists. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last) { @@ -3993,7 +3993,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * exists. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __binary_pred) @@ -4019,7 +4019,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * for which @c *i == @p __value */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline typename iterator_traits<_InputIterator>::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp& __value) { @@ -4043,7 +4043,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * for which @p __pred(*i) is true. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline typename iterator_traits<_InputIterator>::difference_type count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -4084,7 +4084,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @p [__first1,__last1-(__last2-__first2)) */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -4118,7 +4118,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * equal to @p __val. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Integer __count, const _Tp& __val) @@ -4153,7 +4153,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Integer __count, const _Tp& __val, @@ -4178,7 +4178,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @return @p __searcher(__first,__last).first */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator search(_ForwardIterator __first, _ForwardIterator __last, const _Searcher& __searcher) @@ -5571,7 +5571,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @return Iterator referencing the first instance of the smallest value. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR _ForwardIterator inline min_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -5596,7 +5596,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * according to __comp. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) @@ -5635,7 +5635,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @return Iterator referencing the first instance of the largest value. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -5660,7 +5660,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * according to __comp. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 74ff42d4f39..d831e0e9883 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -228,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * preprocessor macro. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline const _Tp& min(const _Tp& __a, const _Tp& __b) { @@ -252,7 +252,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * preprocessor macro. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline const _Tp& max(const _Tp& __a, const _Tp& __b) { @@ -276,7 +276,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * once, unlike a preprocessor macro. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -298,7 +298,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * once, unlike a preprocessor macro. */ template - _GLIBCXX14_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR inline const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -1522,7 +1522,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER * @ingroup binary_search_algorithms */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val) @@ -1571,7 +1571,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * ranges are equal. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool equal(_II1 __first1, _II1 __last1, _II2 __first2) { @@ -1602,7 +1602,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * ranges are equal. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _BinaryPredicate __binary_pred) @@ -1689,7 +1689,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * ranges are equal. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) { @@ -1722,7 +1722,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * ranges are equal. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred) @@ -1754,7 +1754,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * then this is an inline call to @c memcmp. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) @@ -1789,7 +1789,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * comp parameter instead of @c <. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp) @@ -1843,7 +1843,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * returns. */ template - constexpr auto + [[nodiscard]] constexpr auto lexicographical_compare_three_way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, @@ -1932,7 +1932,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * to by the iterators are not equal. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) @@ -1967,7 +1967,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __binary_pred) @@ -2014,7 +2014,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * to by the iterators are not equal. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) @@ -2051,7 +2051,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, diff --git a/libstdc++-v3/include/bits/stl_heap.h b/libstdc++-v3/include/bits/stl_heap.h index 98817cf558a..9c1214a2b21 100644 --- a/libstdc++-v3/include/bits/stl_heap.h +++ b/libstdc++-v3/include/bits/stl_heap.h @@ -492,7 +492,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * the range [__first, i) is a heap. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -521,7 +521,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * the range [__first, i) is a heap. Comparisons are made using __comp. */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) @@ -546,7 +546,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @ingroup heap_algorithms */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { return std::is_heap_until(__first, __last) == __last; } @@ -560,7 +560,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @ingroup heap_algorithms */ template - _GLIBCXX20_CONSTEXPR + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR inline bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) diff --git a/libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc b/libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc index 9d18e7d48f1..f9328599a55 100644 --- a/libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc +++ b/libstdc++-v3/testsuite/25_algorithms/equal/debug/1_neg.cc @@ -27,6 +27,7 @@ test01() std::vector vect; vect.push_back(1); std::equal(vect.end(), vect.begin(), vect.begin()); + // { dg-warning "ignoring return value" "" { target c++17 } 29 } } int diff --git a/libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc b/libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc index a24d883a477..2e9134a74ea 100644 --- a/libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc +++ b/libstdc++-v3/testsuite/25_algorithms/equal/debug/2_neg.cc @@ -27,6 +27,7 @@ test01() std::vector v1, v2; v1.push_back(1); std::equal(v1.begin(), v1.end(), v2.begin()); + // { dg-warning "ignoring return value" "" { target c++17 } 29 } } int diff --git a/libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc b/libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc index 9301e251c71..425e7aa78c6 100644 --- a/libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc +++ b/libstdc++-v3/testsuite/25_algorithms/equal/debug/3_neg.cc @@ -33,6 +33,7 @@ test01() l2.push_back(2); std::equal(++l1.begin(), l1.end(), ++l2.begin()); + // { dg-warning "ignoring return value" "" { target c++17 } 35 } } int diff --git a/libstdc++-v3/testsuite/25_algorithms/find_first_of/concept_check_1.cc b/libstdc++-v3/testsuite/25_algorithms/find_first_of/concept_check_1.cc index f68cc8086c4..a970cd4bd61 100644 --- a/libstdc++-v3/testsuite/25_algorithms/find_first_of/concept_check_1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/find_first_of/concept_check_1.cc @@ -37,6 +37,7 @@ class2 b; void test01() { std::find_first_of(&a, &a, &b, &b, comp); + // { dg-warning "ignoring return value" "" { target c++17 } 39 } } int main() diff --git a/libstdc++-v3/testsuite/25_algorithms/is_permutation/2.cc b/libstdc++-v3/testsuite/25_algorithms/is_permutation/2.cc index 90ad2ff5c09..ab0610c3295 100644 --- a/libstdc++-v3/testsuite/25_algorithms/is_permutation/2.cc +++ b/libstdc++-v3/testsuite/25_algorithms/is_permutation/2.cc @@ -103,6 +103,7 @@ void test02() int arr[] = { 11, 22, 33 }; using namespace std; is_permutation(begin(arr0), end(arr0), begin(arr), end(arr), thrower); + // { dg-warning "ignoring return value" "" { target c++17 } 105 } } int main() diff --git a/libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/71545.cc b/libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/71545.cc index fb9a0ca1913..9f666caa68b 100644 --- a/libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/71545.cc +++ b/libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/71545.cc @@ -33,4 +33,5 @@ int main() X x[1]; int i[1]; std::lexicographical_compare(x, x+1, i, i+1); + // { dg-warning "ignoring return value" "" { target c++17 } 35 } } diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/33613.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/33613.cc index 618091a98a4..fa42b82b721 100644 --- a/libstdc++-v3/testsuite/25_algorithms/lower_bound/33613.cc +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/33613.cc @@ -33,4 +33,5 @@ bool ab(A, B); void test01(A* a, B b) { std::lower_bound(a, a, b, ab); + // { dg-warning "ignoring return value" "" { target c++17 } 35 } } diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/irreflexive.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/irreflexive.cc index 691917ee196..41a6028e404 100644 --- a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/irreflexive.cc +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/irreflexive.cc @@ -44,4 +44,5 @@ void test01() { A as[] = { 0, 1, 2, 3 }; std::lower_bound(as, as + 4, 1, A_int_comparer()); + // { dg-warning "ignoring return value" "" { target c++17 } 46 } } diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc index b72787e24fe..bc01d8147fa 100644 --- a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc @@ -36,6 +36,7 @@ void test01() { A as[] = { 0, 1, 2, 0, 2, 3 }; std::lower_bound(as, as + 6, A(1)); + // { dg-warning "ignoring return value" "" { target c++17 } 38 } } int diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc index 27210dece6f..f860df93940 100644 --- a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc @@ -24,6 +24,7 @@ void test01() { int as[] = { 0, 1, 0, 2, 3 }; std::lower_bound(as, as + 5, 1, std::less()); + // { dg-warning "ignoring return value" "" { target c++17 } 26 } } diff --git a/libstdc++-v3/testsuite/25_algorithms/minmax/3.cc b/libstdc++-v3/testsuite/25_algorithms/minmax/3.cc index 159421c17a4..a6620b9fa0d 100644 --- a/libstdc++-v3/testsuite/25_algorithms/minmax/3.cc +++ b/libstdc++-v3/testsuite/25_algorithms/minmax/3.cc @@ -43,6 +43,7 @@ int compare_counter::count = 0; void test01() { std::minmax({1, 2, 3, 4, 5, 6, 7, 8}, compare_counter()); + // { dg-warning "ignoring return value" "" { target c++17 } 45 } // If N is the number of arguments in the minmax function call, // 25.3.7 specifies that at most 3N/2 comparisons are allowed. diff --git a/libstdc++-v3/testsuite/25_algorithms/search/78346.cc b/libstdc++-v3/testsuite/25_algorithms/search/78346.cc index c1bc5a4857d..e6f3956b252 100644 --- a/libstdc++-v3/testsuite/25_algorithms/search/78346.cc +++ b/libstdc++-v3/testsuite/25_algorithms/search/78346.cc @@ -109,6 +109,7 @@ test01() { value s[] = { 0, 1, 2, 3, 4, 5 }; std::search(s, s+6, stashing_iterator(s), stashing_iterator(s+4)); + // { dg-warning "ignoring return value" "" { target c++17 } 111 } } int diff --git a/libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc b/libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc index 49397b1267b..651fd86fc9c 100644 --- a/libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc +++ b/libstdc++-v3/testsuite/25_algorithms/search_n/58358.cc @@ -29,6 +29,7 @@ void test01() int count = 0; std::search_n(a.begin(), a.end(), 10, 1, [&count](int t, int u) { ++count; return t == u; }); + // { dg-warning "ignoring return value" "" { target c++17 } 30 } VERIFY( count <= 11 ); } diff --git a/libstdc++-v3/testsuite/25_algorithms/unique/1.cc b/libstdc++-v3/testsuite/25_algorithms/unique/1.cc index 6826e26fdc0..698c370e229 100644 --- a/libstdc++-v3/testsuite/25_algorithms/unique/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/unique/1.cc @@ -27,5 +27,6 @@ int main() using namespace std; list menge; unique (menge.begin(), menge.end()); + // { dg-warning "ignoring return value" "" { target c++17 } 29 } return 0; } diff --git a/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc b/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc index 9d1bd4efe32..a008fc57f54 100644 --- a/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc +++ b/libstdc++-v3/testsuite/25_algorithms/unique/11480.cc @@ -31,7 +31,7 @@ bool compare(int a, int b) // libstdc++/11480 void test01() { - std::unique(a, a+10, compare); + std::unique(a, a+10, compare); // { dg-warning "ignoring return value" "" { target c++17 } } VERIFY( compare_count == 9 ); } diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/33613.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/33613.cc index 71ba2fd7ee5..19453a38f51 100644 --- a/libstdc++-v3/testsuite/25_algorithms/upper_bound/33613.cc +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/33613.cc @@ -33,4 +33,5 @@ bool ba(B, A); void test01(A* a, B b) { std::upper_bound(a, a, b, ba); + // { dg-warning "ignoring return value" "" { target c++17 } 35 } } diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc index e6dfb8936de..630357d6a45 100644 --- a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc @@ -36,6 +36,7 @@ void test01() { A as[] = { 0, 2, 1, 3, 4, 5 }; std::upper_bound(as, as + 6, A(1)); + // { dg-warning "ignoring return value" "" { target c++17 } 38 } } int diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc index ec5fea8c324..5beab7d22d7 100644 --- a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc @@ -24,6 +24,7 @@ void test01() { int as[] = { 0, 2, 1, 3, 4 }; std::upper_bound(as, as + 5, 1, std::less()); + // { dg-warning "ignoring return value" "" { target c++17 } 26 } } diff --git a/libstdc++-v3/testsuite/ext/concept_checks.cc b/libstdc++-v3/testsuite/ext/concept_checks.cc index e6baad3e75e..abb43a4fade 100644 --- a/libstdc++-v3/testsuite/ext/concept_checks.cc +++ b/libstdc++-v3/testsuite/ext/concept_checks.cc @@ -73,6 +73,10 @@ test2054( ) upper_bound(Index.begin(), Index.end(), SearchTerm, aComparison); equal_range(Index.begin(), Index.end(), SearchTerm, aComparison); binary_search(Index.begin(), Index.end(), SearchTerm, aComparison); + // { dg-warning "ignoring return value" "" { target c++17 } 72 } + // { dg-warning "ignoring return value" "" { target c++17 } 73 } + // { dg-warning "ignoring return value" "" { target c++17 } 74 } + // { dg-warning "ignoring return value" "" { target c++17 } 75 } } int main() diff --git a/libstdc++-v3/testsuite/ext/is_heap/47709.cc b/libstdc++-v3/testsuite/ext/is_heap/47709.cc index d9bf2df13c7..50bbccaf725 100644 --- a/libstdc++-v3/testsuite/ext/is_heap/47709.cc +++ b/libstdc++-v3/testsuite/ext/is_heap/47709.cc @@ -25,4 +25,5 @@ void foo() { std::vector v; is_heap(v.begin(), v.end()); + // { dg-warning "ignoring return value" "" { target c++17 } 27 } } diff --git a/libstdc++-v3/testsuite/ext/is_sorted/cxx0x.cc b/libstdc++-v3/testsuite/ext/is_sorted/cxx0x.cc index dfdd72641a1..3592d68bfcf 100644 --- a/libstdc++-v3/testsuite/ext/is_sorted/cxx0x.cc +++ b/libstdc++-v3/testsuite/ext/is_sorted/cxx0x.cc @@ -24,4 +24,5 @@ void foo() { std::vector v; is_sorted(v.begin(), v.end()); + // { dg-warning "ignoring return value" "" { target c++17 } 26 } }