2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2017-11-04 05:33:34 +00:00
|
|
|
// compile-flags: -C debug_assertions=yes
|
2019-08-17 05:08:01 +00:00
|
|
|
// ignore-emscripten compiled with panic=abort by default
|
2018-03-16 18:42:42 +00:00
|
|
|
// ignore-emscripten dies with an LLVM error
|
2017-11-04 05:33:34 +00:00
|
|
|
|
|
|
|
use std::panic;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
macro_rules! overflow_test {
|
|
|
|
($t:ident) => (
|
|
|
|
let r = panic::catch_unwind(|| {
|
|
|
|
($t::max_value()).next_power_of_two()
|
|
|
|
});
|
|
|
|
assert!(r.is_err());
|
|
|
|
|
|
|
|
let r = panic::catch_unwind(|| {
|
|
|
|
(($t::max_value() >> 1) + 2).next_power_of_two()
|
|
|
|
});
|
|
|
|
assert!(r.is_err());
|
|
|
|
)
|
|
|
|
}
|
|
|
|
overflow_test!(u8);
|
|
|
|
overflow_test!(u16);
|
|
|
|
overflow_test!(u32);
|
|
|
|
overflow_test!(u64);
|
|
|
|
overflow_test!(u128);
|
|
|
|
}
|