summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-06-20 15:57:16 -0700
committerThiago Macieira <thiago.macieira@intel.com>2014-07-05 23:03:59 +0200
commit16dccb24e4e7fb6332f672e1572e7ca359f794c5 (patch)
tree5295a15ab4b540bcacee24b28eef880e591d800d /src
parent76371c4d560c5a13f54f1ed9078fb68a393aa1bd (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qflags.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h
index 9e97724fec..bdfc453e08 100644
--- a/src/corelib/global/qflags.h
+++ b/src/corelib/global/qflags.h
@@ -53,16 +53,22 @@ class QFlag
{
int i;
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(ulong ai) : i(int(long(ai))) {}
-#endif
- Q_DECL_CONSTEXPR inline QFlag(int ai) : i(ai) {}
+# endif
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); }
+#endif
};
Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE);
@@ -89,7 +95,11 @@ class QFlags
struct Private;
typedef int (Private::*Zero);
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_<
QtPrivate::is_unsigned<Enum>::value,
unsigned int,
@@ -99,7 +109,6 @@ public:
typedef Enum enum_type;
// compiler-generated copy/move ctor/assignment operators are fine!
#ifdef Q_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