1 /* Test for sequence point warnings. */
2 /* Origin: Michael Meeks in
3 <URL:http://gcc.gnu.org/ml/gcc-patches/1998-06/msg00316.html>,
4 adapted to a testcase by Joseph Myers <jsm28@cam.ac.uk>. */
5 /* { dg-do compile } */
6 /* { dg-options "-Wsequence-point" } */
14 extern int fnb (int, int);
15 extern int fnc (int *);
16 extern int sprintf (char *, const char *, ...);
18 typedef __SIZE_TYPE__
size_t;
21 foo (int a
, int b
, int n
, int p
, int *ptr
, struct s
*sptr
,
22 int *ap
, int *bp
, int **cp
, char *ans
, int (*fnp
[8])(int))
26 a
= a
++; /* { dg-warning "undefined" "sequence point warning" } */
27 a
= --a
; /* { dg-warning "undefined" "sequence point warning" } */
28 a
= ++a
+ b
; /* { dg-warning "undefined" "sequence point warning" } */
29 a
= a
-- + b
; /* { dg-warning "undefined" "sequence point warning" } */
30 ap
[n
] = bp
[n
++]; /* { dg-warning "undefined" "sequence point warning" } */
31 ap
[--n
] = bp
[n
]; /* { dg-warning "undefined" "sequence point warning" } */
32 ap
[++n
] = bp
[--n
]; /* { dg-warning "undefined" "sequence point warning" } */
33 cp
[n
][n
] = cp
[n
][n
]++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
34 cp
[n
][p
] = cp
[n
][n
++]; /* { dg-warning "undefined" "sequence point warning" } */
35 *ptr
++ = (size_t)ptr
++; /* { dg-warning "undefined" "sequence point warning" } */
36 sptr
->a
= sptr
->a
++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
37 sptr
->a
= (size_t)(sptr
++); /* { dg-warning "undefined" "sequence point warning" } */
38 *ptr
++ = fn (*ptr
); /* { dg-warning "undefined" "sequence point warning" } */
39 a
= b
= a
++; /* { dg-warning "undefined" "sequence point warning" } */
40 b
= a
= --b
; /* { dg-warning "undefined" "sequence point warning" } */
41 a
= 1 + (a
= 1); /* { dg-warning "undefined" "sequence point warning" } */
42 a
= (a
= b
); /* { dg-warning "undefined" "sequence point warning" } */
43 a
= (a
= b
) + 1; /* { dg-warning "undefined" "sequence point warning" } */
44 a
= (bp
[a
++] = b
) + 1; /* { dg-warning "undefined" "sequence point warning" } */
45 a
= b
++ * b
++; /* { dg-warning "undefined" "sequence point warning" } */
46 a
= fnb (b
++, b
++); /* { dg-warning "undefined" "sequence point warning" } */
47 a
= (*fnp
[b
++]) (b
++); /* { dg-warning "undefined" "sequence point warning" } */
48 a
= (*fnp
[b
]) (b
++); /* { dg-warning "undefined" "sequence point warning" } */
49 a
= (*fnp
[b
++]) (b
); /* { dg-warning "undefined" "sequence point warning" } */
50 *ap
= fnc (ap
++); /* { dg-warning "undefined" "sequence point warning" } */
51 (a
+= b
) + (a
+= n
); /* { dg-warning "undefined" "sequence point warning" } */
52 a
= (b
, b
++) + (b
++, b
); /* { dg-warning "undefined" "sequence point warning" } */
53 ap
[a
++] += a
; /* { dg-warning "undefined" "sequence point warning" } */
54 ap
[a
+=1] += a
; /* { dg-warning "undefined" "sequence point warning" } */
55 ap
[a
++] += a
++; /* { dg-warning "undefined" "sequence point warning" } */
56 ap
[a
+=1] += a
++; /* { dg-warning "undefined" "sequence point warning" } */
57 a
= a
++, b
= a
; /* { dg-warning "undefined" "sequence point warning" } */
58 b
= a
, a
= a
++; /* { dg-warning "undefined" "sequence point warning" } */
59 a
= (b
++ ? n
: a
) + b
; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
60 b
? a
= a
++ : a
; /* { dg-warning "undefined" "sequence point warning" } */
61 b
? a
: a
= a
++; /* { dg-warning "undefined" "sequence point warning" } */
62 b
&& (a
= a
++); /* { dg-warning "undefined" "sequence point warning" } */
63 (a
= a
++) && b
; /* { dg-warning "undefined" "sequence point warning" } */
64 b
, (a
= a
++); /* { dg-warning "undefined" "sequence point warning" } */
65 (a
= a
++), b
; /* { dg-warning "undefined" "sequence point warning" } */
66 a
^= b
^= a
^= b
; /* { dg-warning "undefined" "sequence point warning" } */
68 a
= a
; /* { dg-bogus "undefined" "bogus sequence point warning" } */
69 a
= (a
++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
70 a
= ! (a
++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
71 a
= - (a
++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
72 a
= (double) (a
++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
73 len
= sprintf (ans
, "%d", len
++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
74 a
= fn (a
++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
75 b
++, (b
+ b
); /* { dg-bogus "undefined" "bogus sequence point warning" } */
76 (a
= b
++), (a
= b
++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
77 a
= (b
++, b
++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
78 a
= b
++ && b
++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
79 a
= b
++ || b
++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
80 a
= (b
++ ? b
++ : a
); /* { dg-bogus "undefined" "bogus sequence point warning" } */
81 a
= (b
++ ? a
: b
++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
82 ap
[a
++] += bp
[b
]; /* { dg-bogus "undefined" "bogus sequence point warning" } */
83 ap
[a
+= 1] += 1; /* { dg-bogus "undefined" "bogus sequence point warning" } */
84 *ptr
< 128 ? *ptr
++ : *(ptr
+= 2); /* { dg-bogus "undefined" "bogus sequence point warning" } */
86 /* The following will be represented internally with a tree consisting of
87 many duplicated SAVE_EXPRs. This caused the previous version of the
88 sequence point warning code to fail by running out of virtual memory. */