[clang-tools-extra] r290340 - [clang-tidy] cppcoreguidelines-slicing: display discarded state size in bytes
Clement Courbet via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 22 06:12:32 PST 2016
Author: courbet
Date: Thu Dec 22 08:12:31 2016
New Revision: 290340
URL: http://llvm.org/viewvc/llvm-project?rev=290340&view=rev
Log:
[clang-tidy] cppcoreguidelines-slicing: display discarded state size in bytes
https://reviews.llvm.org/D27212
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp
Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SlicingCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SlicingCheck.cpp?rev=290340&r1=290339&r2=290340&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SlicingCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SlicingCheck.cpp Thu Dec 22 08:12:31 2016
@@ -122,10 +122,11 @@ void SlicingCheck::check(const MatchFind
BaseDecl->getASTContext().getASTRecordLayout(BaseDecl);
const auto &DerivedLayout =
DerivedDecl->getASTContext().getASTRecordLayout(DerivedDecl);
- const auto StateSize = DerivedLayout.getDataSize() - BaseLayout.getDataSize();
+ const CharUnits StateSize =
+ DerivedLayout.getDataSize() - BaseLayout.getDataSize();
if (StateSize.isPositive()) {
diag(Call->getExprLoc(), "slicing object from type %0 to %1 discards "
- "%2*sizeof(char) bytes of state")
+ "%2 bytes of state")
<< DerivedDecl << BaseDecl << static_cast<int>(StateSize.getQuantity());
}
}
Modified: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp?rev=290340&r1=290339&r2=290340&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-slicing.cpp Thu Dec 22 08:12:31 2016
@@ -31,18 +31,18 @@ DerivedWithMemberVariables ReturnsDerive
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]*}} bytes 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]*}} bytes 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]*}} bytes 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]*}} bytes 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]*}} bytes of state
}
void positivesWithOverride() {
More information about the cfe-commits
mailing list