2020-02-19 10:25:41 +00:00
|
|
|
// revisions: noopt opt opt_with_overflow_checks
|
2020-02-15 09:51:51 +00:00
|
|
|
//[noopt]compile-flags: -C opt-level=0
|
2020-02-15 09:47:27 +00:00
|
|
|
//[opt]compile-flags: -O
|
|
|
|
//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
|
|
|
|
|
2020-01-08 20:31:08 +00:00
|
|
|
// build-pass
|
2020-04-19 13:06:00 +00:00
|
|
|
// ignore-pass (test emits codegen-time warnings and verifies that they are not errors)
|
2019-06-12 20:53:00 +00:00
|
|
|
|
2020-02-18 21:49:47 +00:00
|
|
|
#![warn(const_err, arithmetic_overflow, unconditional_panic)]
|
2019-06-12 20:53:00 +00:00
|
|
|
|
2021-01-01 13:47:45 +00:00
|
|
|
// The only way to have promoteds that fail is in `const fn` called from `const`/`static`.
|
|
|
|
const fn overflow() -> u32 {
|
|
|
|
0 - 1 //~WARN arithmetic_overflow
|
|
|
|
//[opt_with_overflow_checks,noopt]~^ WARN any use of this value will cause an error
|
|
|
|
}
|
|
|
|
const fn div_by_zero1() -> i32 {
|
|
|
|
1 / 0 //[opt]~WARN unconditional_panic
|
|
|
|
//[opt]~^ WARN any use of this value will cause an error
|
|
|
|
}
|
|
|
|
const fn div_by_zero2() -> i32 {
|
|
|
|
1 / (1-1)
|
|
|
|
}
|
|
|
|
const fn div_by_zero3() -> i32 {
|
|
|
|
1 / (false as i32)
|
|
|
|
}
|
|
|
|
const fn oob() -> i32 {
|
|
|
|
[1,2,3][4]
|
|
|
|
}
|
|
|
|
|
|
|
|
const X: () = {
|
|
|
|
let _x: &'static u32 = &overflow();
|
|
|
|
//[opt_with_overflow_checks,noopt]~^ WARN any use of this value will cause an error
|
|
|
|
let _x: &'static i32 = &div_by_zero1();
|
|
|
|
//[opt]~^ WARN any use of this value will cause an error
|
|
|
|
let _x: &'static i32 = &div_by_zero2();
|
|
|
|
let _x: &'static i32 = &div_by_zero3();
|
|
|
|
let _x: &'static i32 = &oob();
|
|
|
|
};
|
|
|
|
|
2018-04-08 20:26:28 +00:00
|
|
|
fn main() {
|
|
|
|
}
|