(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
Wduplicated-branches-9.c
       1  /* PR c/64279 */
       2  /* { dg-do compile } */
       3  /* { dg-options "-Wduplicated-branches" } */
       4  
       5  extern int *p, foo (void), a[10];
       6  #define N 5
       7  #define M 5
       8  #define I i
       9  
      10  void
      11  f (int i)
      12  {
      13    *p += i ? 1 : 1; /* { dg-warning "this condition has identical branches" } */
      14    *p += i ? N : M; /* { dg-bogus "this condition has identical branches" "" { xfail *-*-* } } */
      15    *p += i ? M : N; /* { dg-bogus "this condition has identical branches" "" { xfail *-*-* } } */
      16    *p += i ? i : i; /* { dg-warning "this condition has identical branches" } */
      17    *p += i ? i++ : i++; /* { dg-warning "this condition has identical branches" } */
      18    *p += i ? foo () : foo (); /* { dg-warning "this condition has identical branches" } */
      19    *p += i ? ({ i++; }) : ({ i++; }); /* { dg-warning "this condition has identical branches" } */
      20    *p += i ? a[i] : a[i]; /* { dg-warning "this condition has identical branches" } */
      21    *p += i ? a[5] : a[5]; /* { dg-warning "this condition has identical branches" } */
      22    *p += i ? a[N] : a[M]; /* { dg-bogus "this condition has identical branches" "" { xfail *-*-* } } */
      23    *p += i ? a[5] : a[M]; /* { dg-bogus "this condition has identical branches" "" { xfail *-*-* } } */
      24    *p += i ? a[M] : a[5]; /* { dg-bogus "this condition has identical branches" "" { xfail *-*-* } } */
      25    *p += i ? a[I] : a[I]; /* { dg-warning "this condition has identical branches" } */
      26    *p += i ? a[i] : a[I]; /* { dg-bogus "this condition has identical branches" "" { xfail *-*-* } } */
      27    *p += i ? a[I] : a[i]; /* { dg-bogus "this condition has identical branches" "" { xfail *-*-* } } */
      28  
      29    *p += i ?: 1;
      30    *p += i ?: M;
      31    *p += i ?: N;
      32    *p += i ?: i; /* { dg-warning "this condition has identical branches" "" { target c++ } } */
      33    *p += i ?: i++;
      34    *p += i ?: foo ();
      35    *p += i ?: ({ i++; });
      36    *p += i ?: a[i];
      37    *p += i ?: a[5];
      38    *p += i ?: a[M];
      39    *p += i ?: a[M];
      40    *p += i ?: a[5];
      41    *p += i ?: a[I];
      42    *p += i ?: a[I];
      43    *p += i ?: a[i];
      44  
      45    *p += (i > 5 ? (i > 10 ? i : i) : i); /* { dg-warning "this condition has identical branches" } */
      46  }