view: disable trivally copyable type warnings in util::read
This commit is contained in:
parent
20df746217
commit
0cea64fa14
12
view.hpp
12
view.hpp
@ -22,6 +22,7 @@
|
|||||||
#include "cast.hpp"
|
#include "cast.hpp"
|
||||||
#include "types/traits.hpp"
|
#include "types/traits.hpp"
|
||||||
#include "maths.hpp"
|
#include "maths.hpp"
|
||||||
|
#include "platform.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
@ -653,6 +654,14 @@ namespace util {
|
|||||||
ValueT
|
ValueT
|
||||||
read (util::view<ByteT*> &buffer)
|
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 ()))
|
if (unlikely (sizeof (ValueT) > buffer.size ()))
|
||||||
throw std::runtime_error ("insufficient data for extraction");
|
throw std::runtime_error ("insufficient data for extraction");
|
||||||
|
|
||||||
@ -660,6 +669,9 @@ namespace util {
|
|||||||
memcpy (&res, buffer.data (), sizeof (ValueT));
|
memcpy (&res, buffer.data (), sizeof (ValueT));
|
||||||
buffer = buffer.consume (sizeof (ValueT));
|
buffer = buffer.consume (sizeof (ValueT));
|
||||||
return res;
|
return res;
|
||||||
|
#if defined(COMPILER_GCC)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user