summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qdebug.h14
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp9
2 files changed, 20 insertions, 3 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 59bd32e9a4..3c3ceba249 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -278,7 +278,7 @@ template <class T>
inline typename QtPrivate::QEnableIf<
QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<QFlags<T> >::Value,
QDebug>::Type
-operator<<(QDebug debug, const QFlags<T> &flags)
+qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
{
const QMetaObject *obj = qt_getEnumMetaObject(T());
const char *name = qt_getEnumName(T());
@@ -289,10 +289,10 @@ template <class T>
inline typename QtPrivate::QEnableIf<
!QtPrivate::IsQEnumHelper<T>::Value && !QtPrivate::IsQEnumHelper<QFlags<T> >::Value,
QDebug>::Type
-operator<<(QDebug debug, const QFlags<T> &flags)
+qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
#else // !QT_NO_QOBJECT
template <class T>
-inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
+inline QDebug qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
#endif
{
QDebugStateSaver saver(debug);
@@ -312,6 +312,14 @@ inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
return debug;
}
+template<typename T>
+inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
+{
+ // We have to use an indirection otherwise specialisation of some other overload of the
+ // operator<< the compiler would try to instantiate QFlags<T> for the QEnableIf
+ return qt_QMetaEnum_flagDebugOperator_helper(debug, flags);
+}
+
#ifdef Q_OS_MAC
// We provide QDebug stream operators for commonly used Core Foundation
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 32344f1e26..4e5cfed019 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -625,5 +625,14 @@ void tst_QDebug::threadSafety() const
}
}
+// Should compile: instentiation of unrelated operator<< should not cause cause compilation
+// error in QDebug operators (QTBUG-47375)
+class TestClassA {};
+class TestClassB {};
+
+template <typename T>
+TestClassA& operator<< (TestClassA& s, T&) { return s; };
+template<> TestClassA& operator<< <TestClassB>(TestClassA& s, TestClassB& l);
+
QTEST_MAIN(tst_QDebug);
#include "tst_qdebug.moc"