Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Unified Diff: base/bit_cast.h

Issue 2583353002: Make bit_cast fail if the source or dest are not trivially copyable (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/bit_cast_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bit_cast.h
diff --git a/base/bit_cast.h b/base/bit_cast.h
index c9514bceef4d861f660aa200eaccc997c6588361..04c1957f6aca0b1d2e453cfe2e619274398b15ca 100644
--- a/base/bit_cast.h
+++ b/base/bit_cast.h
@@ -63,6 +63,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");
+ static_assert(std::is_trivially_copyable<Dest>::value,
+ "bit_cast requires the destination type to be copyable");
+ static_assert(std::is_trivially_copyable<Source>::value,
+ "bit_cast requires the source type to be copyable");
#if (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1) || \
(defined(__clang__) && defined(_LIBCPP_VERSION)))
« no previous file with comments | « no previous file | base/bit_cast_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698