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
+31Lines changed: 31 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -164,6 +164,37 @@ int Test2(MyConstChar* A) {
164
164
return sum;
165
165
}
166
166
167
+
structA {
168
+
int array[10];
169
+
};
170
+
171
+
structB {
172
+
structA a;
173
+
};
174
+
175
+
intsquare(int num, structB b) {
176
+
structA arr[10];
177
+
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
178
+
for(int i = 0; i < sizeof(arr); i++) {
179
+
structA a = arr[i];
180
+
}
181
+
// CHECK-MESSAGES: :[[@LINE+2]]:24: warning: suspicious usage of 'sizeof(K)'; did you mean 'K'? [bugprone-sizeof-expression]
182
+
// CHECK-MESSAGES: :[[@LINE+1]]:34: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator [bugprone-sizeof-expression]
183
+
for(int i = 0; i < sizeof(10)/sizeof(A); i++) {
184
+
structA a = arr[i];
185
+
}
186
+
187
+
for(int i = 0; i < sizeof(arr)/sizeof(A); i++) {
188
+
structA a = arr[i];
189
+
}
190
+
191
+
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
192
+
for(int j = 0; j < sizeof(b.a); j++) {
193
+
194
+
}
195
+
return2;
196
+
}
197
+
167
198
template <int T>
168
199
intFoo() { int A[T]; returnsizeof(T); }
169
200
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(K)'
0 commit comments