| 1 |
/* Test for constant expressions: overflow and constant expressions |
| 2 |
with -fwrapv: overflows still count as such for the purposes of |
| 3 |
constant expressions even when they have defined values at |
| 4 |
runtime. */ |
| 5 |
/* Origin: Joseph Myers <[email protected]> */ |
| 6 |
/* { dg-do compile } */ |
| 7 |
/* { dg-options "-std=iso9899:1999 -pedantic-errors -fwrapv" } */ |
| 8 |
|
| 9 |
#include <limits.h> |
| 10 |
|
| 11 |
enum e { |
| 12 |
E0 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression" } */ |
| 13 |
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */ |
| 14 |
E1 = 0 * (INT_MIN / -1), /* { dg-warning "integer overflow in expression" } */ |
| 15 |
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */ |
| 16 |
E2 = 0 * (INT_MAX * INT_MAX), /* { dg-warning "integer overflow in expression" } */ |
| 17 |
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */ |
| 18 |
E3 = 0 * (INT_MIN - 1), /* { dg-warning "integer overflow in expression" } */ |
| 19 |
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */ |
| 20 |
E4 = 0 * (unsigned)(INT_MIN - 1), /* { dg-warning "integer overflow in expression" } */ |
| 21 |
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */ |
| 22 |
E5 = 0 * -INT_MIN, /* { dg-warning "integer overflow in expression" } */ |
| 23 |
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */ |
| 24 |
E6 = 0 * !-INT_MIN, /* { dg-warning "integer overflow in expression" } */ |
| 25 |
/* { dg-error "not an integer constant" "constant" { target *-*-* } .-1 } */ |
| 26 |
E7 = INT_MIN % -1 /* { dg-warning "16:integer overflow in expression" } */ |
| 27 |
/* { dg-error "1:overflow in constant expression" "constant" { target *-*-* } .+1 } */ |
| 28 |
}; |