Add other integer overloads to QFlag's constructor

This avoids "change of sign" warnings as found by ICC when the high
bit is set. This often happens when you do
    X & ~Y

as ~Y probably has bit 31 on. If the enum is unsigned, then there's a sign conversion.

Change-Id: Ia5f221d928ac0155f4504a70c4046e60c25fbf3b
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2013-06-28 14:43:27 -07:00 committed by The Qt Project
parent 9c9f609313
commit dd987a9ef0
2 changed files with 37 additions and 3 deletions

View File

@ -53,13 +53,19 @@ class QFlag
{
int i;
public:
Q_DECL_CONSTEXPR inline QFlag(int i);
#if !defined(__LP64__) && !defined(Q_QDOC)
Q_DECL_CONSTEXPR inline QFlag(long ai) : i(int(ai)) {}
Q_DECL_CONSTEXPR inline QFlag(ulong ai) : i(int(long(ai))) {}
#endif
Q_DECL_CONSTEXPR inline QFlag(int ai) : i(ai) {}
Q_DECL_CONSTEXPR inline QFlag(uint ai) : i(int(ai)) {}
Q_DECL_CONSTEXPR inline QFlag(short ai) : i(int(ai)) {}
Q_DECL_CONSTEXPR inline QFlag(ushort ai) : i(int(uint(ai))) {}
Q_DECL_CONSTEXPR inline operator int() const { return i; }
Q_DECL_CONSTEXPR inline operator uint() const { return uint(i); }
};
Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE);
Q_DECL_CONSTEXPR inline QFlag::QFlag(int ai) : i(ai) {}
class QIncompatibleFlag
{
int i;

View File

@ -114,12 +114,40 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
Constructs a QFlag object that stores the given \a value.
*/
/*!
\fn QFlag::QFlag(uint value)
\since Qt 5.3
Constructs a QFlag object that stores the given \a value.
*/
/*!
\fn QFlag::QFlag(short value)
\since 5.3
Constructs a QFlag object that stores the given \a value.
*/
/*!
\fn QFlag::QFlag(ushort value)
\since Qt 5.3
Constructs a QFlag object that stores the given \a value.
*/
/*!
\fn QFlag::operator int() const
Returns the value stored by the QFlag object.
*/
/*!
\fn QFlag::operator uint() const
\since Qt 5.3
Returns the value stored by the QFlag object.
*/
/*!
\class QFlags
\inmodule QtCore