diff mbox series

[committed] libstdc++: Add nodiscard in <algorithm>

Message ID 20240314170050.2835263-1-jwakely@redhat.com
State New
Headers show
Series [committed] libstdc++: Add nodiscard in <algorithm> | expand

Commit Message

Jonathan Wakely March 14, 2024, 4:58 p.m. UTC
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 <algorithm>.
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 mbox series

Patch

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<typename _ForwardIterator1, typename _ForwardIterator2>
-    _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<typename _ForwardIterator1, typename _ForwardIterator2,
 	   typename _BinaryPredicate>
-    _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<typename _InputIterator, typename _Predicate>
-    _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<typename _InputIterator, typename _Predicate>
-    _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<typename _InputIterator, typename _Predicate>
-    _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<typename _InputIterator, typename _Predicate>
-    _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<typename _InputIterator, typename _Predicate>
-    _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<typename _ForwardIterator, typename _Predicate>
-    _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<typename _ForwardIterator, typename _Tp>
-    _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<typename _ForwardIterator, typename _Predicate>
-    _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<typename _ForwardIterator>
-    _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<typename _ForwardIterator, typename _BinaryPredicate>
-    _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<typename _ForwardIterator, typename _Tp, typename _Compare>
-    _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<typename _ForwardIterator, typename _Tp>
-    _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<typename _ForwardIterator, typename _Tp, typename _Compare>
-    _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<typename _ForwardIterator, typename _Tp>
-    _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<typename _ForwardIterator, typename _Tp, typename _Compare>
-    _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<typename _ForwardIterator, typename _Tp>
-    _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<typename _ForwardIterator, typename _Tp, typename _Compare>
-    _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<typename _InputIterator1, typename _InputIterator2>
-    _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<typename _InputIterator1, typename _InputIterator2,
 	   typename _Compare>
-    _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<typename _ForwardIterator>
-    _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<typename _ForwardIterator, typename _Compare>
-    _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<typename _ForwardIterator>
-    _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<typename _ForwardIterator, typename _Compare>
-    _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<typename _Tp>
-    _GLIBCXX14_CONSTEXPR
+    _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
     inline pair<const _Tp&, const _Tp&>
     minmax(const _Tp& __a, const _Tp& __b)
     {
@@ -3304,7 +3304,7 @@  _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
    *  __b) otherwise.
   */
   template<typename _Tp, typename _Compare>
-    _GLIBCXX14_CONSTEXPR
+    _GLIBCXX_NODISCARD _GLIBCXX14_CONSTEXPR
     inline pair<const _Tp&, const _Tp&>
     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<typename _ForwardIterator>
-    _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<typename _ForwardIterator, typename _Compare>
-    _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<typename _Tp>
-    _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<typename _Tp, typename _Compare>
-    _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<typename _ForwardIterator1, typename _ForwardIterator2,
 	   typename _BinaryPredicate>
-    _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<typename _ForwardIterator1, typename _ForwardIterator2>
-    _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<typename _ForwardIterator1, typename _ForwardIterator2,
 	   typename _BinaryPredicate>
-    _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<typename _Tp>
-    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<typename _Tp, typename _Compare>
-    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<typename _InputIterator, typename _Predicate>
-    _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<typename _InputIterator, typename _ForwardIterator>
-    _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<typename _InputIterator, typename _ForwardIterator,
 	   typename _BinaryPredicate>
-    _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<typename _ForwardIterator>
-    _GLIBCXX20_CONSTEXPR
+    _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
     inline _ForwardIterator
     adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
     {
@@ -3993,7 +3993,7 @@  _GLIBCXX_BEGIN_NAMESPACE_ALGO
    *  exists.
   */
   template<typename _ForwardIterator, typename _BinaryPredicate>
-    _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<typename _InputIterator, typename _Tp>
-    _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<typename _InputIterator, typename _Predicate>
-    _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<typename _ForwardIterator1, typename _ForwardIterator2>
-    _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<typename _ForwardIterator, typename _Integer, typename _Tp>
-    _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<typename _ForwardIterator, typename _Integer, typename _Tp,
 	   typename _BinaryPredicate>
-    _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<typename _ForwardIterator, typename _Searcher>
-    _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<typename _ForwardIterator>
-    _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<typename _ForwardIterator, typename _Compare>
-    _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<typename _ForwardIterator>
-    _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<typename _ForwardIterator, typename _Compare>
-    _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<typename _Tp>
-    _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<typename _Tp>
-    _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<typename _Tp, typename _Compare>
-    _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<typename _Tp, typename _Compare>
-    _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<typename _ForwardIterator, typename _Tp>
-    _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<typename _II1, typename _II2>
-    _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<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
-    _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<typename _II1, typename _II2>
-    _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<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
-    _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<typename _II1, typename _II2>
-    _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<typename _II1, typename _II2, typename _Compare>
-    _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<typename _InputIter1, typename _InputIter2, typename _Comp>
-    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<typename _InputIterator1, typename _InputIterator2>
-    _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<typename _InputIterator1, typename _InputIterator2,
 	   typename _BinaryPredicate>
-    _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<typename _InputIterator1, typename _InputIterator2>
-    _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<typename _InputIterator1, typename _InputIterator2,
 	   typename _BinaryPredicate>
-    _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<typename _RandomAccessIterator>
-    _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<typename _RandomAccessIterator, typename _Compare>
-    _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<typename _RandomAccessIterator>
-    _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<typename _RandomAccessIterator, typename _Compare>
-    _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<int> 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<int> 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<int>());
+  // { 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<int> 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<int>());
+  // { 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<int> 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<int> v;
   is_sorted(v.begin(), v.end());
+  // { dg-warning "ignoring return value" "" { target c++17 } 26 }
 }