From e68d8f939c14d0e185f95ca66f512d0d4cf105db Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 1 May 2019 00:13:22 +0300 Subject: [PATCH] static_assert the requirements of endian_load and endian_store --- include/boost/endian/detail/endian_load.hpp | 6 +++++- include/boost/endian/detail/endian_store.hpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/boost/endian/detail/endian_load.hpp b/include/boost/endian/detail/endian_load.hpp index 8e8a3f7..8dd9a20 100644 --- a/include/boost/endian/detail/endian_load.hpp +++ b/include/boost/endian/detail/endian_load.hpp @@ -33,13 +33,17 @@ template inline T endian_load( unsigned char const * p ) BOOST_NOEXCEPT { + BOOST_STATIC_ASSERT( sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8 ); + BOOST_STATIC_ASSERT( N >= 1 && N <= sizeof(T) ); + return detail::endian_load_impl()( p ); } diff --git a/include/boost/endian/detail/endian_store.hpp b/include/boost/endian/detail/endian_store.hpp index 06b4d90..a624352 100644 --- a/include/boost/endian/detail/endian_store.hpp +++ b/include/boost/endian/detail/endian_store.hpp @@ -32,13 +32,17 @@ template inline void endian_store( unsigned char * p, T const & v ) BOOST_NOEXCEPT { + BOOST_STATIC_ASSERT( sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8 ); + BOOST_STATIC_ASSERT( N >= 1 && N <= sizeof(T) ); + return detail::endian_store_impl()( p, v ); }