summaryrefslogtreecommitdiffstats
path: root/include/o3tl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-04-09 17:31:19 +0200
committerStephan Bergmann <sbergman@redhat.com>2015-04-10 07:53:41 +0000
commit6bee77922c2571a7b55f099531f024def3e1036b (patch)
tree93bc4757b15fc93ad5145bb585211010ee6cdfa6 /include/o3tl
parentconvert SFXOBJECTSHELL_ constants to scoped enum (diff)
downloadcore-6bee77922c2571a7b55f099531f024def3e1036b.tar.gz
core-6bee77922c2571a7b55f099531f024def3e1036b.zip
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 <ci@libreoffice.org> Reviewed-by: Tor Lillqvist <tml@collabora.com> Tested-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/typed_flags_set.hxx108
-rw-r--r--include/o3tl/underlying_type.hxx2
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 <sal/config.h>
#include <cassert>
+#include <type_traits>
#include <o3tl/underlying_type.hxx>
namespace o3tl {
+namespace detail {
+
+template<typename T> inline
+typename std::enable_if<std::is_signed<T>::value, bool>::type isNonNegative(
+ T value)
+{
+ return value >= 0;
+}
+
+template<typename T> inline
+typename std::enable_if<std::is_unsigned<T>::value, bool>::type isNonNegative(T)
+{
+ return true;
+}
+
+}
+
template<typename T> 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<E>::type value):
value_(value)
- { assert(value >= 0); }
+ { assert(detail::isNonNegative(value)); }
operator E() { return static_cast<E>(value_); }
@@ -73,7 +91,9 @@ struct is_typed_flags {
template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator ~(E rhs) {
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
o3tl::typed_flags<E>::mask
& ~static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -90,8 +110,12 @@ inline typename o3tl::typed_flags<E>::Wrap operator ~(
template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator ^(E lhs, E rhs) {
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
^ static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -101,7 +125,9 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator ^(
E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
^ static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -111,7 +137,9 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator ^(
typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
^ static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -129,8 +157,12 @@ inline typename o3tl::typed_flags<E>::Wrap operator ^(
template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) {
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
& static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -140,7 +172,9 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator &(
E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
& static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -150,7 +184,9 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator &(
typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
& static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -168,8 +204,12 @@ inline typename o3tl::typed_flags<E>::Wrap operator &(
template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) {
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
| static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -179,7 +219,9 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator |(
E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
| static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -189,7 +231,9 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Wrap operator |(
typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename o3tl::underlying_type<E>::type>(lhs)
| static_cast<typename o3tl::underlying_type<E>::type>(rhs));
@@ -207,8 +251,12 @@ inline typename o3tl::typed_flags<E>::Wrap operator |(
template<typename E>
inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) {
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
lhs = lhs & rhs;
return lhs;
}
@@ -217,15 +265,21 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Self operator &=(
E & lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
lhs = lhs & rhs;
return lhs;
}
template<typename E>
inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) {
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
lhs = lhs | rhs;
return lhs;
}
@@ -234,15 +288,21 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Self operator |=(
E & lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
lhs = lhs | rhs;
return lhs;
}
template<typename E>
inline typename o3tl::typed_flags<E>::Self operator ^=(E & lhs, E rhs) {
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
- assert(static_cast<typename o3tl::underlying_type<E>::type>(rhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(lhs)));
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::type>(rhs)));
lhs = lhs ^ rhs;
return lhs;
}
@@ -251,7 +311,9 @@ template<typename E>
inline typename o3tl::typed_flags<E>::Self operator ^=(
E & lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
- assert(static_cast<typename o3tl::underlying_type<E>::type>(lhs) >= 0);
+ assert(
+ o3tl::detail::isNonNegative(
+ static_cast<typename o3tl::underlying_type<E>::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<typename T> 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