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 <joseph@codesourcery.com> */ 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 *-*-* } 12 } */ 14 E1 = 0 * (INT_MIN / -1), /* { dg-warning "integer overflow in expression" } */ 15 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 14 } */ 16 E2 = 0 * (INT_MAX * INT_MAX), /* { dg-warning "integer overflow in expression" } */ 17 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 16 } */ 18 E3 = 0 * (INT_MIN - 1), /* { dg-warning "integer overflow in expression" } */ 19 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 18 } */ 20 E4 = 0 * (unsigned)(INT_MIN - 1), /* { dg-warning "integer overflow in expression" } */ 21 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 20 } */ 22 E5 = 0 * -INT_MIN, /* { dg-warning "integer overflow in expression" } */ 23 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 22 } */ 24 E6 = 0 * !-INT_MIN, /* { dg-warning "integer overflow in expression" } */ 25 /* { dg-error "not an integer constant" "constant" { target *-*-* } 24 } */ 26 E7 = INT_MIN % -1 /* Not an overflow. */ 27 }; 28