From: Philip Pronin Date: Wed, 12 Mar 2014 08:00:52 +0000 (-0700) Subject: update FOLLY_IS_TRIVIALLY_COPYABLE X-Git-Tag: v0.22.0~648 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e22f0a67786b71aa5d73bfe1b3cd30f9ba329356;p=folly.git update FOLLY_IS_TRIVIALLY_COPYABLE Summary: Let's make sure that boost version is intented to mean exactly the same as `std::is_trivially_copyable` (see 9 [class] / 6) to avoid any confusion (current boost path is more close to `std::is_trivially_copy_constructible` than to `std::is_trivially_copyable`; UPD: unfortunately, old versions of boost don't support `boost::has_trivial_move_constructor` and friends, so I can't completely mimic `std::is_trivially_copyable` here). As mentioned in the original comment, `__has_trivial_copy` returns 1 in case of deleted copy ctor in clang (contradicts 12.8 [class.copy] / 13 + 8.4.2 [dcl.fct.def.default] / 4), which makes `FOLLY_IS_TRIVIALLY_COPYABLE` accept `std::unique_ptr<>`; using `boost::has_trivial_destructor` would at least save us from the problems in this case. Alternative "solution" may be to rename `FOLLY_IS_TRIVIALLY_COPYABLE` to `FOLLY_IS_TRIVIALLY_COPY_CONSTRUCTIBLE`, and make sure `folly::small_vector` won't call dtor when memcopies the data around. Test Plan: fbconfig --clang folly/test:small_vector_test && fbmake runtests_opt (fails in trunk, passes with this diff) Reviewed By: pgriess@fb.com FB internal diff: D1216158 --- diff --git a/folly/Portability.h b/folly/Portability.h index b227ba0d..ab41ef4c 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -123,10 +123,13 @@ struct MaxAlign { char c; } __attribute__((aligned)); // to Boost otherwise. #if FOLLY_HAVE_STD__IS_TRIVIALLY_COPYABLE #include -#define FOLLY_IS_TRIVIALLY_COPYABLE(T) (std::is_trivially_copyable::value) +#define FOLLY_IS_TRIVIALLY_COPYABLE(T) \ + (std::is_trivially_copyable::value) #else #include -#define FOLLY_IS_TRIVIALLY_COPYABLE(T) (boost::has_trivial_copy::value) +#define FOLLY_IS_TRIVIALLY_COPYABLE(T) \ + (boost::has_trivial_copy::value && \ + boost::has_trivial_destructor::value) #endif #endif // __cplusplus diff --git a/folly/test/small_vector_test.cpp b/folly/test/small_vector_test.cpp index 7c1d8849..200257b7 100644 --- a/folly/test/small_vector_test.cpp +++ b/folly/test/small_vector_test.cpp @@ -63,6 +63,9 @@ static_assert(sizeof(small_vector), + "std::unique_ptr<> is trivially copyable"); + namespace { struct NontrivialType {