view: disable trivally copyable type warnings in util::read

This commit is contained in:
Danny Robson 2018-08-02 00:49:25 +10:00
parent 20df746217
commit 0cea64fa14

View File

@ -22,6 +22,7 @@
#include "cast.hpp"
#include "types/traits.hpp"
#include "maths.hpp"
#include "platform.hpp"
#include <cstdlib>
#include <iosfwd>
@ -653,6 +654,14 @@ namespace util {
ValueT
read (util::view<ByteT*> &buffer)
{
// we disable the class-memaccess warning so that we can memcpy into
// types that we know are safe but the compiler will complain about.
// this occurs commonly with oddly packed structures, eg anything
// that uses gnu::packed
#if defined(COMPILER_GCC)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
if (unlikely (sizeof (ValueT) > buffer.size ()))
throw std::runtime_error ("insufficient data for extraction");
@ -660,6 +669,9 @@ namespace util {
memcpy (&res, buffer.data (), sizeof (ValueT));
buffer = buffer.consume (sizeof (ValueT));
return res;
#if defined(COMPILER_GCC)
#pragma GCC diagnostic pop
#endif
}