diff options
| author | Simon BD <simon@server> | 2012-10-06 13:07:29 -0500 |
|---|---|---|
| committer | Simon BD <simon@server> | 2012-10-06 13:07:29 -0500 |
| commit | d4a54837d4ab28219727e1f1e0c131ba6033ba94 (patch) | |
| tree | 4b77978544f2782f4aa3859cf91133c9dc487e43 /src/libstd | |
| parent | eee86d4340668037c12cd4c69cc40daa6564f2fb (diff) | |
Add a test to check that badly written Ord impl do not cause double frees
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sort.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index f3c2f5ff446..7bafb324dad 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -1043,6 +1043,27 @@ mod test_tim_sort { tim_sort(arr); fail ~"Guarantee the fail"; } + + struct DVal { val: ~uint } + impl DVal: Ord { + pure fn lt(other: &DVal) -> bool { true } + pure fn le(other: &DVal) -> bool { true } + pure fn gt(other: &DVal) -> bool { true } + pure fn ge(other: &DVal) -> bool { true } + } + + #[test] + #[should_fail] + fn test_bad_Ord_impl() { + let rng = rand::Rng(); + let mut arr = do vec::from_fn(500) |_i| { + let randVal = rng.gen_uint(); + DVal { val: ~randVal } + }; + + tim_sort(arr); + fail ~"Guarantee the fail"; + } } /*fn f<T: Ord>(array: &[mut T]) { array[0] <-> array[0] } |
