| 1 |
/* PR c/65179 */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-O -Wextra" } */ |
| 4 |
|
| 5 |
enum E { |
| 6 |
A = 0 << 1, |
| 7 |
B = 1 << 1, |
| 8 |
C = -1 << 1, /* { dg-warning "10:left shift of negative value|not an integer constant" "" { target { c || { c++11 && c++17_down } } } } */ |
| 9 |
/* { dg-error "left operand of shift expression" "shift" { target { c++11 && c++17_down } } .-1 } */ |
| 10 |
D = 0 >> 1, |
| 11 |
E = 1 >> 1, |
| 12 |
F = -1 >> 1 |
| 13 |
}; |
| 14 |
|
| 15 |
int |
| 16 |
left (int x) |
| 17 |
{ |
| 18 |
/* Warn for LSHIFT_EXPR. */ |
| 19 |
const int z = 0; |
| 20 |
const int o = 1; |
| 21 |
const int m = -1; |
| 22 |
int r = 0; |
| 23 |
r += z << x; |
| 24 |
r += o << x; |
| 25 |
r += m << x; /* { dg-warning "10:left shift of negative value" "" { target { c || { c++11 && c++17_down } } } } */ |
| 26 |
r += 0 << x; |
| 27 |
r += 1 << x; |
| 28 |
r += -1 << x; /* { dg-warning "11:left shift of negative value" "" { target { c || { c++11 && c++17_down } } } } */ |
| 29 |
r += -1U << x; |
| 30 |
return r; |
| 31 |
} |
| 32 |
|
| 33 |
int |
| 34 |
right (int x) |
| 35 |
{ |
| 36 |
/* Shouldn't warn for RSHIFT_EXPR. */ |
| 37 |
const int z = 0; |
| 38 |
const int o = 1; |
| 39 |
const int m = -1; |
| 40 |
int r = 0; |
| 41 |
r += z >> x; |
| 42 |
r += o >> x; |
| 43 |
r += m >> x; |
| 44 |
r += 0 >> x; |
| 45 |
r += 1 >> x; |
| 46 |
r += -1 >> x; |
| 47 |
r += -1U >> x; |
| 48 |
return r; |
| 49 |
} |