Commit 50fe1805 authored by Kenton Varda's avatar Kenton Varda

Fix canMemcpy assertions that are now broken on GCC 4.

parent ffd8ede2
...@@ -1453,13 +1453,12 @@ DynamicValue::Reader::Reader(const Reader& other) { ...@@ -1453,13 +1453,12 @@ DynamicValue::Reader::Reader(const Reader& other) {
case ENUM: case ENUM:
case STRUCT: case STRUCT:
case ANY_POINTER: case ANY_POINTER:
static_assert(kj::canMemcpy<Text::Reader>() && KJ_ASSERT_CAN_MEMCPY(Text::Reader);
kj::canMemcpy<Data::Reader>() && KJ_ASSERT_CAN_MEMCPY(Data::Reader);
kj::canMemcpy<DynamicList::Reader>() && KJ_ASSERT_CAN_MEMCPY(DynamicList::Reader);
kj::canMemcpy<DynamicEnum>() && KJ_ASSERT_CAN_MEMCPY(DynamicEnum);
kj::canMemcpy<DynamicStruct::Reader>() && KJ_ASSERT_CAN_MEMCPY(DynamicStruct::Reader);
kj::canMemcpy<AnyPointer::Reader>(), KJ_ASSERT_CAN_MEMCPY(AnyPointer::Reader);
"Assumptions here don't hold.");
break; break;
case CAPABILITY: case CAPABILITY:
...@@ -1484,13 +1483,12 @@ DynamicValue::Reader::Reader(Reader&& other) noexcept { ...@@ -1484,13 +1483,12 @@ DynamicValue::Reader::Reader(Reader&& other) noexcept {
case ENUM: case ENUM:
case STRUCT: case STRUCT:
case ANY_POINTER: case ANY_POINTER:
static_assert(kj::canMemcpy<Text::Reader>() && KJ_ASSERT_CAN_MEMCPY(Text::Reader);
kj::canMemcpy<Data::Reader>() && KJ_ASSERT_CAN_MEMCPY(Data::Reader);
kj::canMemcpy<DynamicList::Reader>() && KJ_ASSERT_CAN_MEMCPY(DynamicList::Reader);
kj::canMemcpy<DynamicEnum>() && KJ_ASSERT_CAN_MEMCPY(DynamicEnum);
kj::canMemcpy<DynamicStruct::Reader>() && KJ_ASSERT_CAN_MEMCPY(DynamicStruct::Reader);
kj::canMemcpy<AnyPointer::Reader>(), KJ_ASSERT_CAN_MEMCPY(AnyPointer::Reader);
"Assumptions here don't hold.");
break; break;
case CAPABILITY: case CAPABILITY:
......
...@@ -735,7 +735,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost( ...@@ -735,7 +735,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost(
addr.addrlen = cur->ai_addrlen; addr.addrlen = cur->ai_addrlen;
memcpy(&addr.addr.generic, cur->ai_addr, cur->ai_addrlen); memcpy(&addr.addr.generic, cur->ai_addr, cur->ai_addrlen);
} }
static_assert(canMemcpy<SocketAddress>(), "Can't write() SocketAddress..."); KJ_ASSERT_CAN_MEMCPY(SocketAddress);
output.write(&addr, sizeof(addr)); output.write(&addr, sizeof(addr));
cur = cur->ai_next; cur = cur->ai_next;
} }
......
...@@ -782,7 +782,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost( ...@@ -782,7 +782,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost(
addr.addrlen = cur->ai_addrlen; addr.addrlen = cur->ai_addrlen;
memcpy(&addr.addr.generic, cur->ai_addr, cur->ai_addrlen); memcpy(&addr.addr.generic, cur->ai_addr, cur->ai_addrlen);
} }
static_assert(canMemcpy<SocketAddress>(), "Can't write() SocketAddress..."); KJ_ASSERT_CAN_MEMCPY(SocketAddress);
const char* data = reinterpret_cast<const char*>(&addr); const char* data = reinterpret_cast<const char*>(&addr);
size_t size = sizeof(addr); size_t size = sizeof(addr);
......
...@@ -468,6 +468,7 @@ constexpr bool canMemcpy() { ...@@ -468,6 +468,7 @@ constexpr bool canMemcpy() {
// and assume we can't memcpy() at all, and must explicitly copy-construct everything. // and assume we can't memcpy() at all, and must explicitly copy-construct everything.
return false; return false;
} }
#define KJ_ASSERT_CAN_MEMCPY(T)
#else #else
template <typename T> template <typename T>
constexpr bool canMemcpy() { constexpr bool canMemcpy() {
...@@ -476,6 +477,8 @@ constexpr bool canMemcpy() { ...@@ -476,6 +477,8 @@ constexpr bool canMemcpy() {
return __is_trivially_constructible(T, const T&) && __is_trivially_assignable(T, const T&); return __is_trivially_constructible(T, const T&) && __is_trivially_assignable(T, const T&);
} }
#define KJ_ASSERT_CAN_MEMCPY(T) \
static_assert(kj::canMemcpy<T>(), "this code expects this type to be memcpy()-able");
#endif #endif
// ======================================================================================= // =======================================================================================
......
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