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

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: Review feedback Created 4 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WTF_SizeAssertions_h
6 #define WTF_SizeAssertions_h
7
8 namespace WTF {
9
10 // The ASSERT_SIZE macro can be used to check that a given struct is the same
11 // size as a class. This is useful to visualize where the space is being used in
12 // a class, as well as give a useful compile error message when the size doesn't
13 // match the expected value.
14 template<class T, class U> struct assert_size {
15 template<int ActualSize, int ExpectedSize> struct assertSizeEqual {
16 static_assert(ActualSize == ExpectedSize, "Class should stay small");
17 static const bool innerValue = true;
18 };
19 static const bool value = assertSizeEqual<sizeof(T), sizeof(U)>::innerValue;
20 };
21
22 } // namespace WTF
23
24 #define ASSERT_SIZE(className, sameSizeAsClassName) \
25 static_assert(WTF::assert_size<className, sameSizeAsClassName>::value, "");
26
27 #endif // WTF_SizeAssertions_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698