summaryrefslogtreecommitdiff
path: root/base/bit_cast.h
diff options
context:
space:
mode:
authorJay Civelli <jcivelli@google.com>2017-03-22 17:31:44 -0700
committerTreehugger Robot <treehugger-gerrit@google.com>2017-07-26 01:47:45 +0000
commit0601274935e7f632eb0d6ce0fd223b744349d20b (patch)
tree09642629eabdbeccfd68e6338253228465088c57 /base/bit_cast.h
parentf320c0cf71af274e34404746d4303e6a2452e2d6 (diff)
downloadlibchrome-0601274935e7f632eb0d6ce0fd223b744349d20b.tar.gz
libchrome: Uprev the library to r456626 from Chromium
Pulled the latest and greatest version of libchrome from Chromium. The merge was done against r456626 which corresponds to git commit 08266b3fca707804065a2cfd60331722ade41969 of Mar 14, 2017 Notable changes are: - FOR_EACH_OBSERVER macro removed (replaced by use of C++ 11 range-base for loop) - base::Values no more FundamentalValue - stl_util moved to base namespace - some scoped pointers removed in crypto/ in favor of BoringSSL UniquePtr. - path() accessor renamed to GetPath() in ScopedTempDir (and other classes) - introduction of base::CallbackOnce Test: All unit-tests should still pass. Change-Id: I5c2cb41ea4c037fe69fbb425e711b1399d55d591
Diffstat (limited to 'base/bit_cast.h')
-rw-r--r--base/bit_cast.h33
1 files changed, 5 insertions, 28 deletions
diff --git a/base/bit_cast.h b/base/bit_cast.h
index c9514bceef..90dd925e86 100644
--- a/base/bit_cast.h
+++ b/base/bit_cast.h
@@ -9,6 +9,7 @@
#include <type_traits>
#include "base/compiler_specific.h"
+#include "base/template_util.h"
#include "build/build_config.h"
// bit_cast<Dest,Source> is a template function that implements the equivalent
@@ -63,34 +64,10 @@ template <class Dest, class Source>
inline Dest bit_cast(const Source& source) {
static_assert(sizeof(Dest) == sizeof(Source),
"bit_cast requires source and destination to be the same size");
-
-#if (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1) || \
- (defined(__clang__) && defined(_LIBCPP_VERSION)))
- // GCC 5.1 contains the first libstdc++ with is_trivially_copyable.
- // Assume libc++ Just Works: is_trivially_copyable added on May 13th 2011.
- // However, with libc++ when GCC is the compiler the trait is buggy, see
- // crbug.com/607158, so fall back to the less strict variant for non-clang.
- static_assert(std::is_trivially_copyable<Dest>::value,
- "non-trivially-copyable bit_cast is undefined");
- static_assert(std::is_trivially_copyable<Source>::value,
- "non-trivially-copyable bit_cast is undefined");
-#elif HAS_FEATURE(is_trivially_copyable)
- // The compiler supports an equivalent intrinsic.
- static_assert(__is_trivially_copyable(Dest),
- "non-trivially-copyable bit_cast is undefined");
- static_assert(__is_trivially_copyable(Source),
- "non-trivially-copyable bit_cast is undefined");
-#elif COMPILER_GCC
- // Fallback to compiler intrinsic on GCC and clang (which pretends to be
- // GCC). This isn't quite the same as is_trivially_copyable but it'll do for
- // our purpose.
- static_assert(__has_trivial_copy(Dest),
- "non-trivially-copyable bit_cast is undefined");
- static_assert(__has_trivial_copy(Source),
- "non-trivially-copyable bit_cast is undefined");
-#else
- // Do nothing, let the bots handle it.
-#endif
+ static_assert(base::is_trivially_copyable<Dest>::value,
+ "bit_cast requires the destination type to be copyable");
+ static_assert(base::is_trivially_copyable<Source>::value,
+ "bit_cast requires the source type to be copyable");
Dest dest;
memcpy(&dest, &source, sizeof(dest));