summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-13 23:52:13 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-15 17:26:26 +0200
commit1ef305de158498ba58063b19a02e40c9f6348857 (patch)
treed23dee327d950eb5bda9b6e908c50fb64dae4fff /tests/auto/corelib/global
parent149b5425d8a4fe809fcabddda09859116e29c2ff (diff)
Improve error reporting when requesting unsupported native interface
By switching out the static_assert for an enable_if we end up producing a clearer error, at the call site: /qt/qtbase/examples/gui/rasterwindow/main.cpp:69:9: error: no matching member function for call to 'nativeInterface' app.nativeInterface<QNativeInterface::QCocoaGLContext>(); ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /qt/qtbase/src/gui/kernel/qguiapplication.h:176:5: note: candidate template ignored: requirement 'NativeInterface<QNativeInterface::QCocoaGLContext>::isCompatibleWith<QGuiApplication>' was not satisfied [with NativeInterface = QNativeInterface::QCocoaGLContext, TypeInfo = QNativeInterface::Private::NativeInterface<QNativeInterface::QCocoaGLContext>, BaseType = QGuiApplication] QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QGuiApplication) ^ By using SFINAE for the TypeInfo we can also ensure that it works for types that are not native interfaces, such as if the user tries to call nativeInterface<QString>(). Since we can no longer use decltype(*this) to resolve the base type we need to change QT_DECLARE_NATIVE_INTERFACE_ACCESSOR to take the type as an argument, as we do for other QT_DECLARE_FOO macros. Pick-to: 6.2 Change-Id: Ie3f7e01ab7c3eb3dcc2ef730834f268bb9e81e0c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r--tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp b/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp
index 0da3108817..dfd8d4fca1 100644
--- a/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp
+++ b/tests/auto/corelib/global/qnativeinterface/tst_qnativeinterface.cpp
@@ -44,7 +44,7 @@ struct InterfaceImplementation;
struct PublicClass
{
PublicClass();
- QT_DECLARE_NATIVE_INTERFACE_ACCESSOR
+ QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(PublicClass)
std::unique_ptr<InterfaceImplementation> m_implementation;
};
@@ -66,6 +66,15 @@ QT_DEFINE_NATIVE_INTERFACE(Interface);
QT_DEFINE_NATIVE_INTERFACE(OtherInterface);
QT_END_NAMESPACE
+struct NotInterface {};
+
+struct AlmostInterface
+{
+ struct TypeInfo {
+ // Missing required members
+ };
+};
+
using namespace QNativeInterface;
struct InterfaceImplementation : public Interface
@@ -89,6 +98,10 @@ void tst_QNativeInterface::typeInfo() const
{
using namespace QNativeInterface::Private;
+ QCOMPARE(TypeInfo<Interface>::haveTypeInfo, true);
+ QCOMPARE(TypeInfo<NotInterface>::haveTypeInfo, false);
+ QCOMPARE(TypeInfo<AlmostInterface>::haveTypeInfo, false);
+
QCOMPARE(TypeInfo<Interface>::isCompatibleWith<PublicClass>, true);
QCOMPARE(TypeInfo<Interface>::isCompatibleWith<QObject>, false);
QCOMPARE(TypeInfo<Interface>::isCompatibleWith<int>, false);