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) {
case ENUM:
case STRUCT:
case ANY_POINTER:
static_assert(kj::canMemcpy<Text::Reader>() &&
kj::canMemcpy<Data::Reader>() &&
kj::canMemcpy<DynamicList::Reader>() &&
kj::canMemcpy<DynamicEnum>() &&
kj::canMemcpy<DynamicStruct::Reader>() &&
kj::canMemcpy<AnyPointer::Reader>(),
"Assumptions here don't hold.");
KJ_ASSERT_CAN_MEMCPY(Text::Reader);
KJ_ASSERT_CAN_MEMCPY(Data::Reader);
KJ_ASSERT_CAN_MEMCPY(DynamicList::Reader);
KJ_ASSERT_CAN_MEMCPY(DynamicEnum);
KJ_ASSERT_CAN_MEMCPY(DynamicStruct::Reader);
KJ_ASSERT_CAN_MEMCPY(AnyPointer::Reader);
break;
case CAPABILITY:
......@@ -1484,13 +1483,12 @@ DynamicValue::Reader::Reader(Reader&& other) noexcept {
case ENUM:
case STRUCT:
case ANY_POINTER:
static_assert(kj::canMemcpy<Text::Reader>() &&
kj::canMemcpy<Data::Reader>() &&
kj::canMemcpy<DynamicList::Reader>() &&
kj::canMemcpy<DynamicEnum>() &&
kj::canMemcpy<DynamicStruct::Reader>() &&
kj::canMemcpy<AnyPointer::Reader>(),
"Assumptions here don't hold.");
KJ_ASSERT_CAN_MEMCPY(Text::Reader);
KJ_ASSERT_CAN_MEMCPY(Data::Reader);
KJ_ASSERT_CAN_MEMCPY(DynamicList::Reader);
KJ_ASSERT_CAN_MEMCPY(DynamicEnum);
KJ_ASSERT_CAN_MEMCPY(DynamicStruct::Reader);
KJ_ASSERT_CAN_MEMCPY(AnyPointer::Reader);
break;
case CAPABILITY:
......
......@@ -735,7 +735,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost(
addr.addrlen = 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));
cur = cur->ai_next;
}
......
......@@ -782,7 +782,7 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost(
addr.addrlen = 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);
size_t size = sizeof(addr);
......
......@@ -468,6 +468,7 @@ constexpr bool canMemcpy() {
// and assume we can't memcpy() at all, and must explicitly copy-construct everything.
return false;
}
#define KJ_ASSERT_CAN_MEMCPY(T)
#else
template <typename T>
constexpr bool canMemcpy() {
......@@ -476,6 +477,8 @@ constexpr bool canMemcpy() {
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
// =======================================================================================
......
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