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
6 // ignore-pass (test emits codegen-time warnings and verifies that they are not errors)
9 #![warn(arithmetic_overflow, const_err)]
16 impl<T: Foo> Foo for Vec<T> {
17 const N: i32 = T::N << 42; //~ WARN: arithmetic operation will overflow
21 let _ = x << 42; //~ WARN: arithmetic operation will overflow
26 let n = 1u8 << 8; //~ WARN: arithmetic operation will overflow
28 let n = 1u16 << 16; //~ WARN: arithmetic operation will overflow
30 let n = 1u32 << 32; //~ WARN: arithmetic operation will overflow
32 let n = 1u64 << 64; //~ WARN: arithmetic operation will overflow
34 let n = 1i8 << 8; //~ WARN: arithmetic operation will overflow
36 let n = 1i16 << 16; //~ WARN: arithmetic operation will overflow
38 let n = 1i32 << 32; //~ WARN: arithmetic operation will overflow
40 let n = 1i64 << 64; //~ WARN: arithmetic operation will overflow
43 let n = 1u8 >> 8; //~ WARN: arithmetic operation will overflow
45 let n = 1u16 >> 16; //~ WARN: arithmetic operation will overflow
47 let n = 1u32 >> 32; //~ WARN: arithmetic operation will overflow
49 let n = 1u64 >> 64; //~ WARN: arithmetic operation will overflow
51 let n = 1i8 >> 8; //~ WARN: arithmetic operation will overflow
53 let n = 1i16 >> 16; //~ WARN: arithmetic operation will overflow
55 let n = 1i32 >> 32; //~ WARN: arithmetic operation will overflow
57 let n = 1i64 >> 64; //~ WARN: arithmetic operation will overflow
61 let n = n << 8; //~ WARN: arithmetic operation will overflow
63 let n = 1u8 << -8; //~ WARN: arithmetic operation will overflow
65 let n = 1i8<<(1isize+-1);
68 let n = 1u8 << (4+4); //~ WARN: arithmetic operation will overflow
69 let n = 1i64 >> [63][0];
70 let n = 1i64 >> [64][0]; //~ WARN: arithmetic operation will overflow
72 #[cfg(target_pointer_width = "32")]
73 const BITS: usize = 32;
74 #[cfg(target_pointer_width = "64")]
75 const BITS: usize = 64;
76 let n = 1_isize << BITS; //~ WARN: arithmetic operation will overflow
77 let n = 1_usize << BITS; //~ WARN: arithmetic operation will overflow