aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/algorithm
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2018-08-22 17:47:13 +0000
committerEric Fiselier <eric@efcs.ca>2018-08-22 17:47:13 +0000
commita60d7fac096f086324e3131770a78d9de591515c (patch)
tree72f8adaf0f1a8d5f5780a7782fef59b27b7923da /libcxx/include/algorithm
parentb5686c4e4eb633e686f268a8472d02b04c33dbc1 (diff)
downloadllvm-a60d7fac096f086324e3131770a78d9de591515c.zip
llvm-a60d7fac096f086324e3131770a78d9de591515c.tar.gz
llvm-a60d7fac096f086324e3131770a78d9de591515c.tar.bz2
Add diagnostics for min/max algorithms when a InputIterator is used.
These algorithms require a ForwardIterator or better. Ensure we diagnose the contract violation at compile time instead of of silently doing the wrong thing. Further algorithms will be audited in upcoming patches. llvm-svn: 340426
Diffstat (limited to 'libcxx/include/algorithm')
-rw-r--r--libcxx/include/algorithm6
1 files changed, 6 insertions, 0 deletions
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 74a326d..ee2a54d 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -2398,6 +2398,8 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
+ static_assert(__is_forward_iterator<_ForwardIterator>::value,
+ "std::min_element requires a ForwardIterator");
if (__first != __last)
{
_ForwardIterator __i = __first;
@@ -2462,6 +2464,8 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
+ static_assert(__is_forward_iterator<_ForwardIterator>::value,
+ "std::max_element requires a ForwardIterator");
if (__first != __last)
{
_ForwardIterator __i = __first;
@@ -2548,6 +2552,8 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11
std::pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
+ static_assert(__is_forward_iterator<_ForwardIterator>::value,
+ "std::minmax_element requires a ForwardIterator");
std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first);
if (__first != __last)
{