Commit bb19b301 authored by Joe Loser's avatar Joe Loser Committed by Facebook Github Bot

Allow trivially move constructible types to be relocatable (#1035)

Summary:
- If a type is not marked explicitly with `IsRelocatable`
  as `std::true_type`, we infer its relocability only based on the
  property of whether the type is trivially copyable.
- Extend the default relocability to also be true for trivially move
  constructible types.
Pull Request resolved: https://github.com/facebook/folly/pull/1035

Reviewed By: Orvid

Differential Revision: D14240127

Pulled By: yfeldblum

fbshipit-source-id: 1e15d312d1a8340417bba2beb1db30ce4c543b26
parent 01354e23
......@@ -456,10 +456,9 @@ template <class T>
struct IsRelocatable : std::conditional<
traits_detail::has_IsRelocatable<T>::value,
traits_detail::has_true_IsRelocatable<T>,
// TODO add this line (and some tests for it) when we
// upgrade to gcc 4.7
// std::is_trivially_move_constructible<T>::value ||
is_trivially_copyable<T>>::type {};
bool_constant<
std::is_trivially_move_constructible<T>::value ||
is_trivially_copyable<T>::value>>::type {};
template <class T>
struct IsZeroInitializable
......
......@@ -21,6 +21,7 @@
#include <type_traits>
#include <utility>
#include <folly/Portability.h>
#include <folly/ScopeGuard.h>
#include <folly/portability/GTest.h>
......@@ -98,6 +99,21 @@ TEST(Traits, unset) {
EXPECT_TRUE(IsRelocatable<F4>::value);
}
TEST(Traits, triviallyMoveConstructible) {
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wunneeded-member-function")
struct TriviallyMoveConstructible {
TriviallyMoveConstructible(const TriviallyMoveConstructible&) = delete;
TriviallyMoveConstructible& operator=(const TriviallyMoveConstructible&) =
delete;
TriviallyMoveConstructible(TriviallyMoveConstructible&&) = default;
TriviallyMoveConstructible& operator=(TriviallyMoveConstructible&&) =
delete;
};
EXPECT_TRUE(IsRelocatable<TriviallyMoveConstructible>::value);
FOLLY_POP_WARNING
}
TEST(Traits, bitAndInit) {
EXPECT_TRUE(IsZeroInitializable<int>::value);
EXPECT_FALSE(IsZeroInitializable<vector<int>>::value);
......
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