File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -378,8 +378,7 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
378378 if (const auto *Type = dyn_cast<ArrayType>(SizeofArgTy)) {
379379 // check if the array element size is larger than one. If true,
380380 // the size of the array is higher than the number of elements
381- CharUnits SSize = Ctx.getTypeSizeInChars (Type->getElementType ());
382- if (!SSize.isOne ()) {
381+ if (!getSizeOfType (Ctx, Type->getElementType ().getTypePtr ()).isOne ()) {
383382 diag (SzOfExpr->getBeginLoc (),
384383 " suspicious usage of 'sizeof' in the loop" )
385384 << SzOfExpr->getSourceRange ();
Original file line number Diff line number Diff line change @@ -235,6 +235,10 @@ Changes in existing checks
235235 <clang-tidy/checks/bugprone/signed-char-misuse>` check by fixing
236236 false positives on C23 enums with the fixed underlying type of signed char.
237237
238+ - Improved :doc: `bugprone-sizeof-expression
239+ <clang-tidy/checks/bugprone/sizeof-expression>` check by fixing
240+ a crash on ``sizeof `` of an array of dependent type.
241+
238242- Improved :doc: `bugprone-tagged-union-member-count
239243 <clang-tidy/checks/bugprone/tagged-union-member-count>` by fixing a false
240244 positive when enums or unions from system header files or the ``std ``
Original file line number Diff line number Diff line change 1- // RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- -config="{CheckOptions: {bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression: true}}" --
1+ // RUN: %check_clang_tidy %s bugprone-sizeof-expression %t \
2+ // RUN: -- -config="{CheckOptions: {bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression: true}}" \
3+ // RUN: -- -fno-delayed-template-parsing
24
35class C {
46 int size () { return sizeof (this ); }
@@ -227,6 +229,13 @@ void loop_access_elements(int num, struct B b) {
227229 for (int i = 0 , j = 0 ; i < sizeof (arr) && j < sizeof (buf); i++, j++) {}
228230}
229231
232+ template <typename T>
233+ void templated_array () {
234+ T arr[10 ];
235+ // CHECK-MESSAGES: :[[@LINE+1]]:23: warning: suspicious usage of 'sizeof' in the loop [bugprone-sizeof-expression]
236+ for (int i = 0 ; i < sizeof (arr); ++i) {}
237+ }
238+
230239template <int T>
231240int Foo () { int A[T]; return sizeof (T); }
232241// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(K)'
You can’t perform that action at this time.
0 commit comments