(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
Wshift-negative-value-3.c
       1  /* PR c/65179 */
       2  /* { dg-do compile } */
       3  /* { dg-options "-O -Wextra -Wno-shift-negative-value" } */
       4  
       5  enum E {
       6    A = 0 << 1,
       7    B = 1 << 1,
       8    C = -1 << 1,
       9    /* { dg-error "not an integer constant" "no constant" { target { c++11 && c++17_down } } .-1 } */
      10    /* { dg-error "left operand of shift expression" "shift" { target { c++11 && c++17_down } } .-2 } */
      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  }