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

Unified Diff: Source/wtf/SizeAssertions.h

Issue 1317143005: [WIP] do something :-) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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 | « Source/platform/text/BidiContext.cpp ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/SizeAssertions.h
diff --git a/Source/wtf/SizeAssertions.h b/Source/wtf/SizeAssertions.h
new file mode 100644
index 0000000000000000000000000000000000000000..e7e90e8a418676e390ea9dbdb1641a577e971db4
--- /dev/null
+++ b/Source/wtf/SizeAssertions.h
@@ -0,0 +1,32 @@
+#ifndef WTF_SizeAssertions_h
+#define WTF_SizeAssertions_h
+
+#include "wtf/CPU.h"
+
+namespace WTF {
+
+template<class T, int Expected32BitSize, int Expected64BitSize> struct assert_size {
+ template<int ActualSize, int ExpectedSize> class assert_equal {
+ static_assert(ActualSize == ExpectedSize,
+ "Object size doesn't match expected value, think before making them bigger :-)");
+ };
+#if CPU(32BIT)
+ assert_equal<sizeof(T), Expected32BitSize> tmp;
+#else
+ assert_equal<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)
+#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 | « Source/platform/text/BidiContext.cpp ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698