From a9a26d7fc321ec327eb786b7cc60aa8a9afa27a0 Mon Sep 17 00:00:00 2001
From: Brilliantov Kirill Vladimirovich <brilliantov@inbox.ru>
Date: Fri, 1 Feb 2019 11:12:40 +0300
Subject: [PATCH] src/corelib/: added workaround for test chrono

Qt use __has_include() for check chrono, it available from gcc5
https://www.gnu.org/software/gcc/gcc-5/changes.html
gcc-4.9.x should backport this feature
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63662

Signed-off-by: Brilliantov Kirill Vladimirovich <brilliantov@inbox.ru>
---
 src/corelib/configure.json          | 22 ++++++++++++++++++++++
 src/corelib/kernel/qdeadlinetimer.h |  4 ++--
 src/corelib/kernel/qobject.h        |  4 ++--
 src/corelib/kernel/qtimer.h         |  6 +++---
 src/corelib/thread/qmutex.h         |  8 ++++----
 5 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/corelib/configure.json b/src/corelib/configure.json
index 183eb3a13e..96fa31e47d 100644
--- a/src/corelib/configure.json
+++ b/src/corelib/configure.json
@@ -279,6 +279,18 @@
             "type": "compile",
             "test": "unix/cxx11_random"
         },
+        "cxx11_chrono": {
+            "label": "C++ <crono>",
+            "type": "compile",
+            "test": {
+                "include": "chrono",
+                "main": [
+                    "std::chrono::milliseconds val(100);",
+                    "int v = static_cast<int>(val.count());"
+                ],
+                "qmake": "CONFIG += c++11"
+            }
+        },
         "eventfd": {
             "label": "eventfd",
             "type": "compile",
@@ -479,6 +491,11 @@
             "condition": "tests.cxx11_future",
             "output": [ "publicFeature" ]
         },
+        "cxx11_chrono": {
+            "label": "C++11 <chrono>",
+            "condition": "tests.cxx11_chrono",
+            "output": [ { "type": "define", "name": "QT_CXX11_CHRONO" } ]
+        },
         "eventfd": {
             "label": "eventfd",
             "condition": "!config.wasm && tests.eventfd",
@@ -906,6 +923,11 @@ If your users intend to develop applications against this build,
 ensure that the IDEs they use either set QT_FORCE_STDERR_LOGGING to 1
 or are able to read the logged output from journald, syslog or slog2."
         },
+        {
+            "type": "note",
+            "condition": "!tests.cxx11_chrono",
+            "message": "C++11 <chrono> will be unavailable."
+        },
         {
             "type": "error",
             "condition": "!tests.cxx11_random",
diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h
index 1a4ee04a96..253e69e10b 100644
--- a/src/corelib/kernel/qdeadlinetimer.h
+++ b/src/corelib/kernel/qdeadlinetimer.h
@@ -52,7 +52,7 @@
 
 #include <limits>
 
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
 #  include <chrono>
 #endif
 
@@ -121,7 +121,7 @@ public:
     QDeadlineTimer &operator-=(qint64 msecs)
     { *this = *this + (-msecs); return *this; }
 
-#if QT_HAS_INCLUDE(<chrono>) || defined(Q_CLANG_QDOC)
+#if QT_HAS_INCLUDE(<chrono>) || defined(Q_CLANG_QDOC) || defined(QT_CXX11_CHRONO)
     template <class Clock, class Duration>
     QDeadlineTimer(std::chrono::time_point<Clock, Duration> deadline_,
                    Qt::TimerType type_ = Qt::CoarseTimer) : t2(0)
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index aac9bcdee9..0d5f4ab711 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -55,7 +55,7 @@
 
 #include <QtCore/qobject_impl.h>
 
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
 #  include <chrono>
 #endif
 
@@ -149,7 +149,7 @@ public:
     void moveToThread(QThread *thread);
 
     int startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer);
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
     Q_ALWAYS_INLINE
     int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer)
     {
diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h
index 66f317c567..0c4e6332f2 100644
--- a/src/corelib/kernel/qtimer.h
+++ b/src/corelib/kernel/qtimer.h
@@ -47,7 +47,7 @@
 #include <QtCore/qbasictimer.h> // conceptual inheritance
 #include <QtCore/qobject.h>
 
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
 #  include <chrono>
 #endif
 
@@ -177,7 +177,7 @@ Q_SIGNALS:
     void timeout(QPrivateSignal);
 
 public:
-#if QT_HAS_INCLUDE(<chrono>) || defined(Q_QDOC)
+#if QT_HAS_INCLUDE(<chrono>) || defined(Q_QDOC) || defined(QT_CXX11_CHRONO)
     void setInterval(std::chrono::milliseconds value)
     {
         setInterval(int(value.count()));
@@ -223,7 +223,7 @@ private:
     static void singleShotImpl(int msec, Qt::TimerType timerType,
                                const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj);
 
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
     static Qt::TimerType defaultTypeFor(std::chrono::milliseconds interval)
     { return defaultTypeFor(int(interval.count())); }
 
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index 837355a602..5d3ac605b2 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -44,7 +44,7 @@
 #include <QtCore/qatomic.h>
 #include <new>
 
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
 #  include <chrono>
 #  include <limits>
 #endif
@@ -139,7 +139,7 @@ public:
     // Lockable concept
     bool try_lock() QT_MUTEX_LOCK_NOEXCEPT { return tryLock(); }
 
-#if QT_HAS_INCLUDE(<chrono>) || defined(Q_CLANG_QDOC)
+#if QT_HAS_INCLUDE(<chrono>) || defined(Q_CLANG_QDOC) || defined(QT_CXX11_CHRONO)
     // TimedLockable concept
     template <class Rep, class Period>
     bool try_lock_for(std::chrono::duration<Rep, Period> duration)
@@ -166,7 +166,7 @@ private:
     friend class QMutexLocker;
     friend class ::tst_QMutex;
 
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
     template<class Rep, class Period>
     static int convertToMilliseconds(std::chrono::duration<Rep, Period> duration)
     {
@@ -265,7 +265,7 @@ public:
     inline void unlock() Q_DECL_NOTHROW {}
     inline bool isRecursive() const Q_DECL_NOTHROW { return true; }
 
-#if QT_HAS_INCLUDE(<chrono>)
+#if QT_HAS_INCLUDE(<chrono>) || defined(QT_CXX11_CHRONO)
     template <class Rep, class Period>
     inline bool try_lock_for(std::chrono::duration<Rep, Period> duration) Q_DECL_NOTHROW
     {
-- 
2.20.1

