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

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

Issue 1785653002: WTF TypeTraits: Fix IsTrivially{DefaultConstructible,Destructible}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | third_party/WebKit/Source/wtf/TypeTraitsTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c6a052308bed20a8cb638c66d795995be912c78b..4b9fef359bb11e3cce67b2c97e4d1bbec389c0bb 100644
--- a/third_party/WebKit/Source/wtf/TypeTraits.h
+++ b/third_party/WebKit/Source/wtf/TypeTraits.h
@@ -106,14 +106,41 @@ template <typename T> struct IsTriviallyMoveAssignable {
static const bool value = IsTriviallyCopyAssignable<T>::value;
};
+// Same as above, but for __has_trivial_constructor and __has_trivial_destructor. For IsTriviallyDefaultConstructible,
+// we don't have to write IsDefaultConstructible ourselves since we can use std::is_constructible<T>. For
+// IsTriviallyDestructible, though, we can't rely on std::is_destructible<T> right now.
+#if !COMPILER(MSVC) || COMPILER(CLANG)
+template <typename T>
+class IsDestructible {
+ typedef char YesType;
+ struct NoType {
+ char padding[8];
+ };
+
+ template <typename T2, typename = decltype(std::declval<T2>().~T2())>
+ static YesType checkDestructibility(int);
+ template <typename T2>
+ static NoType checkDestructibility(...);
+
+public:
+ static const bool value = sizeof(checkDestructibility<T>(0)) == sizeof(YesType);
+};
+#endif
+
template <typename T> struct IsTriviallyDefaultConstructible {
- // TODO(yutak): Below has the same issue as crbug.com/592767.
+#if COMPILER(MSVC) && !COMPILER(CLANG)
static const bool value = __has_trivial_constructor(T);
+#else
+ static const bool value = __has_trivial_constructor(T) && std::is_constructible<T>::value;
+#endif
};
template <typename T> struct IsTriviallyDestructible {
- // TODO(yutak): Ditto.
+#if COMPILER(MSVC) && !COMPILER(CLANG)
static const bool value = __has_trivial_destructor(T);
+#else
+ static const bool value = __has_trivial_destructor(T) && IsDestructible<T>::value;
+#endif
};
template <typename T, typename U> struct IsSubclass {
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/TypeTraitsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698