Commit cdf0c2e8 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Account for different interpretations of "trivially copyable"

Unfortunately, different runtime libraries and/or compilers differ on
whether a class without any copy constructor, move constructor, copy
assignment and move assignment operator is considered trivially
copyable.
See discussion on https://crrev.com/c/941521.

This CL adds a comment about this, and deletes a test for this specific
case.

R=mstarzinger@chromium.org
CC=jyan@ca.ibm.com, ivica.bogosavljevic@mips.com

Change-Id: Ie07adda370e5e955b782e72356b50121477d4623
Reviewed-on: https://chromium-review.googlesource.com/944081
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51704}
parent 226da60f
......@@ -199,6 +199,10 @@ V8_INLINE Dest bit_cast(Source const& source) {
namespace v8 {
namespace base {
// Note that some implementations of std::is_trivially_copyable mandate that at
// least one of the copy constructor, move constructor, copy assignment or move
// assignment is non-deleted, while others do not. Be aware that also
// base::is_trivially_copyable will differ for these cases.
template <typename T>
struct is_trivially_copyable {
#if V8_CC_MSVC
......@@ -222,11 +226,8 @@ struct is_trivially_copyable {
// Move assignment operator is trivial or deleted.
(std::is_trivially_move_assignable<T>::value ||
!std::is_move_assignable<T>::value) &&
// One of the above is non-deleted.
(std::is_trivially_copy_constructible<T>::value ||
std::is_trivially_copy_assignable<T>::value ||
std::is_trivially_move_constructible<T>::value ||
std::is_trivially_move_assignable<T>::value) &&
// (Some implementations mandate that one of the above is non-deleted, but
// the standard does not, so let's skip this check.)
// Trivial non-deleted destructor.
std::is_trivially_destructible<T>::value;
......@@ -253,10 +254,10 @@ struct is_trivially_copyable {
#else
#define ASSERT_TRIVIALLY_COPYABLE(T) \
static_assert(::v8::base::is_trivially_copyable<T>::value, \
#T "should be trivially copyable")
#T " should be trivially copyable")
#define ASSERT_NOT_TRIVIALLY_COPYABLE(T) \
static_assert(!::v8::base::is_trivially_copyable<T>::value, \
#T "should not be trivially copyable")
#T " should not be trivially copyable")
#endif
// The USE(x, ...) template is used to silence C++ compiler warnings
......
......@@ -26,19 +26,17 @@ struct TriviallyCopyable {
};
ASSERT_TRIVIALLY_COPYABLE(TriviallyCopyable);
struct StillTriviallyCopyable {
const int i;
StillTriviallyCopyable(const StillTriviallyCopyable&) = delete;
};
ASSERT_TRIVIALLY_COPYABLE(StillTriviallyCopyable);
struct NonTrivialDestructor {
~NonTrivialDestructor() {}
};
ASSERT_NOT_TRIVIALLY_COPYABLE(NonTrivialDestructor);
struct NonCopyable {
NonCopyable(const NonCopyable&&) = delete;
NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator=(const NonCopyable&) = delete;
NonCopyable& operator=(const NonCopyable&&) = delete;
};
ASSERT_NOT_TRIVIALLY_COPYABLE(NonCopyable);
struct NonTrivialCopyConstructor {
NonTrivialCopyConstructor(const NonTrivialCopyConstructor&) {}
};
......
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