diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-09-20 15:06:11 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-28 23:50:10 +0200 |
commit | ac9be327f8dc788a964b77c6bcdf0391c85c9cbd (patch) | |
tree | e7f66c52a02cf1a8c260c47d1bba0d400acad82a /src | |
parent | 26f238a80d38d6e1da0a6d485dd0b185b73c46ef (diff) |
QFlags: use unsigned int when the enum's underlying is unsigned
Replace storage and operator int() return types with unsigned int
if the enum is unsigned.
This fixes a number of exisiting warnings, in particular with
Qt::MouseButton under GCC.
Change-Id: Ia12d36212329aec3e9d62a5fbd38809a6c2b36d0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qflags.h | 16 | ||||
-rw-r--r-- | src/corelib/global/qglobal.cpp | 13 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index faacf7321c..3edbef3bd6 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -44,6 +44,7 @@ #include <QtCore/qglobal.h> #include <QtCore/qtypeinfo.h> +#include <QtCore/qtypetraits.h> QT_BEGIN_HEADER @@ -82,11 +83,18 @@ class QFlags "long long would overflow. Qt 5.1 will have support for 64bit enums."); struct Private; typedef int (Private::*Zero); - int i; public: +#ifndef qdoc + typedef typename QtPrivate::if_< + QtPrivate::is_unsigned<Enum>::value, + unsigned int, + signed int + >::type Int; +#endif typedef Enum enum_type; // compiler-generated copy/move ctor/assignment operators are fine! #ifdef qdoc + typedef int Int; // the real typedef above is too complex for qdoc inline QFlags(const QFlags &other); inline QFlags &operator=(const QFlags &other); #endif @@ -101,7 +109,7 @@ public: inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; } inline QFlags &operator^=(Enum f) { i ^= f; return *this; } - Q_DECL_CONSTEXPR inline operator int() const { return i; } + Q_DECL_CONSTEXPR inline operator Int() const { return i; } Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const { return QFlags(Enum(i | f.i)); } Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(Enum(i | f)); } @@ -114,7 +122,9 @@ public: Q_DECL_CONSTEXPR inline bool operator!() const { return !i; } - Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); } + Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == Int(f) ); } +private: + Int i; }; #define Q_DECLARE_FLAGS(Flags, Enum)\ diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index ef211cfce2..805868f4c6 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -172,6 +172,15 @@ Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n); */ /*! + \typedef QFlags::Int + \since 5.0 + + Typedef for the integer type used for storage as well as for + implicit conversion. Either \c int or \c{unsigned int}, depending + on whether the enum's underlying type is signed or unsigned. +*/ + +/*! \typedef QFlags::enum_type Typedef for the Enum template type. @@ -261,9 +270,11 @@ Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n); */ /*! - \fn QFlags::operator int() const + \fn QFlags::operator Int() const Returns the value stored in the QFlags object as an integer. + + \sa Int */ /*! |