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) {
400400 " suspicious usage of 'sizeof(array)/sizeof(...)';"
401401 " denominator differs from the size of array elements" )
402402 << 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.
404406 diag (E->getOperatorLoc (),
405407 " suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions "
406408 " have the same type" )
Original file line number Diff line number Diff line change @@ -175,7 +175,8 @@ Changes in existing checks
175175- Improved :doc: `bugprone-sizeof-expression
176176 <clang-tidy/checks/bugprone/sizeof-expression>` check to find suspicious
177177 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.
179180
180181- Improved :doc: `bugprone-throw-keyword-missing
181182 <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() {
385385 sum += sizeof (PtrArray) / sizeof (A[0 ]);
386386 return sum;
387387}
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