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