4
4
// RUN: -Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
5
5
6
6
int f (int , int = 0 );
7
+ int g1 ();
8
+ int g2 (int );
7
9
8
10
struct A {
9
11
int x, y;
@@ -79,24 +81,28 @@ void test() {
79
81
A { ++a, a++ }.x + A { ++a, a++ }.y ; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
80
82
// cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
81
83
82
- (xs[2 ] && (a = 0 )) + a; // ok
84
+ (xs[2 ] && (a = 0 )) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
85
+ // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
83
86
(0 && (a = 0 )) + a; // ok
84
87
(1 && (a = 0 )) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
85
88
// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
86
89
87
- (xs[3 ] || (a = 0 )) + a; // ok
90
+ (xs[3 ] || (a = 0 )) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
91
+ // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
88
92
(0 || (a = 0 )) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
89
93
// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
90
94
(1 || (a = 0 )) + a; // ok
91
95
92
- (xs[4 ] ? a : ++a) + a; // ok
96
+ (xs[4 ] ? a : ++a) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
97
+ // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
93
98
(0 ? a : ++a) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
94
99
// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
95
100
(1 ? a : ++a) + a; // ok
96
101
(0 ? a : a++) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
97
102
// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
98
103
(1 ? a : a++) + a; // ok
99
- (xs[5 ] ? ++a : ++a) + a; // FIXME: warn here
104
+ (xs[5 ] ? ++a : ++a) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
105
+ // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
100
106
101
107
(++a, xs[6 ] ? ++a : 0 ) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
102
108
// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
@@ -122,10 +128,13 @@ void test() {
122
128
// unconditional.
123
129
a = a++ && f (a, a);
124
130
125
- // This has undefined behavior if a != 0. FIXME: We should diagnose this.
126
- (a && a++) + a;
131
+ // This has undefined behavior if a != 0.
132
+ (a && a++) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
133
+ // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
127
134
128
- (xs[7 ] && ++a) * (!xs[7 ] && ++a); // ok
135
+ // FIXME: Don't warn here.
136
+ (xs[7 ] && ++a) * (!xs[7 ] && ++a); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
137
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
129
138
130
139
xs[0 ] = (a = 1 , a); // ok
131
140
(a -= 128 ) &= 128 ; // ok
@@ -135,13 +144,64 @@ void test() {
135
144
// cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
136
145
xs[8 ] ? 0 : ++a + a++; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
137
146
// cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
138
- xs[8 ] ? ++a : a++; // ok
147
+ xs[8 ] ? ++a : a++; // no-warning
148
+ xs[8 ] ? a+=1 : a+= 2 ; // no-warning
149
+ (xs[8 ] ? a+=1 : a+= 2 ) = a; // cxx11-warning {{unsequenced modification and access to 'a'}}
150
+ // TODO cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
151
+ (xs[8 ] ? a+=1 : a) = a; // cxx11-warning {{unsequenced modification and access to 'a'}}
152
+ // TODO cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
153
+ (xs[8 ] ? a : a+= 2 ) = a; // cxx11-warning {{unsequenced modification and access to 'a'}}
154
+ // TODO cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
155
+ a = (xs[8 ] ? a+=1 : a+= 2 ); // no-warning
156
+ a += (xs[8 ] ? a+=1 : a+= 2 ); // cxx11-warning {{unsequenced modification and access to 'a'}}
157
+ // TODO cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
158
+
159
+ (false ? a+=1 : a) = a; // no-warning
160
+ (true ? a+=1 : a) = a; // cxx11-warning {{unsequenced modification and access to 'a'}}
161
+ // TODO cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
162
+ (false ? a : a+=2 ) = a; // cxx11-warning {{unsequenced modification and access to 'a'}}
163
+ // TODO cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
164
+ (true ? a : a+=2 ) = a; // no-warning
139
165
140
166
xs[8 ] && (++a + a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
141
167
// cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
142
168
xs[8 ] || (++a + a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
143
169
// cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
144
170
171
+ ((a++, false ) || (a++, false )); // no-warning PR39779
172
+ ((a++, true ) && (a++, true )); // no-warning PR39779
173
+
174
+ int i,j;
175
+ (i = g1 (), false ) || (j = g2 (i)); // no-warning PR22197
176
+ (i = g1 (), true ) && (j = g2 (i)); // no-warning PR22197
177
+
178
+ (a++, false ) || (a++, false ) || (a++, false ) || (a++, false ); // no-warning
179
+ (a++, true ) || (a++, true ) || (a++, true ) || (a++, true ); // no-warning
180
+ a = ((a++, false ) || (a++, false ) || (a++, false ) || (a++, false )); // no-warning
181
+ a = ((a++, true ) && (a++, true ) && (a++, true ) && (a++, true )); // no-warning
182
+ a = ((a++, false ) || (a++, false ) || (a++, false ) || a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
183
+ // TODO cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
184
+ a = ((a++, true ) && (a++, true ) && (a++, true ) && a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
185
+ // TODO cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
186
+ a = ((a++, false ) || (a++, false ) || (a++, false ) || (a + a, false )); // no-warning
187
+ a = ((a++, true ) && (a++, true ) && (a++, true ) && (a + a, true )); // no-warning
188
+
189
+ a = (false && a++); // no-warning
190
+ a = (true && a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
191
+ // TODO cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
192
+ a = (true && ++a); // no-warning
193
+ a = (true || a++); // no-warning
194
+ a = (false || a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
195
+ // TODO cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
196
+ a = (false || ++a); // no-warning
197
+
198
+ (a++) | (a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
199
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
200
+ (a++) & (a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
201
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
202
+ (a++) ^ (a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
203
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
204
+
145
205
(__builtin_classify_type (++a) ? 1 : 0 ) + ++a; // ok
146
206
(__builtin_constant_p (++a) ? 1 : 0 ) + ++a; // ok
147
207
(__builtin_object_size (&(++a, a), 0 ) ? 1 : 0 ) + ++a; // ok
0 commit comments