From 16dccb24e4e7fb6332f672e1572e7ca359f794c5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 20 Jun 2014 15:57:16 -0700 Subject: 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 --- src/corelib/global/qflags.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/corelib') 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::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 -- cgit v1.2.3 From f17494e9b829f079bf632eed7757c1a30f360b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Thu, 12 Jun 2014 14:49:37 +0200 Subject: Android: Refactor exception checking in qjni. In places where we call java/jni functions that can throw exceptions, we check and clear the exception, if necessary. This change moves the "checking" code into a single (private) function. Change-Id: Ic3de2be51305972b096e1ed0a477e341eb5d9404 Reviewed-by: Yoann Lopes --- src/corelib/kernel/qjni.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qjni.cpp b/src/corelib/kernel/qjni.cpp index 437205bf92..aa9b196e62 100644 --- a/src/corelib/kernel/qjni.cpp +++ b/src/corelib/kernel/qjni.cpp @@ -67,6 +67,19 @@ static QString qt_convertJString(jstring string) return res; } +static inline bool exceptionCheckAndClear(JNIEnv *env) +{ + if (Q_UNLIKELY(env->ExceptionCheck())) { +#ifdef QT_DEBUG + env->ExceptionDescribe(); +#endif // QT_DEBUG + env->ExceptionClear(); + return true; + } + + return false; +} + typedef QHash JClassHash; Q_GLOBAL_STATIC(JClassHash, cachedClasses) @@ -85,14 +98,8 @@ static jclass getCachedClass(JNIEnv *env, const char *className) QJNIObjectPrivate classObject = classLoader.callObjectMethod("loadClass", "(Ljava/lang/String;)Ljava/lang/Class;", stringName.object()); - if (env->ExceptionCheck()) { -#ifdef QT_DEBUG - env->ExceptionDescribe(); -#endif // QT_DEBUG - env->ExceptionClear(); - } - if (classObject.isValid()) + if (!exceptionCheckAndClear(env) && classObject.isValid()) clazz = static_cast(env->NewGlobalRef(classObject.object())); cachedClasses->insert(key, clazz); @@ -121,13 +128,8 @@ static jmethodID getCachedMethodID(JNIEnv *env, else id = env->GetMethodID(clazz, name, sig); - if (env->ExceptionCheck()) { + if (exceptionCheckAndClear(env)) id = 0; -#ifdef QT_DEBUG - env->ExceptionDescribe(); -#endif // QT_DEBUG - env->ExceptionClear(); - } cachedMethodID->insert(key, id); } else { @@ -154,13 +156,8 @@ static jfieldID getCachedFieldID(JNIEnv *env, else id = env->GetFieldID(clazz, name, sig); - if (env->ExceptionCheck()) { + if (exceptionCheckAndClear(env)) id = 0; -#ifdef QT_DEBUG - env->ExceptionDescribe(); -#endif // QT_DEBUG - env->ExceptionClear(); - } cachedFieldID->insert(key, id); } else { -- cgit v1.2.3 From 81bd9633cc73eb710f144aabfa6d7f32a1d69660 Mon Sep 17 00:00:00 2001 From: Niels Weber Date: Mon, 7 Jul 2014 13:23:02 +0200 Subject: Fix for code snippet in commandlineparser documentation One line in the code snippet wasn't translated whlie the others were. Change-Id: Ie77a317833f800087b485609cd001dd26060a40f Reviewed-by: Leena Miettinen --- .../doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp index 46b4274301..257a138d0d 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser_main.cpp @@ -59,7 +59,8 @@ int main(int argc, char *argv[]) parser.addOption(showProgressOption); // A boolean option with multiple names (-f, --force) - QCommandLineOption forceOption(QStringList() << "f" << "force", "Overwrite existing files."); + QCommandLineOption forceOption(QStringList() << "f" << "force", + QCoreApplication::translate("main", "Overwrite existing files.")); parser.addOption(forceOption); // An option with a value -- cgit v1.2.3