From 6c173766e32a226a085b9d44ad8a60230d848b9c Mon Sep 17 00:00:00 2001 From: Beman Date: Wed, 10 Dec 2014 15:03:06 -0500 Subject: [PATCH] Eliminate gcc -Wconversion warnings. --- include/boost/endian/buffers.hpp | 8 ++--- .../boost/endian/detail/cover_operators.hpp | 36 ++++++++++++------- test/endian_test.cpp | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/include/boost/endian/buffers.hpp b/include/boost/endian/buffers.hpp index 38e1b13..5d539df 100644 --- a/include/boost/endian/buffers.hpp +++ b/include/boost/endian/buffers.hpp @@ -236,19 +236,19 @@ namespace endian typedef unrolled_byte_loops next; static T load_big(const unsigned char* bytes) BOOST_NOEXCEPT - { return *(bytes - 1) | (next::load_big(bytes - 1) << 8); } + { return static_cast(*(bytes - 1) | (next::load_big(bytes - 1) << 8)); } static T load_little(const unsigned char* bytes) BOOST_NOEXCEPT - { return *bytes | (next::load_little(bytes + 1) << 8); } + { return static_cast(*bytes | (next::load_little(bytes + 1) << 8)); } static void store_big(char* bytes, T value) BOOST_NOEXCEPT { *(bytes - 1) = static_cast(value); - next::store_big(bytes - 1, value >> 8); + next::store_big(bytes - 1, static_cast(value >> 8)); } static void store_little(char* bytes, T value) BOOST_NOEXCEPT { *bytes = static_cast(value); - next::store_little(bytes + 1, value >> 8); + next::store_little(bytes + 1, static_cast(value >> 8)); } }; diff --git a/include/boost/endian/detail/cover_operators.hpp b/include/boost/endian/detail/cover_operators.hpp index dabf187..b877d86 100644 --- a/include/boost/endian/detail/cover_operators.hpp +++ b/include/boost/endian/detail/cover_operators.hpp @@ -62,20 +62,32 @@ namespace boost # endif // The basic arithmetic operations. - friend D& operator+=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x + y; } - friend D& operator-=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x - y; } - friend D& operator*=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x * y; } - friend D& operator/=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x / y; } - friend D& operator%=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x % y; } - friend D& operator&=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x & y; } - friend D& operator|=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x | y; } - friend D& operator^=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x ^ y; } - friend D& operator<<=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x << y; } - friend D& operator>>=(D& x, ArithmeticT y) BOOST_NOEXCEPT { return x = +x >> y; } + friend D& operator+=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x + y); } + friend D& operator-=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x - y); } + friend D& operator*=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x * y); } + friend D& operator/=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x / y); } + friend D& operator%=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x % y); } + friend D& operator&=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x & y); } + friend D& operator|=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x | y); } + friend D& operator^=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x ^ y); } + friend D& operator<<=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x << y); } + friend D& operator>>=(D& x, ArithmeticT y) BOOST_NOEXCEPT + { return x = static_cast(+x >> y); } // A few binary arithmetic operations not covered by operators base class. - friend ArithmeticT operator<<(const D& x, ArithmeticT y) BOOST_NOEXCEPT { return +x << y; } - friend ArithmeticT operator>>(const D& x, ArithmeticT y) BOOST_NOEXCEPT { return +x >> y; } + friend ArithmeticT operator<<(const D& x, ArithmeticT y) BOOST_NOEXCEPT + { return static_cast(+x << y); } + friend ArithmeticT operator>>(const D& x, ArithmeticT y) BOOST_NOEXCEPT + { return static_cast(+x >> y); } // Auto-increment and auto-decrement can be defined in terms of the // arithmetic operations. diff --git a/test/endian_test.cpp b/test/endian_test.cpp index 2c06092..8848be8 100644 --- a/test/endian_test.cpp +++ b/test/endian_test.cpp @@ -74,7 +74,7 @@ namespace ++v; // verify integer_cover_operators being applied to this type - // will fail to compile if no endian<> specialization is present - Endian x(v+v); + Endian x(static_cast(v+v)); if ( x == x ) // silence warning return; }