File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -379,6 +379,8 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
379379 auto Loc = Result.Nodes .getNodeAs <Expr>(" sizeof-expr" );
380380
381381 if (const auto type = dyn_cast<ArrayType>(SizeofArgTy)) {
382+ // check if the array element size is larger than one. If true,
383+ // the size of the array is higher than the number of elements
382384 CharUnits sSize = Ctx.getTypeSizeInChars (type->getElementType ());
383385 if (!sSize .isOne ()) {
384386 diag (Loc->getBeginLoc (), " suspicious usage of 'sizeof' in the loop" )
Original file line number Diff line number Diff line change @@ -146,6 +146,13 @@ Changes in existing checks
146146 <clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
147147 conversion in argument of ``std::make_optional ``.
148148
149+ - Improved :doc: `bugprone-sizeof-expression
150+ <clang-tidy/checks/bugprone/bugprone-sizeof-expression> ` check by adding
151+ `WarnOnSizeOfInLoopTermination ` option to detect misuses of ``sizeof ``
152+ expression in loop conditions. The check detects the use of ``sizeof ``
153+ opertaor to determine the number of elements in the array, where the
154+ array size is higher than the number of elements in the array.
155+
149156- Improved :doc: `bugprone-string-constructor
150157 <clang-tidy/checks/bugprone/string-constructor>` check to find suspicious
151158 calls of ``std::string `` constructor with char pointer, start position and
@@ -219,11 +226,6 @@ Changes in existing checks
219226 tolerating fix-it breaking compilation when functions is used as pointers
220227 to avoid matching usage of functions within the current compilation unit.
221228
222- - Improved :doc: `bugprone-sizeof-expression
223- <clang-tidy/checks/bugprone/bugprone-sizeof-expression> ` check by adding
224- `WarnOnSizeOfInLoopTermination ` option to detect misuses of ``sizeof ``
225- expression in loop conditions.
226-
227229Removed checks
228230^^^^^^^^^^^^^^
229231
You can’t perform that action at this time.
0 commit comments