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

Unified Diff: third_party/WebKit/Source/wtf/TypeTraits.h

Issue 2200053002: Add TypeTraits template for checking safe bitfields (WIP) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_make_visibility_enum_class_rebase
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
Index: third_party/WebKit/Source/wtf/TypeTraits.h
diff --git a/third_party/WebKit/Source/wtf/TypeTraits.h b/third_party/WebKit/Source/wtf/TypeTraits.h
index c5199c173c2c4d6b9286d2ee525480ff9e326986..f0a0e7d6b167550370a26e2be94b5d2cfa100621 100644
--- a/third_party/WebKit/Source/wtf/TypeTraits.h
+++ b/third_party/WebKit/Source/wtf/TypeTraits.h
@@ -23,9 +23,11 @@
#define TypeTraits_h
#include <cstddef>
+#include <limits>
#include <type_traits>
#include <utility>
+#include "base/template_util.h"
#include "wtf/Compiler.h"
namespace WTF {
@@ -141,6 +143,18 @@ template <typename T> struct IsTriviallyDestructible {
#endif
};
+// In MSVC, enums default to 'int' as their underlying type, which means when
+// they are interpreted as signed when read out of a bitfield. This causes
+// issues when trying to serialize/deserialize an enum from a bitfield. To fix
+// this, ensure that all bitfields use an unsigned underlying type, e.g.
+// enum class Foo : unsigned {}.
+// TODO(sashab): Migrate this to be a clang plugin instead.
+template <typename T>
+struct IsEnumSafeToStoreInBitfield {
+ static_assert(std::is_enum<T>::value, "T must be an enum.");
+ static const bool value = !std::numeric_limits<base::underlying_type<T>>::is_signed;
+};
+
template <typename T, typename U> struct IsSubclass {
private:
typedef char YesType;

Powered by Google App Engine
This is Rietveld 408576698