From 1eb7005850b9f54c30b34bd1268d2314767131fe Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Thu, 30 Oct 2014 22:44:13 -0700
Subject: [PATCH] Use the new warning enabling/disabling macros in qtbase
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Change-Id: I91ff06644e8047c2ca483f9768b46c1372eb6171
Reviewed-by: Martin Smith <martin.smith@digia.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
---
 bin/syncqt.pl                                 |  1 +
 doc/global/qt-cpp-defines.qdocconf            |  8 ++++++-
 src/corelib/global/qglobal.h                  | 24 +++++++++----------
 src/corelib/kernel/qfunctions_wince.h         |  2 +-
 src/corelib/thread/qatomic.h                  | 11 +++------
 src/corelib/tools/qstring.h                   | 11 +++------
 src/gui/image/qimage.h                        | 16 ++++---------
 src/gui/painting/qdrawhelper_sse2.cpp         |  4 +---
 src/gui/painting/qdrawhelper_sse_p.h          |  4 +---
 src/plugins/platforms/cocoa/qnsview.mm        |  6 ++---
 .../qatomicinteger/tst_qatomicinteger.cpp     | 10 +++-----
 .../corelib/tools/qstring/tst_qstring.cpp     | 10 +++-----
 12 files changed, 42 insertions(+), 65 deletions(-)

diff --git a/bin/syncqt.pl b/bin/syncqt.pl
index a394ffac0d1..3780c9f422a 100755
--- a/bin/syncqt.pl
+++ b/bin/syncqt.pl
@@ -230,6 +230,7 @@ sub classNames {
                 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
                 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE(_[A-Z]+)*[\r\n]*$/); #qt macro
                 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
+                $line .= ";" if($line =~ m/^QT_WARNING_(PUSH|POP|DISABLE_\w+\(.*\))[\r\n]*$/); # qt macros
                 $parsable .= " " . $line;
             }
         }
diff --git a/doc/global/qt-cpp-defines.qdocconf b/doc/global/qt-cpp-defines.qdocconf
index e806a004801..cf84a6ee6ee 100644
--- a/doc/global/qt-cpp-defines.qdocconf
+++ b/doc/global/qt-cpp-defines.qdocconf
@@ -116,6 +116,8 @@ Cpp.ignoretokens        += \
                           QT_END_NAMESPACE \
                           QT_FASTCALL \
                           QT_MUTEX_LOCK_NOEXCEPT \
+                          QT_WARNING_PUSH \
+                          QT_WARNING_POP \
                           QT_WIDGET_PLUGIN_EXPORT \
                           QWEBKIT_EXPORT
 
@@ -144,4 +146,8 @@ Cpp.ignoredirectives    += \
                           Q_PRIVATE_PROPERTY \
                           QT_FORWARD_DECLARE_CLASS \
                           Q_DECLARE_HANDLE \
-                          Q_REVISION
+                          Q_REVISION \
+                          QT_WARNING_DISABLE_CLANG \
+                          QT_WARNING_DISABLE_GCC \
+                          QT_WARNING_DISABLE_INTEL \
+                          QT_WARNING_DISABLE_MSVC
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 4e8721f7d75..19e368defc4 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -834,22 +834,22 @@ Q_CORE_EXPORT void qFreeAligned(void *ptr);
 #endif
 #if defined(QT_NO_WARNINGS)
 #  if defined(Q_CC_MSVC)
-#    pragma warning(disable: 4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */
-#    pragma warning(disable: 4244) /* conversion from 'type1' to 'type2', possible loss of data */
-#    pragma warning(disable: 4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
-#    pragma warning(disable: 4514) /* unreferenced inline function has been removed */
-#    pragma warning(disable: 4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
-#    pragma warning(disable: 4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
-#    pragma warning(disable: 4706) /* assignment within conditional expression */
+QT_WARNING_DISABLE_MSVC(4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */
+QT_WARNING_DISABLE_MSVC(4244) /* conversion from 'type1' to 'type2', possible loss of data */
+QT_WARNING_DISABLE_MSVC(4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
+QT_WARNING_DISABLE_MSVC(4514) /* unreferenced inline function has been removed */
+QT_WARNING_DISABLE_MSVC(4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
+QT_WARNING_DISABLE_MSVC(4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
+QT_WARNING_DISABLE_MSVC(4706) /* assignment within conditional expression */
 #    if _MSC_VER <= 1310 // MSVC 2003
-#      pragma warning(disable: 4786) /* 'identifier' : identifier was truncated to 'number' characters in the debug information */
+QT_WARNING_DISABLE_MSVC(4786) /* 'identifier' : identifier was truncated to 'number' characters in the debug information */
 #    endif
-#    pragma warning(disable: 4355) /* 'this' : used in base member initializer list */
+QT_WARNING_DISABLE_MSVC(4355) /* 'this' : used in base member initializer list */
 #    if _MSC_VER < 1800 // MSVC 2013
-#      pragma warning(disable: 4231) /* nonstandard extension used : 'identifier' before template explicit instantiation */
+QT_WARNING_DISABLE_MSVC(4231) /* nonstandard extension used : 'identifier' before template explicit instantiation */
 #    endif
-#    pragma warning(disable: 4710) /* function not inlined */
-#    pragma warning(disable: 4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */
+QT_WARNING_DISABLE_MSVC(4710) /* function not inlined */
+QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */
 #  elif defined(Q_CC_BOR)
 #    pragma option -w-inl
 #    pragma option -w-aus
diff --git a/src/corelib/kernel/qfunctions_wince.h b/src/corelib/kernel/qfunctions_wince.h
index cc5e0ca83fd..8cbde6c4654 100644
--- a/src/corelib/kernel/qfunctions_wince.h
+++ b/src/corelib/kernel/qfunctions_wince.h
@@ -208,7 +208,7 @@ int qt_wince_SetErrorMode(int);
 bool qt_wince__chmod(const char *file, int mode);
 bool qt_wince__wchmod(const wchar_t *file, int mode);
 
-#pragma warning(disable: 4273)
+QT_WARNING_DISABLE_MSVC(4273)
 HANDLE qt_wince_CreateFileA(LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
 
 // Printer ----------------------------------------------------------
diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h
index 7526cfe0e69..a665746db4a 100644
--- a/src/corelib/thread/qatomic.h
+++ b/src/corelib/thread/qatomic.h
@@ -40,11 +40,8 @@
 
 QT_BEGIN_NAMESPACE
 
-
-#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wextra"
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wextra")
 
 // High-level atomic integer operations
 template <typename T>
@@ -214,9 +211,7 @@ public:
 #endif
 };
 
-#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL)
-# pragma GCC diagnostic pop
-#endif
+QT_WARNING_POP
 
 #ifdef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
 #  undef QT_BASIC_ATOMIC_HAS_CONSTRUCTORS
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 718f10860ac..4d51521b120 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -924,11 +924,8 @@ inline QString QString::arg(const QString &a1, const QString &a2, const QString
 inline QString QString::section(QChar asep, int astart, int aend, SectionFlags aflags) const
 { return section(QString(asep), astart, aend, aflags); }
 
-#ifdef Q_CC_MSVC
-// "conditional expression is constant"
-#pragma warning(push)
-#pragma warning(disable : 4127)
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_MSVC(4127)   // "conditional expression is constant"
 
 inline int QString::toWCharArray(wchar_t *array) const
 {
@@ -939,9 +936,7 @@ inline int QString::toWCharArray(wchar_t *array) const
     return toUcs4_helper(d->data(), size(), reinterpret_cast<uint *>(array));
 }
 
-#ifdef Q_CC_MSVC
-#pragma warning(pop)
-#endif
+QT_WARNING_POP
 
 inline QString QString::fromWCharArray(const wchar_t *string, int size)
 {
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index 6a483f610f8..8984af12d1e 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -349,13 +349,9 @@ inline void QImage::setPixel(const QPoint &pt, uint index_or_rgb) { setPixel(pt.
 
 #if QT_DEPRECATED_SINCE(5, 0)
 
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#elif defined(Q_CC_MSVC)
-# pragma warning(push)
-# pragma warning(disable: 4996)
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
+QT_WARNING_DISABLE_MSVC(4996)
 
 inline QString QImage::text(const char* key, const char* lang) const
 {
@@ -427,11 +423,7 @@ inline void QImage::setText(const char* key, const char* lang, const QString &s)
     setText(k, s);
 }
 
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
-# pragma GCC diagnostic pop
-#elif defined(Q_CC_MSVC)
-# pragma warning(pop)
-#endif
+QT_WARNING_POP
 
 inline int QImage::numColors() const
 {
diff --git a/src/gui/painting/qdrawhelper_sse2.cpp b/src/gui/painting/qdrawhelper_sse2.cpp
index 77889b3c35e..95552afbee0 100644
--- a/src/gui/painting/qdrawhelper_sse2.cpp
+++ b/src/gui/painting/qdrawhelper_sse2.cpp
@@ -484,9 +484,7 @@ void qt_bitmapblit16_sse2(QRasterBuffer *rasterBuffer, int x, int y,
     const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16);
 
     const __m128i c128 = _mm_set1_epi16(c);
-#if defined(Q_CC_MSVC)
-#  pragma warning(disable: 4309) // truncation of constant value
-#endif
+QT_WARNING_DISABLE_MSVC(4309) // truncation of constant value
     const __m128i maskmask = _mm_set_epi16(0x0101, 0x0202, 0x0404, 0x0808,
                                            0x1010, 0x2020, 0x4040, 0x8080);
     const __m128i maskadd = _mm_set_epi16(0x7f7f, 0x7e7e, 0x7c7c, 0x7878,
diff --git a/src/gui/painting/qdrawhelper_sse_p.h b/src/gui/painting/qdrawhelper_sse_p.h
index a1f878b5c0e..de1a1d86be9 100644
--- a/src/gui/painting/qdrawhelper_sse_p.h
+++ b/src/gui/painting/qdrawhelper_sse_p.h
@@ -124,9 +124,7 @@ inline void qt_bitmapblit16_sse_template(QRasterBuffer *rasterBuffer,
     const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16);
 
     const __m64 c64 = _mm_set1_pi16(c);
-#ifdef Q_CC_MSVC
-#  pragma warning(disable: 4309) // truncation of constant value
-#endif
+QT_WARNING_DISABLE_MSVC(4309) // truncation of constant value
     const __m64 maskmask1 = _mm_set_pi16(0x1010, 0x2020, 0x4040, 0x8080);
     const __m64 maskadd1 = _mm_set_pi16(0x7070, 0x6060, 0x4040, 0x0000);
 
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 798e349538b..9dcad519a36 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -416,8 +416,8 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
                && [notificationName isEqualToString:_q_NSWindowDidChangeOcclusionStateNotification]) {
 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
 // ### HACK Remove the enum declaration, the warning disabling and the cast further down once 10.8 is unsupported
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wobjc-method-access"
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wobjc-method-access")
         enum { NSWindowOcclusionStateVisible = 1UL << 1 };
 #endif
         if ((NSUInteger)[self.window occlusionState] & NSWindowOcclusionStateVisible) {
@@ -432,7 +432,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
                 m_platformWindow->obscureWindow();
         }
 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
-#pragma clang diagnostic pop
+QT_WARNING_POP
 #endif
     } else if (notificationName == NSWindowDidChangeScreenNotification) {
         if (m_window) {
diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
index 425a07b3a7a..605a1525e30 100644
--- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
+++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
@@ -94,13 +94,9 @@
 #  define QATOMIC_TEST_NOT_SUPPORTED
 #endif
 
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL)
-#  pragma GCC diagnostic ignored "-Wtype-limits"
-#  pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
-#  pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
-#endif
+QT_WARNING_DISABLE_GCC("-Wtype-limits")
+QT_WARNING_DISABLE_GCC("-Wsign-compare")
+QT_WARNING_DISABLE_CLANG("-Wtautological-constant-out-of-range-compare")
 
 typedef signed char schar;
 
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index e001440045d..ed72b58d6e4 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -813,10 +813,8 @@ void tst_QString::acc_01()
     }
 }
 
-#ifdef Q_CC_GNU
-#    pragma GCC diagnostic push
-#    pragma GCC diagnostic ignored "-Wformat-security"
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wformat-security")
 
 void tst_QString::isNull()
 {
@@ -828,9 +826,7 @@ void tst_QString::isNull()
     QVERIFY(!a.isNull());
 }
 
-#ifdef Q_CC_GNU
-#    pragma GCC diagnostic pop
-#endif
+QT_WARNING_POP
 
 void tst_QString::isEmpty()
 {
-- 
GitLab