Attempt to work with Visual Studio in -Za (strict ANSI) mode
Visual Studio always treats enum values as signed int, even when the value doesn't fit in a signed int (like 0x80000000 or larger than 32- the tags themselves are still signed. That causes ambiguity in creating a QFlag from an enum value. Visual C++ defines __STDC__ in C mode, but we have no macro in C++ mode. Also note that the Windows SDK headers don't compile in -Za mode. Task-number: QTBUG-39700 Change-Id: Ia943cef37ac1f539bd461c3c18200b0c365c72b3 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
76371c4d56
commit
16dccb24e4
@ -53,16 +53,22 @@ class QFlag
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
public:
|
public:
|
||||||
#if !defined(__LP64__) && !defined(Q_QDOC)
|
Q_DECL_CONSTEXPR inline QFlag(int ai) : i(ai) {}
|
||||||
|
Q_DECL_CONSTEXPR inline operator int() const { return i; }
|
||||||
|
|
||||||
|
#if !defined(Q_CC_MSVC)
|
||||||
|
// Microsoft Visual Studio has buggy behavior when it comes to
|
||||||
|
// unsigned enums: even if the enum is unsigned, the enum tags are
|
||||||
|
// always signed
|
||||||
|
# if !defined(__LP64__) && !defined(Q_QDOC)
|
||||||
Q_DECL_CONSTEXPR inline QFlag(long ai) : i(int(ai)) {}
|
Q_DECL_CONSTEXPR inline QFlag(long ai) : i(int(ai)) {}
|
||||||
Q_DECL_CONSTEXPR inline QFlag(ulong ai) : i(int(long(ai))) {}
|
Q_DECL_CONSTEXPR inline QFlag(ulong ai) : i(int(long(ai))) {}
|
||||||
#endif
|
# 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(uint ai) : i(int(ai)) {}
|
||||||
Q_DECL_CONSTEXPR inline QFlag(short 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 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_DECL_CONSTEXPR inline operator uint() const { return uint(i); }
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE);
|
Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE);
|
||||||
|
|
||||||
@ -89,7 +95,11 @@ class QFlags
|
|||||||
struct Private;
|
struct Private;
|
||||||
typedef int (Private::*Zero);
|
typedef int (Private::*Zero);
|
||||||
public:
|
public:
|
||||||
#ifndef Q_QDOC
|
#if defined(Q_CC_MSVC) || defined(Q_QDOC)
|
||||||
|
// see above for MSVC
|
||||||
|
// the definition below is too complex for qdoc
|
||||||
|
typedef int Int;
|
||||||
|
#else
|
||||||
typedef typename QtPrivate::if_<
|
typedef typename QtPrivate::if_<
|
||||||
QtPrivate::is_unsigned<Enum>::value,
|
QtPrivate::is_unsigned<Enum>::value,
|
||||||
unsigned int,
|
unsigned int,
|
||||||
@ -99,7 +109,6 @@ public:
|
|||||||
typedef Enum enum_type;
|
typedef Enum enum_type;
|
||||||
// compiler-generated copy/move ctor/assignment operators are fine!
|
// compiler-generated copy/move ctor/assignment operators are fine!
|
||||||
#ifdef Q_QDOC
|
#ifdef Q_QDOC
|
||||||
typedef int Int; // the real typedef above is too complex for qdoc
|
|
||||||
inline QFlags(const QFlags &other);
|
inline QFlags(const QFlags &other);
|
||||||
inline QFlags &operator=(const QFlags &other);
|
inline QFlags &operator=(const QFlags &other);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user