1 /* PR c/80116 */
2 /* { dg-options "-Wmultistatement-macros" } */
3 /* { dg-do compile } */
4
5 #define SWAP(X, Y) \
6 tmp = X; /* { dg-warning "macro expands to multiple statements" } */ \
7 X = Y; \
8 Y = tmp
9
10 #define STUFF \
11 if (0) x = y
12
13 #define STUFF2 \
14 if (0) x = y; x++
15
16 #define STUFF3 \
17 if (x) /* { dg-message "not guarded by this 'if' clause" } */ \
18 SWAP(x, y) /* { dg-message "in expansion of macro .SWAP." } */
19
20 #define SET(X, Y) \
21 (X) = (Y)
22
23 #define STUFF4 \
24 if (x) \
25 SET(x, y); \
26 SET(x, y)
27
28 #define STUFF5 \
29 { tmp = x; x = y; }
30
31 #define STUFF6 \
32 x++;;
33
34 int x, y, tmp;
35
36 void
fn1(void)37 fn1 (void)
38 {
39 if (x) /* { dg-message "not guarded by this 'if' clause" } */
40 SWAP(x, y); /* { dg-message "in expansion of macro .SWAP." } */
41 }
42
43 void
fn2(void)44 fn2 (void)
45 {
46 SWAP(x, y);
47 }
48
49 void
fn3(void)50 fn3 (void)
51 {
52 if (x)
53 {
54 SWAP(x, y);
55 }
56 }
57
58 void
fn4(void)59 fn4 (void)
60 {
61 if (x)
62 ({ x = 10; x++; });
63 }
64
65 void
fn5(void)66 fn5 (void)
67 {
68 if (x) /* { dg-message "not guarded by this 'if' clause" } */
69 L1:
70 SWAP (x, y); /* { dg-message "in expansion of macro .SWAP." } */
71 goto L1;
72 }
73
74 void
fn6(void)75 fn6 (void)
76 {
77 if (x)
78 SET (x, y);
79 SET (tmp, x);
80 }
81
82 void
fn7(void)83 fn7 (void)
84 {
85 STUFF;
86 }
87
88 void
fn8(void)89 fn8 (void)
90 {
91 STUFF2;
92 }
93
94 void
fn9(void)95 fn9 (void)
96 {
97 STUFF3; /* { dg-message "in expansion of macro .STUFF3." } */
98 }
99
100 void
fn10(void)101 fn10 (void)
102 {
103 STUFF4;
104 }
105
106 void
fn11(void)107 fn11 (void)
108 {
109 if (x)
110 STUFF5;
111 }
112
113 void
fn12(void)114 fn12 (void)
115 {
116 if (x)
117 STUFF6;
118 }
119