Index: clang-tidy/cppcoreguidelines/SlicingCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/SlicingCheck.cpp +++ clang-tidy/cppcoreguidelines/SlicingCheck.cpp @@ -122,11 +122,15 @@ BaseDecl->getASTContext().getASTRecordLayout(BaseDecl); const auto &DerivedLayout = DerivedDecl->getASTContext().getASTRecordLayout(DerivedDecl); - const auto StateSize = DerivedLayout.getDataSize() - BaseLayout.getDataSize(); - if (StateSize.isPositive()) { + const auto StateSizeInChars = + DerivedLayout.getDataSize() - BaseLayout.getDataSize(); + if (StateSizeInChars.isPositive()) { + const int StateSizeInBits = + static_cast(StateSizeInChars.getQuantity()) * + BaseDecl->getASTContext().getCharWidth(); diag(Call->getExprLoc(), "slicing object from type %0 to %1 discards " - "%2*sizeof(char) bytes of state") - << DerivedDecl << BaseDecl << static_cast(StateSize.getQuantity()); + "%2 bits of state") + << DerivedDecl << BaseDecl << StateSizeInBits; } } Index: test/clang-tidy/cppcoreguidelines-slicing.cpp =================================================================== --- test/clang-tidy/cppcoreguidelines-slicing.cpp +++ test/clang-tidy/cppcoreguidelines-slicing.cpp @@ -31,18 +31,18 @@ void positivesWithMemberVariables() { DerivedWithMemberVariables b; Base a{b}; - // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}}*sizeof(char) bytes of state [cppcoreguidelines-slicing] + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bits of state [cppcoreguidelines-slicing] a = b; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}}*sizeof(char) bytes of state + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bits of state TakesBaseByValue(b); - // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}}*sizeof(char) bytes of state + // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bits of state TwiceDerivedWithNoMemberVariables c; a = c; - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'TwiceDerivedWithNoMemberVariables' to 'Base' discards {{[0-9]*}}*sizeof(char) bytes of state + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'TwiceDerivedWithNoMemberVariables' to 'Base' discards {{[0-9]*}} bits of state a = ReturnsDerived(); - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}}*sizeof(char) bytes of state + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: slicing object from type 'DerivedWithMemberVariables' to 'Base' discards {{[0-9]*}} bits of state } void positivesWithOverride() {