Commit 7db342c0 authored by Kenton Varda's avatar Kenton Varda

Work around GCC 8's new -Wclass-memaccess.

parent a0d44664
......@@ -336,16 +336,28 @@ struct MessageSize {
using kj::byte;
class word { uint64_t content KJ_UNUSED_MEMBER; KJ_DISALLOW_COPY(word); public: word() = default; };
// word is an opaque type with size of 64 bits. This type is useful only to make pointer
// arithmetic clearer. Since the contents are private, the only way to access them is to first
// reinterpret_cast to some other pointer type.
//
// Copying is disallowed because you should always use memcpy(). Otherwise, you may run afoul of
// aliasing rules.
//
// A pointer of type word* should always be word-aligned even if won't actually be dereferenced as
// that type.
class word {
// word is an opaque type with size of 64 bits. This type is useful only to make pointer
// arithmetic clearer. Since the contents are private, the only way to access them is to first
// reinterpret_cast to some other pointer type.
//
// Copying is disallowed because you should always use memcpy(). Otherwise, you may run afoul of
// aliasing rules.
//
// A pointer of type word* should always be word-aligned even if won't actually be dereferenced
// as that type.
public:
word() = default;
private:
uint64_t content KJ_UNUSED_MEMBER;
#if __GNUC__ < 8 || __clang__
// GCC 8's -Wclass-memaccess complains whenever we try to memcpy() a `word` if we've disallowed
// the copy constructor. We don't want to disable the warning becaues it's a useful warning and
// we'd have to disable it for all applications that include this header. Instead we allow `word`
// to be copyable on GCC.
KJ_DISALLOW_COPY(word);
#endif
};
static_assert(sizeof(byte) == 1, "uint8_t is not one byte?");
static_assert(sizeof(word) == 8, "uint64_t is not 8 bytes?");
......
......@@ -72,6 +72,16 @@ namespace _ { // private
// =======================================================================================
#if __GNUC__ >= 8 && !__clang__
// GCC 8 introduced a warning which complains whenever we try to memset() or memcpy() a
// WirePointer, becaues we deleted the regular copy constructor / assignment operator. Weirdly, if
// I remove those deletions, GCC *still* complains that WirePointer is non-trivial. I don't
// understand why -- maybe because WireValue has private members? We don't want to make WireValue's
// member public, but memset() and memcpy() on it are certainly valid and desirable, so we'll just
// have to disable the warning I guess.
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
struct WirePointer {
// A pointer, in exactly the format in which it appears on the wire.
......
......@@ -249,6 +249,13 @@ private:
// -------------------------------------------------------------------
#if __GNUC__ >= 8 && !__clang__
// GCC 8's class-memaccess warning rightly does not like the memcpy()'s below, but there's no
// "legal" way for us to extract the contetn of a PTMF so too bad.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
class PtmfHelper {
// This class is a private helper for GetFunctorStartAddress. The class represents the internal
// representation of a pointer-to-member-function.
......@@ -310,6 +317,10 @@ class PtmfHelper {
#undef BODY
};
#if __GNUC__ >= 8 && !__clang__
#pragma GCC diagnostic pop
#endif
template <typename... ParamTypes>
struct GetFunctorStartAddress {
// Given a functor (any object defining operator()), return the start address of the function,
......
......@@ -906,7 +906,6 @@ Promise<Array<SocketAddress>> SocketAddress::lookupHost(
}
SocketAddress addr;
memset(&addr, 0, sizeof(addr)); // mollify valgrind
if (params.host == "*") {
// Set up a wildcard SocketAddress. Only use the port number returned by getaddrinfo().
addr.wildcard = true;
......
......@@ -249,6 +249,13 @@ EncodingResult<String> decodeUtf32(ArrayPtr<const char32_t> utf16) {
namespace {
#if __GNUC__ >= 8 && !__clang__
// GCC 8's new class-memaccess warning rightly dislikes the following hacks, but we're really sure
// we want to allow them so disable the warning.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
template <typename To, typename From>
Array<To> coerceTo(Array<From>&& array) {
static_assert(sizeof(To) == sizeof(From), "incompatible coercion");
......@@ -269,6 +276,10 @@ EncodingResult<Array<To>> coerceTo(EncodingResult<Array<From>>&& result) {
return { coerceTo<To>(Array<From>(kj::mv(result))), result.hadErrors };
}
#if __GNUC__ >= 8 && !__clang__
#pragma GCC diagnostic pop
#endif
template <size_t s>
struct WideConverter;
......
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