1 // revisions: noopt opt opt_with_overflow_checks
2 //[noopt]compile-flags: -C opt-level=0
3 //[opt]compile-flags: -O
4 //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
9 #![deny(arithmetic_overflow, const_err)]
10 #![allow(unused_variables)]
17 impl<T: Foo> Foo for Vec<T> {
18 const N: i32 = T::N << 42; // FIXME this should warn
22 let _ = x << 42; //~ ERROR: arithmetic operation will overflow
27 let n = 1u8 << 8; //~ ERROR: arithmetic operation will overflow
29 let n = 1u16 << 16; //~ ERROR: arithmetic operation will overflow
31 let n = 1u32 << 32; //~ ERROR: arithmetic operation will overflow
33 let n = 1u64 << 64; //~ ERROR: arithmetic operation will overflow
35 let n = 1i8 << 8; //~ ERROR: arithmetic operation will overflow
37 let n = 1i16 << 16; //~ ERROR: arithmetic operation will overflow
39 let n = 1i32 << 32; //~ ERROR: arithmetic operation will overflow
41 let n = 1i64 << 64; //~ ERROR: arithmetic operation will overflow
44 let n = 1u8 >> 8; //~ ERROR: arithmetic operation will overflow
46 let n = 1u16 >> 16; //~ ERROR: arithmetic operation will overflow
48 let n = 1u32 >> 32; //~ ERROR: arithmetic operation will overflow
50 let n = 1u64 >> 64; //~ ERROR: arithmetic operation will overflow
52 let n = 1i8 >> 8; //~ ERROR: arithmetic operation will overflow
54 let n = 1i16 >> 16; //~ ERROR: arithmetic operation will overflow
56 let n = 1i32 >> 32; //~ ERROR: arithmetic operation will overflow
58 let n = 1i64 >> 64; //~ ERROR: arithmetic operation will overflow
62 let n = n << 8; //~ ERROR: arithmetic operation will overflow
64 let n = 1u8 << -8; //~ ERROR: arithmetic operation will overflow
66 let n = 1i8<<(1isize+-1);
69 let n = 1u8 << (4+4); //~ ERROR: arithmetic operation will overflow
70 let n = 1i64 >> [63][0];
71 let n = 1i64 >> [64][0]; //~ ERROR: arithmetic operation will overflow
73 #[cfg(target_pointer_width = "32")]
74 const BITS: usize = 32;
75 #[cfg(target_pointer_width = "64")]
76 const BITS: usize = 64;
77 let n = 1_isize << BITS; //~ ERROR: arithmetic operation will overflow
78 let n = 1_usize << BITS; //~ ERROR: arithmetic operation will overflow