aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-09-22 14:09:50 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-09-22 14:09:50 +0000
commit0d293e45b66c742fdbc3998209bb20ed6c5806bf (patch)
treeb94e3298127f119ce2169436e5c50e2f47401d56 /include/llvm/ADT
parent7f80b75b963781d81b772ae2f3a35dc74e1b6457 (diff)
downloadexternal_llvm-0d293e45b66c742fdbc3998209bb20ed6c5806bf.zip
external_llvm-0d293e45b66c742fdbc3998209bb20ed6c5806bf.tar.gz
external_llvm-0d293e45b66c742fdbc3998209bb20ed6c5806bf.tar.bz2
Provide basic type safety for array_pod_sort comparators.
This makes using array_pod_sort significantly safer. The implementation relies on function pointer casting but that should be safe as we're dealing with void* here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191175 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r--include/llvm/ADT/STLExtras.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h
index bfe1392..3aa8183 100644
--- a/include/llvm/ADT/STLExtras.h
+++ b/include/llvm/ADT/STLExtras.h
@@ -293,12 +293,16 @@ inline void array_pod_sort(IteratorTy Start, IteratorTy End) {
get_array_pod_sort_comparator(*Start));
}
-template<class IteratorTy>
-inline void array_pod_sort(IteratorTy Start, IteratorTy End,
- int (*Compare)(const void*, const void*)) {
+template <class IteratorTy>
+inline void array_pod_sort(
+ IteratorTy Start, IteratorTy End,
+ int (*Compare)(
+ const typename std::iterator_traits<IteratorTy>::value_type *,
+ const typename std::iterator_traits<IteratorTy>::value_type *)) {
// Don't dereference start iterator of empty sequence.
if (Start == End) return;
- qsort(&*Start, End-Start, sizeof(*Start), Compare);
+ qsort(&*Start, End - Start, sizeof(*Start),
+ reinterpret_cast<int (*)(const void *, const void *)>(Compare));
}
//===----------------------------------------------------------------------===//