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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/SizeAssertions.h
diff --git a/third_party/WebKit/Source/wtf/SizeAssertions.h b/third_party/WebKit/Source/wtf/SizeAssertions.h
new file mode 100644
index 0000000000000000000000000000000000000000..176d980fb60b5f691bdac9f83cdf52421c72ea25
--- /dev/null
+++ b/third_party/WebKit/Source/wtf/SizeAssertions.h
@@ -0,0 +1,34 @@
+#ifndef WTF_SizeAssertions_h
+#define WTF_SizeAssertions_h
+
+#include "wtf/CPU.h"
+
+namespace WTF {
+
+// Expected32BitSize and Expected64BitSize are in bytes. Use a template instead
+// of a plain static assert so that failure messages give the expected number.
+template<class T, int Expected32BitSize, int Expected64BitSize> struct assert_size {
+ template<int ActualSize, int ExpectedSize> class assertSizeEqual {
+ static_assert(ActualSize == ExpectedSize,
+ "Object size doesn't match expected value, think before making it bigger :-)");
+ };
+#if CPU(32BIT)
+ assertSizeEqual<sizeof(T), Expected32BitSize> tmp;
+#else
+ assertSizeEqual<sizeof(T), Expected64BitSize> tmp;
+#endif
+ enum { Dummy = 1 };
+};
+
+} // namespace WTF
+
+// Some objects have additional members when asserts are enabled, so only check
+// sizes when they are disabled.
+#if ENABLE(ASSERT)
esprehn 2016/08/11 09:47:40 The bots and CQ always enable asserts, so this mea
+#define ASSERT_SIZE(className, expected32BitSize, expected64BitSize)
+#else
+#define ASSERT_SIZE(className, expected32BitSize, expected64BitSize) \
+ static_assert(WTF::assert_size<className, expected32BitSize, expected64BitSize>::Dummy, "");
+#endif
+
+#endif // WTF_SizeAssertions_h
« 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