2015-10-17 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / c-c++-common / Wshift-negative-value-3.c
blobbf9b1a07bb78317bf0a67730b8a6cfb3b627bb91
1 /* PR c/65179 */
2 /* { dg-do compile } */
3 /* { dg-options "-O -Wextra -Wno-shift-negative-value" } */
4 /* { dg-additional-options "-std=c++11" { target c++ } } */
6 enum E {
7 A = 0 << 1,
8 B = 1 << 1,
9 C = -1 << 1,
10 D = 0 >> 1,
11 E = 1 >> 1,
12 F = -1 >> 1
15 int
16 left (int x)
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-bogus "left shift of negative value" } */
26 r += 0 << x;
27 r += 1 << x;
28 r += -1 << x; /* { dg-bogus "left shift of negative value" } */
29 r += -1U << x;
30 return r;
33 int
34 right (int x)
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;