2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2023-01-18 13:04:26 -06:00
|
|
|
// compile-flags: -C debug_assertions=true
|
2021-12-03 09:32:51 -06:00
|
|
|
// needs-unwind
|
2018-03-16 13:42:42 -05:00
|
|
|
// ignore-emscripten dies with an LLVM error
|
2017-11-04 00:33:34 -05:00
|
|
|
|
|
|
|
use std::panic;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
macro_rules! overflow_test {
|
|
|
|
($t:ident) => (
|
|
|
|
let r = panic::catch_unwind(|| {
|
2020-06-02 02:59:11 -05:00
|
|
|
($t::MAX).next_power_of_two()
|
2017-11-04 00:33:34 -05:00
|
|
|
});
|
|
|
|
assert!(r.is_err());
|
|
|
|
|
|
|
|
let r = panic::catch_unwind(|| {
|
2020-06-02 02:59:11 -05:00
|
|
|
(($t::MAX >> 1) + 2).next_power_of_two()
|
2017-11-04 00:33:34 -05:00
|
|
|
});
|
|
|
|
assert!(r.is_err());
|
|
|
|
)
|
|
|
|
}
|
|
|
|
overflow_test!(u8);
|
|
|
|
overflow_test!(u16);
|
|
|
|
overflow_test!(u32);
|
|
|
|
overflow_test!(u64);
|
|
|
|
overflow_test!(u128);
|
|
|
|
}
|