1 /* PR c/65179 */ 2 /* { dg-do compile } */ 3 /* { dg-options "-O -Wextra" } */ 4 /* { dg-additional-options "-std=c++11 -std=c++03" { target c++ } } */ 5 /* { dg-additional-options "-std=c90" { target c } } */ 6 7 enum E { 8 A = 0 << 1, 9 B = 1 << 1, 10 C = -1 << 1, /* { dg-bogus "left shift of negative value" } */ 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; 26 r += m << x; /* { dg-bogus "left shift of negative value" } */ 27 r += 0 << x; 28 r += 1 << x; 29 r += -1 << x; /* { dg-bogus "left shift of negative value" } */ 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 } 51