diff options
author | Eric Fiselier <eric@efcs.ca> | 2018-08-22 17:47:13 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2018-08-22 17:47:13 +0000 |
commit | a60d7fac096f086324e3131770a78d9de591515c (patch) | |
tree | 72f8adaf0f1a8d5f5780a7782fef59b27b7923da /libcxx/test/std/algorithms/alg.sorting | |
parent | b5686c4e4eb633e686f268a8472d02b04c33dbc1 (diff) | |
download | bcm5719-llvm-a60d7fac096f086324e3131770a78d9de591515c.tar.gz bcm5719-llvm-a60d7fac096f086324e3131770a78d9de591515c.zip |
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/test/std/algorithms/alg.sorting')
-rw-r--r-- | libcxx/test/std/algorithms/alg.sorting/alg.min.max/requires_forward_iterator.fail.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.min.max/requires_forward_iterator.fail.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/requires_forward_iterator.fail.cpp new file mode 100644 index 00000000000..a1069dee7ae --- /dev/null +++ b/libcxx/test/std/algorithms/alg.sorting/alg.min.max/requires_forward_iterator.fail.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <algorithm> + +// template<ForwardIterator Iter> +// max_element(Iter first, Iter last); + +#include <algorithm> +#include <cassert> + +#include "test_iterators.h" + +int main() { + int arr[] = {1, 2, 3}; + const int *b = std::begin(arr), *e = std::end(arr); + typedef input_iterator<const int*> Iter; + { + // expected-error@algorithm:* {{"std::min_element requires a ForwardIterator"}} + std::min_element(Iter(b), Iter(e)); + } + { + // expected-error@algorithm:* {{"std::max_element requires a ForwardIterator"}} + std::max_element(Iter(b), Iter(e)); + } + { + // expected-error@algorithm:* {{"std::minmax_element requires a ForwardIterator"}} + std::minmax_element(Iter(b), Iter(e)); + } + +} |