Skip to content

Commit

Permalink
Allow trivially move constructible types to be relocatable (facebook#…
Browse files Browse the repository at this point in the history
…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: facebook#1035

Reviewed By: Orvid

Differential Revision: D14240127

Pulled By: yfeldblum

fbshipit-source-id: 1e15d312d1a8340417bba2beb1db30ce4c543b26
  • Loading branch information
JoeLoser authored and sandraiser committed Mar 4, 2019
1 parent 8eede35 commit fa87a7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions folly/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions folly/test/TraitsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <type_traits>
#include <utility>

#include <folly/Portability.h>
#include <folly/ScopeGuard.h>
#include <folly/portability/GTest.h>

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fa87a7f

Please sign in to comment.