1 /* Test for constant expressions: overflow and constant expressions;
2 see also overflow-warn-*.c for some other cases. */
3 /* Origin: Joseph Myers <joseph@codesourcery.com> */
4 /* { dg-do compile } */
5 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
10 int a
= DBL_MAX
; /* { dg-warning "overflow in conversion" } */
11 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
12 int b
= (int) DBL_MAX
; /* { dg-error "overflow" } */
13 unsigned int c
= -1.0; /* { dg-warning "overflow in conversion" } */
14 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
15 unsigned int d
= (unsigned)-1.0; /* { dg-error "overflow" } */
17 int e
= 0 << 1000; /* { dg-warning "shift count" } */
18 /* { dg-error "constant" "constant" { target *-*-* } .-1 } */
19 int f
= 0 << -1; /* { dg-warning "shift count" } */
20 /* { dg-error "constant" "constant" { target *-*-* } .-1 } */
21 int g
= 0 >> 1000; /* { dg-warning "shift count" } */
22 /* { dg-error "constant" "constant" { target *-*-* } .-1 } */
23 int h
= 0 >> -1; /* { dg-warning "shift count" } */
24 /* { dg-error "constant" "constant" { target *-*-* } .-1 } */
26 int b1
= (0 ? (int) DBL_MAX
: 0);
27 unsigned int d1
= (0 ? (unsigned int)-1.0 : 0);
28 int e1
= (0 ? 0 << 1000 : 0);
29 int f1
= (0 ? 0 << -1 : 0);
30 int g1
= (0 ? 0 >> 1000 : 0);
31 int h1
= (0 ? 0 >> -1: 0);
34 /* { dg-error "constant" "constant" { target *-*-* } .-1 } */
36 int j
[1] = { DBL_MAX
}; /* { dg-warning "overflow in conversion" } */
37 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
39 int array
[2] = { [0 * (INT_MAX
+ 1)] = 0 }; /* { dg-warning "integer overflow in expression" } */
40 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
42 _Bool k
= INT_MAX
+ 1; /* { dg-warning "integer overflow in expression" } */
43 /* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */