diff options
author | Paolo Carlini <pcarlini@suse.de> | 2008-01-13 01:34:58 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2008-01-13 01:34:58 +0000 |
commit | a4c07f2d9fd576786b98c6a2e4fdb17039e5511e (patch) | |
tree | 1e46f02ee8df7d4a9f796162ef33a4be1bca271c /libstdc++-v3/include/debug/functions.h | |
parent | 5db2e9ca7dc5ab9bac4baad91c224ba7d8fc0c45 (diff) | |
download | gcc-a4c07f2d9fd576786b98c6a2e4fdb17039e5511e.zip gcc-a4c07f2d9fd576786b98c6a2e4fdb17039e5511e.tar.gz gcc-a4c07f2d9fd576786b98c6a2e4fdb17039e5511e.tar.bz2 |
re PR libstdc++/34730 (Legal program doesn't compile with -D_GLIBCXX_DEBUG)
2008-01-12 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/34730
* include/debug/functions.h (__check_sorted_set,
__check_sorted_set_aux): Add.
(__check_sorted): Check StrictWeakOrdering.
* include/debug/macros.h (__glibcxx_check_strict_weak_ordering,
__glibcxx_check_strict_weak_ordering_pred): Remove.
(__glibcxx_check_sorted, __glibcxx_check_sorted_pred): Adjust.
(__glibcxx_check_sorted_set, __glibcxx_check_sorted_set_pred): Add.
* include/debug/debug.h (__glibcxx_requires_sorted_set,
__glibcxx_requires_sorted_set_pred): Add.
* include/bits/stl_algo.h (merge, includes, set_union,
set_intersection, set_difference, set_symmetric_difference):
Adjust, use __glibcxx_requires_sorted_set* instead.
* testsuite/25_algorithms/set_intersection/34730.cc: New.
From-SVN: r131500
Diffstat (limited to 'libstdc++-v3/include/debug/functions.h')
-rw-r--r-- | libstdc++-v3/include/debug/functions.h | 87 |
1 files changed, 80 insertions, 7 deletions
diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h index 15c2154..7e7562a 100644 --- a/libstdc++-v3/include/debug/functions.h +++ b/libstdc++-v3/include/debug/functions.h @@ -1,6 +1,6 @@ // Debugging support implementation -*- C++ -*- -// Copyright (C) 2003, 2005, 2006 +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -205,10 +205,9 @@ namespace __gnu_debug return true; _ForwardIterator __next = __first; - for (++__next; __next != __last; __first = __next, ++__next) { + for (++__next; __next != __last; __first = __next, ++__next) if (*__next < *__first) return false; - } return true; } @@ -232,10 +231,9 @@ namespace __gnu_debug return true; _ForwardIterator __next = __first; - for (++__next; __next != __last; __first = __next, ++__next) { + for (++__next; __next != __last; __first = __next, ++__next) if (__pred(*__next, *__first)) return false; - } return true; } @@ -247,6 +245,11 @@ namespace __gnu_debug { typedef typename std::iterator_traits<_InputIterator>::iterator_category _Category; + + // Verify that the < operator for elements in the sequence is a + // StrictWeakOrdering by checking that it is irreflexive. + _GLIBCXX_DEBUG_ASSERT(__first == __last || !(*__first < *__first)); + return __check_sorted_aux(__first, __last, _Category()); } @@ -257,10 +260,80 @@ namespace __gnu_debug { typedef typename std::iterator_traits<_InputIterator>::iterator_category _Category; - return __check_sorted_aux(__first, __last, __pred, - _Category()); + + // Verify that the predicate is StrictWeakOrdering by checking that it + // is irreflexive. + _GLIBCXX_DEBUG_ASSERT(__first == __last || !__pred(*__first, *__first)); + + return __check_sorted_aux(__first, __last, __pred, _Category()); + } + + template<typename _InputIterator1, typename _InputIterator2> + inline bool + __check_sorted_set_aux(const _InputIterator1& __first, + const _InputIterator1& __last, + const _InputIterator2&, std::__true_type) + { return __check_sorted(__first, __last); } + + template<typename _InputIterator1, typename _InputIterator2> + inline bool + __check_sorted_set_aux(const _InputIterator1&, + const _InputIterator1&, + const _InputIterator2&, std::__false_type) + { return true; } + + template<typename _InputIterator1, typename _InputIterator2, + typename _Predicate> + inline bool + __check_sorted_set_aux(const _InputIterator1& __first, + const _InputIterator1& __last, + const _InputIterator2&, _Predicate __pred, + std::__true_type) + { return __check_sorted(__first, __last, __pred); } + + template<typename _InputIterator1, typename _InputIterator2, + typename _Predicate> + inline bool + __check_sorted_set_aux(const _InputIterator1&, + const _InputIterator1&, + const _InputIterator2&, _Predicate, + std::__false_type) + { return true; } + + // ... special variant used in std::merge, std::includes, std::set_*. + template<typename _InputIterator1, typename _InputIterator2> + inline bool + __check_sorted_set(const _InputIterator1& __first, + const _InputIterator1& __last, + const _InputIterator2&) + { + typedef typename std::iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename std::iterator_traits<_InputIterator2>::value_type + _ValueType2; + + typedef typename std::__are_same<_ValueType1, _ValueType2>::__type + _SameType; + return __check_sorted_set_aux(__first, __last, _SameType()); } + template<typename _InputIterator1, typename _InputIterator2, + typename _Predicate> + inline bool + __check_sorted_set(const _InputIterator1& __first, + const _InputIterator1& __last, + const _InputIterator2&, _Predicate __pred) + { + typedef typename std::iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename std::iterator_traits<_InputIterator2>::value_type + _ValueType2; + + typedef typename std::__are_same<_ValueType1, _ValueType2>::__type + _SameType; + return __check_sorted_set_aux(__first, __last, __pred, _SameType()); + } + // _GLIBCXX_RESOLVE_LIB_DEFECTS // 270. Binary search requirements overly strict // Determine if a sequence is partitioned w.r.t. this element. |