mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-22 16:37:40 +08:00
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. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@340426 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user