Commit e9ac448f authored by Andre Pinto's avatar Andre Pinto Committed by Facebook Github Bot

Fix small_vector on gcc 49

Summary:
In folly::small_vector, we were (mistakenly) relying on a default constructor
for non-trivially constructible types.

The problem got worse on gcc 4.9, because for that compiler version, we set
folly::is_trivially_copyable to be std::is_trivial. This is mostly okay, as
std::is_trivial implies std::is_trivially_copyable. The problem is that
std::is_trivial also implies std::is_default_constructuble, which which was
breaking folly::small_vector

Reviewed By: yfeldblum

Differential Revision: D8346780

fbshipit-source-id: 9c8a9dab21ea2d4fd34f636458324915c30e10a2
parent 1f456545
...@@ -102,7 +102,9 @@ namespace detail { ...@@ -102,7 +102,9 @@ namespace detail {
* memory is initialized to type T already. * memory is initialized to type T already.
*/ */
template <class T> template <class T>
typename std::enable_if<!folly::is_trivially_copyable<T>::value>::type typename std::enable_if<
std::is_default_constructible<T>::value &&
!folly::is_trivially_copyable<T>::value>::type
moveObjectsRight(T* first, T* lastConstructed, T* realLast) { moveObjectsRight(T* first, T* lastConstructed, T* realLast) {
if (lastConstructed == realLast) { if (lastConstructed == realLast) {
return; return;
...@@ -139,7 +141,9 @@ moveObjectsRight(T* first, T* lastConstructed, T* realLast) { ...@@ -139,7 +141,9 @@ moveObjectsRight(T* first, T* lastConstructed, T* realLast) {
// std::move_backward here will just turn into a memmove. (TODO: // std::move_backward here will just turn into a memmove. (TODO:
// change to std::is_trivially_copyable when that works.) // change to std::is_trivially_copyable when that works.)
template <class T> template <class T>
typename std::enable_if<folly::is_trivially_copyable<T>::value>::type typename std::enable_if<
!std::is_default_constructible<T>::value ||
folly::is_trivially_copyable<T>::value>::type
moveObjectsRight(T* first, T* lastConstructed, T* realLast) { moveObjectsRight(T* first, T* lastConstructed, T* realLast) {
std::move_backward(first, lastConstructed, realLast); std::move_backward(first, lastConstructed, realLast);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment