diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-02-16 15:16:08 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-02-18 13:44:41 +0100 |
commit | 8079361852417f57b5db8e47994870c4c8d63e3f (patch) | |
tree | 4c729059c2acea78fd41a5e184e36e711c1d57bd /tests/auto/tools | |
parent | 9078b41dde7eddd449d77399dbd0102f656cafab (diff) | |
download | qtbase-8079361852417f57b5db8e47994870c4c8d63e3f.tar.gz |
typeNameForCast: use add_pointer instead of string manipulation
Relying on string manipulation leads to -Wredundant-parens warnings in
the best case, and to non-compiling code (when using typedefs) in the
worst case.
We can avoid both issues by simply generating code that uses
add_pointer, which takes care of reference types (even typedef'd ones),
and creates no warnings about parens (as we don't write any anymore).
Fixes: QTBUG-100915
Pick-to: 6.3 6.2
Change-Id: Ic5b1cbfda20d920d11f51beeb62e9479261d5f00
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/tools')
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 1fb153ac09..7f4b431c81 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -362,6 +362,8 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wignored-qualifiers") QT_WARNING_DISABLE_GCC("-Wignored-qualifiers") +using ObjectCRef = const QObject &; + class TestClass : public MyNamespace::TestSuperClass, public DONT_CONFUSE_MOC(MyStruct), public DONT_CONFUSE_MOC_EVEN_MORE(MyStruct2, dummy, ignored) { @@ -557,6 +559,7 @@ signals: // public slots: void const slotWithSillyConst() {} + void slotTakingCRefViaTypedef(ObjectCRef o) { this->setObjectName(o.objectName()); } public: Q_INVOKABLE void const slotWithSillyConst2() {} @@ -686,6 +689,7 @@ private slots: void preprocessorConditionals(); void blackslashNewlines(); void slotWithSillyConst(); + void slotTakingCRefViaTypedef(); void testExtraData(); void testExtraDataForEnum(); void namespaceTypeProperty(); @@ -1074,6 +1078,15 @@ void tst_Moc::slotWithSillyConst() QVERIFY(mobj->indexOfSlot("slotWithVoidStar(void*)") != -1); } +void tst_Moc::slotTakingCRefViaTypedef() +{ + TestClass tst; + QObject obj; + obj.setObjectName("works"); + QMetaObject::invokeMethod(&tst, "slotTakingCRefViaTypedef", Q_ARG(ObjectCRef, obj)); + QCOMPARE(obj.objectName(), "works"); +} + void tst_Moc::testExtraData() { const QMetaObject *mobj = &PropertyTestClass::staticMetaObject; |