[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 20 06:31:58 PDT 2024


================
@@ -342,31 +342,33 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
 
     if (DenominatorSize > CharUnits::Zero() &&
         !NumeratorSize.isMultipleOf(DenominatorSize)) {
-      diag(E->getOperatorLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';"
+      diag(E->getOperatorLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)':"
                                 " numerator is not a multiple of denominator")
           << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     } else if (ElementSize > CharUnits::Zero() &&
                DenominatorSize > CharUnits::Zero() &&
                ElementSize != DenominatorSize) {
-      diag(E->getOperatorLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';"
-                                " numerator is not a multiple of denominator")
+      diag(E->getOperatorLoc(),
+           "suspicious usage of 'sizeof(array)/sizeof(...)':"
+           " denominator differs from the size of array elements")
----------------
NagyDonat wrote:

Yes, this is only triggered when `arrayType(hasElementType(recordType().bind("elem-type")))` matches, so we have an array type whose elements are records.


https://github.com/llvm/llvm-project/pull/95550


More information about the cfe-commits mailing list