summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C
blob: 01d87be8bbed5b9fda9892ca1fdd9bc27bcf57b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// PR 17880
// { dg-do compile }
// { dg-options "-Wsequence-point" }

int
foo (int x)
{
  unsigned int a;
  int b;

  b = (a += 5) > a;  // { dg-warning "undefined" "sequence point warning" }
  b = (a += 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
  b = (a -= 5) > a;  // { dg-warning "undefined" "sequence point warning" }
  b = (a -= 5) + a == 10;  // { dg-warning "undefined" "sequence point warning" }
  b = a-- > a;  // { dg-warning "undefined" "sequence point warning" }
  b = a-- + a == 10;  // { dg-warning "undefined" "sequence point warning" }
  b = ++a > a;  // { dg-warning "undefined" "sequence point warning" }
  b = ++a + a == 10;  // { dg-warning "undefined" "sequence point warning" }

  if ((a += 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
  if ((a += 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
  if ((a -= 5) > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
  if ((a -= 5) + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
  if (a-- > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
  if (a-- + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
  if (++a > a) return -1;  // { dg-warning "undefined" "sequence point warning" }
  if (++a + a == 10) return -1;  // { dg-warning "undefined" "sequence point warning" }
  do {} while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
  while ((a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
  for ((a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
  for (b = (a += 5) > a;;);  // { dg-warning "undefined" "sequence point warning" }
  for (; (a += 5) > a;);  // { dg-warning "undefined" "sequence point warning" }
  for (;; b = (a += 5) > a);  // { dg-warning "undefined" "sequence point warning" }
  for (;; a++ + a++);  // { dg-warning "undefined" "sequence point warning" }
  if (a) a++ - a--;    // { dg-warning "undefined" "sequence point warning" }
  ((a +=5) > a) ? a : b; // { dg-warning "undefined" "sequence point warning" }
  return (a++ - a--); // { dg-warning "undefined" "sequence point warning" }
}

void bar (int i)
{
  int a = i++ - i++; // { dg-warning "undefined" "sequence point warning" }
} 

void baz (int i)
{
  switch (i++ + i++)  // { dg-warning "undefined" "sequence point warning" }
    {
    case 1:
      i++ - i++;  // { dg-warning "undefined" "sequence point warning" }
    case 2:
      break;
    }
}