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

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

Issue 1771303002: WTF: Fix Vector<T> memcpy'ing incorrectly for some T. (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
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 d3ef548876db6d540ac964845425393e9a94e19f..35b0c18f4c9d89951bec1007492149931c72fe0e 100644
--- a/third_party/WebKit/Source/wtf/TypeTraits.h
+++ b/third_party/WebKit/Source/wtf/TypeTraits.h
@@ -48,12 +48,47 @@ enum WeakHandlingFlag {
WeakHandlingInCollections
};
+template <typename T, typename From>
+class IsAssignable {
+ typedef char YesType;
+ struct NoType {
+ char padding[8];
+ };
+
+ template <typename T2, typename From2, typename = decltype(std::declval<T2>() = std::declval<From2>(), 0)>
tzik 2016/03/08 11:52:48 Does this ", 0" take effect? If it's not, can we r
Yuta Kitamura 2016/03/09 05:14:27 Yeah, right. Fixed.
+ static YesType checkAssignability(int);
+ template <typename T2, typename From2>
+ static NoType checkAssignability(...);
+
+public:
+ static const bool value = sizeof(checkAssignability<T, From>(0)) == sizeof(YesType);
+};
+
+template <typename T>
+struct IsCopyAssignable {
+ static_assert(!std::is_reference<T>::value, "T must not be a reference.");
+ static const bool value = IsAssignable<T, const T&>::value;
+};
+
+template <typename T>
+struct IsMoveAssignable {
+ static_assert(!std::is_reference<T>::value, "T must not be a reference.");
+ static const bool value = IsAssignable<T, T&&>::value;
+};
+
template <typename T> struct IsTriviallyCopyAssignable {
- static const bool value = __has_trivial_assign(T);
+ static const bool value = __has_trivial_assign(T) && IsCopyAssignable<T>::value;
};
template <typename T> struct IsTriviallyMoveAssignable {
- static const bool value = __has_trivial_assign(T);
+ // TODO(yutak): This isn't really correct, because __has_trivial_assign appears to look only at copy constructor.
tzik 2016/03/08 11:52:49 s/copy constructor/copy assignment/?
yzshen1 2016/03/08 21:30:38 This comment scares me a little bit. :/ I think op
Yuta Kitamura 2016/03/09 05:14:26 I think that is a big no-no for us, because that c
Yuta Kitamura 2016/03/09 05:14:27 Yep you are right. Fixed.
+ // However, std::is_trivially_move_assignable isn't available at this moment, and there isn't a good way to
+ // write that ourselves.
+ //
+ // Having IsCopyAssignable<T>::value here is doubly wrong, but without it, the issue mentioned in crbug.com/592767
+ // becomes reproducible, because __has_trivial_assign(T) and IsMoveAssignable<T>::value are both true in that
+ // case.
+ static const bool value = __has_trivial_assign(T) && IsCopyAssignable<T>::value && IsMoveAssignable<T>::value;
};
template <typename T> struct IsTriviallyDefaultConstructible {
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/TypeTraitsTest.cpp » ('j') | third_party/WebKit/Source/wtf/VectorTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698