[libcxx-commits] [libcxx] r357619 - libcxx: Add _LIBCPP_NODISCARD_EXT to 38 more functions
Nico Weber via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 3 11:13:08 PDT 2019
Author: nico
Date: Wed Apr 3 11:13:08 2019
New Revision: 357619
URL: http://llvm.org/viewvc/llvm-project?rev=357619&view=rev
Log:
libcxx: Add _LIBCPP_NODISCARD_EXT to 38 more functions
This builds on the work done in r342808 and adds _LIBCPP_NODISCARD_EXT
to 37 more functions, namely:
adjacent_find, all_of, any_of, binary_search, clamp, count_if, count,
equal_range, equal, find_end, find_first_not_of, find_first_of, find_if,
find, includes, is_heap_until, is_heap, is_partitioned, is_permutation,
is_sorted_until, is_sorted, lexicographical_compare, lower_bound,
max_element, max, min_element, min, minmax_element, minmax, mismatch,
none_of, remove_if, remove, search_n, search, unique, upper_bound
The motivation here is that we noticed that find_if is nodiscard with
Visual Studio's standard library, and we deemed that useful
(https://crbug.com/948122).
https://devblogs.microsoft.com/cppblog/c17-progress-in-vs-2017-15-5-and-15-6/
says "Our criteria for emitting the warning are: discarding the return
value is a guaranteed leak [...], discarding the return value is
near-guaranteed to be incorrect (e.g. remove()/remove_if()/unique()), or
the function is essentially a pure observer (e.g. vector::empty() and
std::is_sorted())." so I went through algorithm and tried to apply these
criteria.
Some of these, like vector::empty() are already nodiscard per C++
standard and didn't need changing.
I didn't (yet?) go over std::string::find* methods which should probably
have _LIBCPP_NODISCARD_EXT too (but not as part of this change).
Differential Revision: https://reviews.llvm.org/D60145
Modified:
libcxx/trunk/docs/UsingLibcxx.rst
libcxx/trunk/include/algorithm
libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp
libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp
Modified: libcxx/trunk/docs/UsingLibcxx.rst
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/UsingLibcxx.rst?rev=357619&r1=357618&r2=357619&view=diff
==============================================================================
--- libcxx/trunk/docs/UsingLibcxx.rst (original)
+++ libcxx/trunk/docs/UsingLibcxx.rst Wed Apr 3 11:13:08 2019
@@ -304,4 +304,41 @@ Entities declared with ``_LIBCPP_NODISCA
This section lists all extended applications of ``[[nodiscard]]`` to entities
which no dialect declares as such (See the second form described above).
+* ``adjacent_find``
+* ``all_of``
+* ``any_of``
+* ``binary_search``
+* ``clamp``
+* ``count_if``
+* ``count``
+* ``equal_range``
+* ``equal``
+* ``find_end``
+* ``find_first_of``
+* ``find_if_not``
+* ``find_if``
+* ``find``
* ``get_temporary_buffer``
+* ``includes``
+* ``is_heap_until``
+* ``is_heap``
+* ``is_partitioned``
+* ``is_permutation``
+* ``is_sorted_until``
+* ``is_sorted``
+* ``lexicographical_compare``
+* ``lower_bound``
+* ``max_element``
+* ``max``
+* ``min_element``
+* ``min``
+* ``minmax_element``
+* ``minmax``
+* ``mismatch``
+* ``none_of``
+* ``remove_if``
+* ``remove``
+* ``search_n``
+* ``search``
+* ``unique``
+* ``upper_bound``
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=357619&r1=357618&r2=357619&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Wed Apr 3 11:13:08 2019
@@ -811,7 +811,8 @@ struct __debug_less
// all_of
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -824,7 +825,8 @@ all_of(_InputIterator __first, _InputIte
// any_of
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -837,7 +839,8 @@ any_of(_InputIterator __first, _InputIte
// none_of
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -882,7 +885,8 @@ for_each_n(_InputIterator __first, _Size
// find
template <class _InputIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_InputIterator
find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
@@ -895,7 +899,8 @@ find(_InputIterator __first, _InputItera
// find_if
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_InputIterator
find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -908,7 +913,8 @@ find_if(_InputIterator __first, _InputIt
// find_if_not
template<class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_InputIterator
find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -1043,7 +1049,8 @@ __find_end(_RandomAccessIterator1 __firs
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
@@ -1055,7 +1062,8 @@ find_end(_ForwardIterator1 __first1, _Fo
}
template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
@@ -1081,7 +1089,8 @@ __find_first_of_ce(_ForwardIterator1 __f
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
@@ -1090,7 +1099,8 @@ find_first_of(_ForwardIterator1 __first1
}
template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
@@ -1103,7 +1113,8 @@ find_first_of(_ForwardIterator1 __first1
// adjacent_find
template <class _ForwardIterator, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
{
@@ -1121,7 +1132,8 @@ adjacent_find(_ForwardIterator __first,
}
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
{
@@ -1132,7 +1144,8 @@ adjacent_find(_ForwardIterator __first,
// count
template <class _InputIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename iterator_traits<_InputIterator>::difference_type
count(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
@@ -1146,7 +1159,8 @@ count(_InputIterator __first, _InputIter
// count_if
template <class _InputIterator, class _Predicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename iterator_traits<_InputIterator>::difference_type
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
@@ -1160,7 +1174,8 @@ count_if(_InputIterator __first, _InputI
// mismatch
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _BinaryPredicate __pred)
@@ -1172,7 +1187,8 @@ mismatch(_InputIterator1 __first1, _Inpu
}
template <class _InputIterator1, class _InputIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
{
@@ -1183,7 +1199,8 @@ mismatch(_InputIterator1 __first1, _Inpu
#if _LIBCPP_STD_VER > 11
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
@@ -1196,7 +1213,8 @@ mismatch(_InputIterator1 __first1, _Inpu
}
template <class _InputIterator1, class _InputIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
@@ -1210,7 +1228,8 @@ mismatch(_InputIterator1 __first1, _Inpu
// equal
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred)
{
@@ -1221,7 +1240,8 @@ equal(_InputIterator1 __first1, _InputIt
}
template <class _InputIterator1, class _InputIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
{
@@ -1259,7 +1279,8 @@ __equal(_RandomAccessIterator1 __first1,
}
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred )
@@ -1271,7 +1292,8 @@ equal(_InputIterator1 __first1, _InputIt
}
template <class _InputIterator1, class _InputIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
@@ -1287,7 +1309,7 @@ equal(_InputIterator1 __first1, _InputIt
// is_permutation
template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _BinaryPredicate __pred)
{
@@ -1334,7 +1356,8 @@ is_permutation(_ForwardIterator1 __first
}
template<class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2)
@@ -1413,7 +1436,8 @@ __is_permutation(_RandomAccessIterator1
}
template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
@@ -1426,7 +1450,8 @@ is_permutation(_ForwardIterator1 __first
}
template<class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
@@ -1444,7 +1469,8 @@ is_permutation(_ForwardIterator1 __first
// __search is in <functional>
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
@@ -1457,7 +1483,8 @@ search(_ForwardIterator1 __first1, _Forw
}
template <class _ForwardIterator1, class _ForwardIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
@@ -1470,7 +1497,7 @@ search(_ForwardIterator1 __first1, _Forw
#if _LIBCPP_STD_VER > 14
template <class _ForwardIterator, class _Searcher>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s)
{ return __s(__f, __l).first; }
#endif
@@ -1555,7 +1582,8 @@ __search_n(_RandomAccessIterator __first
}
template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
search_n(_ForwardIterator __first, _ForwardIterator __last,
_Size __count, const _Tp& __value_, _BinaryPredicate __pred)
@@ -1566,7 +1594,8 @@ search_n(_ForwardIterator __first, _Forw
}
template <class _ForwardIterator, class _Size, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_)
{
@@ -1995,7 +2024,7 @@ generate(_ForwardIterator __first, _Forw
// generate_n
template <class _OutputIterator, class _Size, class _Generator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
{
@@ -2009,7 +2038,7 @@ generate_n(_OutputIterator __first, _Siz
// remove
template <class _ForwardIterator, class _Tp>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
__first = _VSTD::find(__first, __last, __value_);
@@ -2031,7 +2060,7 @@ remove(_ForwardIterator __first, _Forwar
// remove_if
template <class _ForwardIterator, class _Predicate>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
__first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type>
@@ -2090,7 +2119,7 @@ remove_copy_if(_InputIterator __first, _
// unique
template <class _ForwardIterator, class _BinaryPredicate>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
{
__first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type>
@@ -2109,7 +2138,8 @@ unique(_ForwardIterator __first, _Forwar
}
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
unique(_ForwardIterator __first, _ForwardIterator __last)
{
@@ -2432,7 +2462,8 @@ rotate_copy(_ForwardIterator __first, _F
// min_element
template <class _ForwardIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
@@ -2449,7 +2480,8 @@ min_element(_ForwardIterator __first, _F
}
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last)
{
@@ -2460,7 +2492,8 @@ min_element(_ForwardIterator __first, _F
// min
template <class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
@@ -2468,7 +2501,8 @@ min(const _Tp& __a, const _Tp& __b, _Com
}
template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
min(const _Tp& __a, const _Tp& __b)
{
@@ -2478,7 +2512,8 @@ min(const _Tp& __a, const _Tp& __b)
#ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
min(initializer_list<_Tp> __t, _Compare __comp)
{
@@ -2486,7 +2521,8 @@ min(initializer_list<_Tp> __t, _Compare
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
min(initializer_list<_Tp> __t)
{
@@ -2498,7 +2534,8 @@ min(initializer_list<_Tp> __t)
// max_element
template <class _ForwardIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
@@ -2516,7 +2553,8 @@ max_element(_ForwardIterator __first, _F
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last)
{
@@ -2527,7 +2565,8 @@ max_element(_ForwardIterator __first, _F
// max
template <class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
@@ -2535,7 +2574,8 @@ max(const _Tp& __a, const _Tp& __b, _Com
}
template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
max(const _Tp& __a, const _Tp& __b)
{
@@ -2545,7 +2585,8 @@ max(const _Tp& __a, const _Tp& __b)
#ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
max(initializer_list<_Tp> __t, _Compare __comp)
{
@@ -2553,7 +2594,8 @@ max(initializer_list<_Tp> __t, _Compare
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
max(initializer_list<_Tp> __t)
{
@@ -2565,7 +2607,8 @@ max(initializer_list<_Tp> __t)
#if _LIBCPP_STD_VER > 14
// clamp
template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
const _Tp&
clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
{
@@ -2575,7 +2618,8 @@ clamp(const _Tp& __v, const _Tp& __lo, c
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
const _Tp&
clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
{
@@ -2586,7 +2630,7 @@ clamp(const _Tp& __v, const _Tp& __lo, c
// minmax_element
template <class _ForwardIterator, class _Compare>
-_LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11
std::pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
@@ -2636,7 +2680,8 @@ minmax_element(_ForwardIterator __first,
}
template <class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
std::pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last)
{
@@ -2647,7 +2692,8 @@ minmax_element(_ForwardIterator __first,
// minmax
template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<const _Tp&, const _Tp&>
minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
@@ -2656,7 +2702,8 @@ minmax(const _Tp& __a, const _Tp& __b, _
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<const _Tp&, const _Tp&>
minmax(const _Tp& __a, const _Tp& __b)
{
@@ -2666,7 +2713,8 @@ minmax(const _Tp& __a, const _Tp& __b)
#ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<_Tp, _Tp>
minmax(initializer_list<_Tp> __t, _Compare __comp)
{
@@ -2703,7 +2751,8 @@ minmax(initializer_list<_Tp> __t, _Compa
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<_Tp, _Tp>
minmax(initializer_list<_Tp> __t)
{
@@ -3130,7 +3179,7 @@ template<class _RandomAccessIterator, cl
}
template <class _InputIterator, class _Predicate>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
@@ -3538,7 +3587,7 @@ stable_partition(_ForwardIterator __firs
// is_sorted_until
template <class _ForwardIterator, class _Compare>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
if (__first != __last)
@@ -3555,7 +3604,8 @@ is_sorted_until(_ForwardIterator __first
}
template<class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
{
@@ -3565,7 +3615,8 @@ is_sorted_until(_ForwardIterator __first
// is_sorted
template <class _ForwardIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
@@ -3573,7 +3624,8 @@ is_sorted(_ForwardIterator __first, _For
}
template<class _ForwardIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_sorted(_ForwardIterator __first, _ForwardIterator __last)
{
@@ -4122,7 +4174,8 @@ __lower_bound(_ForwardIterator __first,
}
template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
@@ -4131,7 +4184,8 @@ lower_bound(_ForwardIterator __first, _F
}
template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
@@ -4164,7 +4218,8 @@ __upper_bound(_ForwardIterator __first,
}
template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
@@ -4173,7 +4228,8 @@ upper_bound(_ForwardIterator __first, _F
}
template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
@@ -4218,7 +4274,8 @@ __equal_range(_ForwardIterator __first,
}
template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
@@ -4233,7 +4290,8 @@ equal_range(_ForwardIterator __first, _F
}
template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
@@ -4253,7 +4311,8 @@ __binary_search(_ForwardIterator __first
}
template <class _ForwardIterator, class _Tp, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
@@ -4268,7 +4327,8 @@ binary_search(_ForwardIterator __first,
}
template <class _ForwardIterator, class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
@@ -4722,7 +4782,7 @@ stable_sort(_RandomAccessIterator __firs
// is_heap_until
template <class _RandomAccessIterator, class _Compare>
-_LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
+_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::difference_type difference_type;
@@ -4749,7 +4809,8 @@ is_heap_until(_RandomAccessIterator __fi
}
template<class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
@@ -4759,7 +4820,8 @@ is_heap_until(_RandomAccessIterator __fi
// is_heap
template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
@@ -4767,7 +4829,8 @@ is_heap(_RandomAccessIterator __first, _
}
template<class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
@@ -5320,7 +5383,8 @@ __includes(_InputIterator1 __first1, _In
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
_Compare __comp)
@@ -5336,7 +5400,8 @@ includes(_InputIterator1 __first1, _Inpu
}
template <class _InputIterator1, class _InputIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
{
@@ -5582,7 +5647,8 @@ __lexicographical_compare(_InputIterator
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
@@ -5598,7 +5664,8 @@ lexicographical_compare(_InputIterator1
}
template <class _InputIterator1, class _InputIterator2>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_LIBCPP_NODISCARD_EXT inline
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
Modified: libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp?rev=357619&r1=357618&r2=357619&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp (original)
+++ libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.fail.cpp Wed Apr 3 11:13:08 2019
@@ -22,15 +22,265 @@
// MODULES_DEFINES: _LIBCPP_ENABLE_NODISCARD
#define _LIBCPP_ENABLE_NODISCARD
+#include <algorithm>
+#include <functional>
+#include <iterator>
#include <memory>
#include "test_macros.h"
+struct P {
+ bool operator()(int) const { return false; }
+};
+
int main(int, char**) {
- {
- // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
- std::get_temporary_buffer<int>(1);
- }
+ int arr[1] = { 1 };
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::adjacent_find(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::adjacent_find(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::all_of(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::any_of(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::binary_search(std::begin(arr), std::end(arr), 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::binary_search(std::begin(arr), std::end(arr), 1, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::clamp(2, 1, 3);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::clamp(2, 1, 3, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::count_if(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::count(std::begin(arr), std::end(arr), 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::equal_range(std::begin(arr), std::end(arr), 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::equal_range(std::begin(arr), std::end(arr), 1, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::find_end(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::find_end(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::find_first_of(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::find_first_of(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::find_if_not(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::find_if(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::find(std::begin(arr), std::end(arr), 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::get_temporary_buffer<int>(1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::includes(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::includes(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_heap_until(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_heap_until(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_heap(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_heap(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_partitioned(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_sorted_until(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_sorted_until(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_sorted(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::is_sorted(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::lexicographical_compare(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::lexicographical_compare(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::lower_bound(std::begin(arr), std::end(arr), 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::lower_bound(std::begin(arr), std::end(arr), 1, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::max_element(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::max_element(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::max(1, 2);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::max(1, 2, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::max({1, 2, 3});
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::max({1, 2, 3}, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::min_element(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::min_element(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::min(1, 2);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::min(1, 2, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::min({1, 2, 3});
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::min({1, 2, 3}, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::minmax_element(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::minmax_element(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::minmax(1, 2);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::minmax(1, 2, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::minmax({1, 2, 3});
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::minmax({1, 2, 3}, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::none_of(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::remove_if(std::begin(arr), std::end(arr), P());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::remove(std::begin(arr), std::end(arr), 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::search_n(std::begin(arr), std::end(arr), 1, 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::search_n(std::begin(arr), std::end(arr), 1, 1, std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::search(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::search(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::search(std::begin(arr), std::end(arr),
+ std::default_searcher(std::begin(arr), std::end(arr)));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::unique(std::begin(arr), std::end(arr));
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::unique(std::begin(arr), std::end(arr), std::greater<int>());
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::upper_bound(std::begin(arr), std::end(arr), 1);
+
+ // expected-error-re at +1 {{ignoring return value of function declared with {{'nodiscard'|warn_unused_result}} attribute}}
+ std::upper_bound(std::begin(arr), std::end(arr), 1, std::greater<int>());
return 0;
}
Modified: libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp?rev=357619&r1=357618&r2=357619&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/diagnostics/nodiscard_extensions.pass.cpp Wed Apr 3 11:13:08 2019
@@ -17,14 +17,112 @@
// be tested here and in nodiscard_extensions.fail.cpp. They should also
// be listed in `UsingLibcxx.rst` in the documentation for the extension.
+#include <algorithm>
+#include <functional>
+#include <iterator>
#include <memory>
#include "test_macros.h"
+struct P {
+ bool operator()(int) const { return false; }
+};
+
int main(int, char**) {
- {
- std::get_temporary_buffer<int>(1); // intentional memory leak.
- }
+ int arr[1] = { 1 };
+
+ std::adjacent_find(std::begin(arr), std::end(arr));
+ std::adjacent_find(std::begin(arr), std::end(arr), std::greater<int>());
+ std::all_of(std::begin(arr), std::end(arr), P());
+ std::any_of(std::begin(arr), std::end(arr), P());
+ std::binary_search(std::begin(arr), std::end(arr), 1);
+ std::binary_search(std::begin(arr), std::end(arr), 1, std::greater<int>());
+ std::clamp(2, 1, 3);
+ std::clamp(2, 1, 3, std::greater<int>());
+ std::count_if(std::begin(arr), std::end(arr), P());
+ std::count(std::begin(arr), std::end(arr), 1);
+ std::equal_range(std::begin(arr), std::end(arr), 1);
+ std::equal_range(std::begin(arr), std::end(arr), 1, std::greater<int>());
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr));
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr),
+ std::greater<int>());
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+ std::equal(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+ std::find_end(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+ std::find_end(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+ std::find_first_of(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr));
+ std::find_first_of(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr), std::greater<int>());
+ std::find_if_not(std::begin(arr), std::end(arr), P());
+ std::find_if(std::begin(arr), std::end(arr), P());
+ std::find(std::begin(arr), std::end(arr), 1);
+ std::get_temporary_buffer<int>(1); // intentional memory leak.
+ std::includes(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+ std::includes(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+ std::is_heap_until(std::begin(arr), std::end(arr));
+ std::is_heap_until(std::begin(arr), std::end(arr), std::greater<int>());
+ std::is_heap(std::begin(arr), std::end(arr));
+ std::is_heap(std::begin(arr), std::end(arr), std::greater<int>());
+ std::is_partitioned(std::begin(arr), std::end(arr), P());
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr));
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr),
+ std::greater<int>());
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr));
+ std::is_permutation(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr), std::greater<int>());
+ std::is_sorted_until(std::begin(arr), std::end(arr));
+ std::is_sorted_until(std::begin(arr), std::end(arr), std::greater<int>());
+ std::is_sorted(std::begin(arr), std::end(arr));
+ std::is_sorted(std::begin(arr), std::end(arr), std::greater<int>());
+ std::lexicographical_compare(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr));
+ std::lexicographical_compare(std::begin(arr), std::end(arr), std::begin(arr),
+ std::end(arr), std::greater<int>());
+ std::lower_bound(std::begin(arr), std::end(arr), 1);
+ std::lower_bound(std::begin(arr), std::end(arr), 1, std::greater<int>());
+ std::max_element(std::begin(arr), std::end(arr));
+ std::max_element(std::begin(arr), std::end(arr), std::greater<int>());
+ std::max(1, 2);
+ std::max(1, 2, std::greater<int>());
+ std::max({1, 2, 3});
+ std::max({1, 2, 3}, std::greater<int>());
+ std::min_element(std::begin(arr), std::end(arr));
+ std::min_element(std::begin(arr), std::end(arr), std::greater<int>());
+ std::min(1, 2);
+ std::min(1, 2, std::greater<int>());
+ std::min({1, 2, 3});
+ std::min({1, 2, 3}, std::greater<int>());
+ std::minmax_element(std::begin(arr), std::end(arr));
+ std::minmax_element(std::begin(arr), std::end(arr), std::greater<int>());
+ std::minmax(1, 2);
+ std::minmax(1, 2, std::greater<int>());
+ std::minmax({1, 2, 3});
+ std::minmax({1, 2, 3}, std::greater<int>());
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr));
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr),
+ std::greater<int>());
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+ std::mismatch(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+ std::none_of(std::begin(arr), std::end(arr), P());
+ std::remove_if(std::begin(arr), std::end(arr), P());
+ std::remove(std::begin(arr), std::end(arr), 1);
+ std::search_n(std::begin(arr), std::end(arr), 1, 1);
+ std::search_n(std::begin(arr), std::end(arr), 1, 1, std::greater<int>());
+ std::search(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr));
+ std::search(std::begin(arr), std::end(arr), std::begin(arr), std::end(arr),
+ std::greater<int>());
+ std::search(std::begin(arr), std::end(arr),
+ std::default_searcher(std::begin(arr), std::end(arr)));
+ std::unique(std::begin(arr), std::end(arr));
+ std::unique(std::begin(arr), std::end(arr), std::greater<int>());
+ std::upper_bound(std::begin(arr), std::end(arr), 1);
+ std::upper_bound(std::begin(arr), std::end(arr), 1, std::greater<int>());
return 0;
}
More information about the libcxx-commits
mailing list