Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: third_party/WebKit/Source/wtf/SizeAssertions.h

Issue 2231953003: Added ASSERT_SIZE macro for checking size of size-sensitive classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSValue.cpp ('k') | third_party/WebKit/Source/wtf/wtf.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #ifndef WTF_SizeAssertions_h
2 #define WTF_SizeAssertions_h
3
4 #include "wtf/CPU.h"
5
6 namespace WTF {
7
8 // Expected32BitSize and Expected64BitSize are in bytes. Use a template instead
9 // of a plain static assert so that failure messages give the expected number.
10 template<class T, int Expected32BitSize, int Expected64BitSize> struct assert_si ze {
11 template<int ActualSize, int ExpectedSize> class assertSizeEqual {
12 static_assert(ActualSize == ExpectedSize,
13 "Object size doesn't match expected value, think before making it bi gger :-)");
14 };
15 #if CPU(32BIT)
16 assertSizeEqual<sizeof(T), Expected32BitSize> tmp;
17 #else
18 assertSizeEqual<sizeof(T), Expected64BitSize> tmp;
19 #endif
20 enum { Dummy = 1 };
21 };
22
23 } // namespace WTF
24
25 // Some objects have additional members when asserts are enabled, so only check
26 // sizes when they are disabled.
27 #if ENABLE(ASSERT)
esprehn 2016/08/11 09:47:40 The bots and CQ always enable asserts, so this mea
28 #define ASSERT_SIZE(className, expected32BitSize, expected64BitSize)
29 #else
30 #define ASSERT_SIZE(className, expected32BitSize, expected64BitSize) \
31 static_assert(WTF::assert_size<className, expected32BitSize, expected64BitSi ze>::Dummy, "");
32 #endif
33
34 #endif // WTF_SizeAssertions_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSValue.cpp ('k') | third_party/WebKit/Source/wtf/wtf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698