Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |