From 6bee77922c2571a7b55f099531f024def3e1036b Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 9 Apr 2015 17:31:19 +0200 Subject: [PATCH] Get rid of false GCC 4.7 -Werror=type-limits in template code Change-Id: I4b13d3b7d74690401234dfa30c8c1b6647820b6a Reviewed-on: https://gerrit.libreoffice.org/15216 Tested-by: Jenkins Reviewed-by: Tor Lillqvist Tested-by: Tor Lillqvist --- include/o3tl/typed_flags_set.hxx | 108 ++++++++++++++++++++++++------- include/o3tl/underlying_type.hxx | 2 +- 2 files changed, 86 insertions(+), 24 deletions(-) diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx index 3e960035b61e..6151babb0cf5 100644 --- a/include/o3tl/typed_flags_set.hxx +++ b/include/o3tl/typed_flags_set.hxx @@ -23,11 +23,29 @@ #include #include +#include #include namespace o3tl { +namespace detail { + +template inline +typename std::enable_if::value, bool>::type isNonNegative( + T value) +{ + return value >= 0; +} + +template inline +typename std::enable_if::value, bool>::type isNonNegative(T) +{ + return true; +} + +} + template struct typed_flags {}; /// Mark a (scoped) enumeration as a set of bit flags, with accompanying @@ -54,7 +72,7 @@ struct is_typed_flags { public: explicit Wrap(typename underlying_type::type value): value_(value) - { assert(value >= 0); } + { assert(detail::isNonNegative(value)); } operator E() { return static_cast(value_); } @@ -73,7 +91,9 @@ struct is_typed_flags { template inline typename o3tl::typed_flags::Wrap operator ~(E rhs) { - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); return static_cast::Wrap>( o3tl::typed_flags::mask & ~static_cast::type>(rhs)); @@ -90,8 +110,12 @@ inline typename o3tl::typed_flags::Wrap operator ~( template inline typename o3tl::typed_flags::Wrap operator ^(E lhs, E rhs) { - assert(static_cast::type>(lhs) >= 0); - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); return static_cast::Wrap>( static_cast::type>(lhs) ^ static_cast::type>(rhs)); @@ -101,7 +125,9 @@ template inline typename o3tl::typed_flags::Wrap operator ^( E lhs, typename o3tl::typed_flags::Wrap rhs) { - assert(static_cast::type>(lhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); return static_cast::Wrap>( static_cast::type>(lhs) ^ static_cast::type>(rhs)); @@ -111,7 +137,9 @@ template inline typename o3tl::typed_flags::Wrap operator ^( typename o3tl::typed_flags::Wrap lhs, E rhs) { - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); return static_cast::Wrap>( static_cast::type>(lhs) ^ static_cast::type>(rhs)); @@ -129,8 +157,12 @@ inline typename o3tl::typed_flags::Wrap operator ^( template inline typename o3tl::typed_flags::Wrap operator &(E lhs, E rhs) { - assert(static_cast::type>(lhs) >= 0); - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); return static_cast::Wrap>( static_cast::type>(lhs) & static_cast::type>(rhs)); @@ -140,7 +172,9 @@ template inline typename o3tl::typed_flags::Wrap operator &( E lhs, typename o3tl::typed_flags::Wrap rhs) { - assert(static_cast::type>(lhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); return static_cast::Wrap>( static_cast::type>(lhs) & static_cast::type>(rhs)); @@ -150,7 +184,9 @@ template inline typename o3tl::typed_flags::Wrap operator &( typename o3tl::typed_flags::Wrap lhs, E rhs) { - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); return static_cast::Wrap>( static_cast::type>(lhs) & static_cast::type>(rhs)); @@ -168,8 +204,12 @@ inline typename o3tl::typed_flags::Wrap operator &( template inline typename o3tl::typed_flags::Wrap operator |(E lhs, E rhs) { - assert(static_cast::type>(lhs) >= 0); - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); return static_cast::Wrap>( static_cast::type>(lhs) | static_cast::type>(rhs)); @@ -179,7 +219,9 @@ template inline typename o3tl::typed_flags::Wrap operator |( E lhs, typename o3tl::typed_flags::Wrap rhs) { - assert(static_cast::type>(lhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); return static_cast::Wrap>( static_cast::type>(lhs) | static_cast::type>(rhs)); @@ -189,7 +231,9 @@ template inline typename o3tl::typed_flags::Wrap operator |( typename o3tl::typed_flags::Wrap lhs, E rhs) { - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); return static_cast::Wrap>( static_cast::type>(lhs) | static_cast::type>(rhs)); @@ -207,8 +251,12 @@ inline typename o3tl::typed_flags::Wrap operator |( template inline typename o3tl::typed_flags::Self operator &=(E & lhs, E rhs) { - assert(static_cast::type>(lhs) >= 0); - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); lhs = lhs & rhs; return lhs; } @@ -217,15 +265,21 @@ template inline typename o3tl::typed_flags::Self operator &=( E & lhs, typename o3tl::typed_flags::Wrap rhs) { - assert(static_cast::type>(lhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); lhs = lhs & rhs; return lhs; } template inline typename o3tl::typed_flags::Self operator |=(E & lhs, E rhs) { - assert(static_cast::type>(lhs) >= 0); - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); lhs = lhs | rhs; return lhs; } @@ -234,15 +288,21 @@ template inline typename o3tl::typed_flags::Self operator |=( E & lhs, typename o3tl::typed_flags::Wrap rhs) { - assert(static_cast::type>(lhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); lhs = lhs | rhs; return lhs; } template inline typename o3tl::typed_flags::Self operator ^=(E & lhs, E rhs) { - assert(static_cast::type>(lhs) >= 0); - assert(static_cast::type>(rhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(rhs))); lhs = lhs ^ rhs; return lhs; } @@ -251,7 +311,9 @@ template inline typename o3tl::typed_flags::Self operator ^=( E & lhs, typename o3tl::typed_flags::Wrap rhs) { - assert(static_cast::type>(lhs) >= 0); + assert( + o3tl::detail::isNonNegative( + static_cast::type>(lhs))); lhs = lhs ^ rhs; return lhs; } diff --git a/include/o3tl/underlying_type.hxx b/include/o3tl/underlying_type.hxx index 3d8b6250c734..4b2e0778ee60 100644 --- a/include/o3tl/underlying_type.hxx +++ b/include/o3tl/underlying_type.hxx @@ -17,7 +17,7 @@ namespace o3tl { template struct underlying_type { -#if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ <= 7 && \ +#if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ <= 6 && \ !defined __clang__ typedef int type; #else