From 4f10505d0964894e956eaefa6203bf1640d18c27 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 27 Mar 2018 20:16:32 +1100 Subject: [PATCH] build: fix warnings from -Wparentheses --- bitwise.hpp | 4 ++-- fixed.cpp | 2 +- fixed.hpp | 10 +++++++++- json2/personality/jsonish.cpp | 6 +++--- maths.hpp | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bitwise.hpp b/bitwise.hpp index 3e76f76e..46e491bb 100644 --- a/bitwise.hpp +++ b/bitwise.hpp @@ -39,7 +39,7 @@ namespace util { constexpr T rotatel [[gnu::pure]] (const T value, std::size_t magnitude) { - return (value << magnitude) | (value >> sizeof (value) * 8 - magnitude); + return (value << magnitude) | (value >> (sizeof (value) * 8 - magnitude)); } @@ -47,7 +47,7 @@ namespace util { constexpr T rotater [[gnu::pure]] (const T value, std::size_t magnitude) { - return (value >> magnitude) | (value << sizeof (value) * 8 - magnitude); + return (value >> magnitude) | (value << (sizeof (value) * 8 - magnitude)); } diff --git a/fixed.cpp b/fixed.cpp index cb63172a..cf0b77b6 100644 --- a/fixed.cpp +++ b/fixed.cpp @@ -145,7 +145,7 @@ template \ fixed \ fixed::operator OP (integer_type val) const \ { \ - return fixed::from_native (m_value OP val << E); \ + return fixed::from_native (m_value OP (native_type{val} << E)); \ } SIMPLE_INTEGER_LIT(+) diff --git a/fixed.hpp b/fixed.hpp index e2958cbf..2afb73b6 100644 --- a/fixed.hpp +++ b/fixed.hpp @@ -24,7 +24,15 @@ #include namespace util { - template + template < + // whether the type is signed or unsigned. supply an appropriately + // signed type here; it won't be used for anything else. + typename T, + // how many bits total are used for the integral component + unsigned I, + // how many bits are used for the fractional component + unsigned E + > class [[gnu::packed]] fixed { public: static_assert (I > 0); diff --git a/json2/personality/jsonish.cpp b/json2/personality/jsonish.cpp index 87fd7db9..45b8b973 100644 --- a/json2/personality/jsonish.cpp +++ b/json2/personality/jsonish.cpp @@ -76,9 +76,9 @@ jsonish::parse_number (const std::function &cb, ++cursor; auto digit_start = cursor; - while (cursor != last && ('0' <= *cursor && *cursor <= '9' || - 'a' <= *cursor && *cursor <= 'f' || - 'A' <= *cursor && *cursor <= 'F')) + while (cursor != last && ((('0' <= *cursor) && (*cursor <= '9')) || + (('a' <= *cursor) && (*cursor <= 'f')) || + (('A' <= *cursor) && (*cursor <= 'F')))) ++cursor; if (digit_start == cursor) throw parse_error {cursor}; diff --git a/maths.hpp b/maths.hpp index f9dd41f8..269bee1d 100644 --- a/maths.hpp +++ b/maths.hpp @@ -425,7 +425,7 @@ namespace util { bool samesign (T a, T b) { - return a < 0 && b < 0 || a > 0 && b > 0; + return (a >= 0 && b >= 0) || (a <= 0 && b <= 0); }