You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp
+31-31Lines changed: 31 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -173,44 +173,44 @@ struct B {
173
173
};
174
174
175
175
voidloop_access_elements(int num, structB b) {
176
-
structA arr[10];
177
-
char buf[20];
178
-
179
-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
180
-
for(int i = 0; i < sizeof(arr); i++) {
181
-
structA a = arr[i];
182
-
}
183
-
184
-
// Loop warning should not trigger here, even though this code is incorrect
185
-
// CHECK-MESSAGES: :[[@LINE+2]]:24: warning: suspicious usage of 'sizeof(K)'; did you mean 'K'? [bugprone-sizeof-expression]
186
-
// CHECK-MESSAGES: :[[@LINE+1]]:34: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator [bugprone-sizeof-expression]
187
-
for(int i = 0; i < sizeof(10)/sizeof(A); i++) {
188
-
structA a = arr[i];
189
-
}
176
+
structA arr[10];
177
+
char buf[20];
178
+
179
+
// CHECK-MESSAGES: :[[@LINE+1]]:22: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
180
+
for(int i = 0; i < sizeof(arr); i++) {
181
+
structA a = arr[i];
182
+
}
183
+
184
+
// Loop warning should not trigger here, even though this code is incorrect
185
+
// CHECK-MESSAGES: :[[@LINE+2]]:22: warning: suspicious usage of 'sizeof(K)'; did you mean 'K'? [bugprone-sizeof-expression]
186
+
// CHECK-MESSAGES: :[[@LINE+1]]:32: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator [bugprone-sizeof-expression]
187
+
for(int i = 0; i < sizeof(10)/sizeof(A); i++) {
188
+
structA a = arr[i];
189
+
}
190
190
191
-
// Should not warn here
192
-
for(int i = 0; i < sizeof(arr)/sizeof(A); i++) {}
191
+
// Should not warn here
192
+
for(int i = 0; i < sizeof(arr)/sizeof(A); i++) {}
193
193
194
-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
195
-
for(int j = 0; j < sizeof(b.a.array); j++) {}
194
+
// CHECK-MESSAGES: :[[@LINE+1]]:22: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
195
+
for(int j = 0; j < sizeof(b.a.array); j++) {}
196
196
197
-
// Should not warn here
198
-
for(int i = 0; i < sizeof(buf); i++) {}
197
+
// Should not warn here
198
+
for(int i = 0; i < sizeof(buf); i++) {}
199
199
200
-
int i = 0;
201
-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
202
-
while(i <= sizeof(arr)) {i++;}
200
+
int i = 0;
201
+
// CHECK-MESSAGES: :[[@LINE+1]]:14: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
202
+
while(i <= sizeof(arr)) {i++;}
203
203
204
-
i = 0;
205
-
do {
206
-
i++;
207
-
} while(i <= sizeof(arr));
204
+
i = 0;
205
+
do {
206
+
i++;
207
+
// CHECK-MESSAGES: :[[@LINE+1]]:16: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
208
+
} while(i <= sizeof(arr));
209
+
210
+
// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
211
+
for(int i = 0, j = 0; i < sizeof(arr) && j < sizeof(buf); i++, j++) {}
208
212
}
209
213
210
-
// Add cases for while loop
211
-
212
-
// Add cases for do-while loop
213
-
214
214
template <int T>
215
215
intFoo() { int A[T]; returnsizeof(T); }
216
216
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(K)'
0 commit comments