File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -400,7 +400,9 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
400
400
" suspicious usage of 'sizeof(array)/sizeof(...)';"
401
401
" denominator differs from the size of array elements" )
402
402
<< E->getLHS ()->getSourceRange () << E->getRHS ()->getSourceRange ();
403
- } else if (NumTy && DenomTy && NumTy == DenomTy) {
403
+ } else if (NumTy && DenomTy && NumTy == DenomTy &&
404
+ !NumTy->isDependentType ()) {
405
+ // Dependent type should not be compared.
404
406
diag (E->getOperatorLoc (),
405
407
" suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions "
406
408
" have the same type" )
Original file line number Diff line number Diff line change @@ -175,7 +175,8 @@ Changes in existing checks
175
175
- Improved :doc: `bugprone-sizeof-expression
176
176
<clang-tidy/checks/bugprone/sizeof-expression>` check to find suspicious
177
177
usages of ``sizeof() ``, ``alignof() ``, and ``offsetof() `` when adding or
178
- subtracting from a pointer directly or when used to scale a numeric value.
178
+ subtracting from a pointer directly or when used to scale a numeric value and
179
+ fix false positive when sizeof expression with template types.
179
180
180
181
- Improved :doc: `bugprone-throw-keyword-missing
181
182
<clang-tidy/checks/bugprone/throw-keyword-missing>` by fixing a false positive
Original file line number Diff line number Diff line change @@ -385,3 +385,10 @@ int ValidExpressions() {
385
385
sum += sizeof (PtrArray) / sizeof (A[0 ]);
386
386
return sum;
387
387
}
388
+
389
+ namespace gh115175 {
390
+ template <class T >
391
+ int ValidateTemplateTypeExpressions (T t) {
392
+ return sizeof (t.val ) / sizeof (t.val [0 ]);
393
+ }
394
+ } // namespace gh115175
You can’t perform that action at this time.
0 commit comments