Skip to content

readability-convert-member-functions-to-static false positive with Qt slot methods #57520

@firewave

Description

@firewave
#include <QObject>

class TestDummy : public QObject {
Q_OBJECT

private slots:
    void construct();
};

#include <QtTest>

void TestDummy::construct()
{
    QCOMPARE(13, 13); // no warning with empty body
}

QTEST_MAIN(TestDummy)
clang-tidy-14 -checks=readability-convert-member-functions-to-static testdummy.cpp -- -isystem /usr/include/x86_64-linux-gnu/qt5/QtTest -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore
testdummy.cpp:12:17: error: method 'construct' can be made static [readability-convert-member-functions-to-static,-warnings-as-errors]
void TestDummy::construct()
                ^

The methods are called on a class object in the generated MOC:

void TestDummy::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
    if (_c == QMetaObject::InvokeMetaMethod) {
        auto *_t = static_cast<TestDummy*>(_o);
        (void)_t;
        switch (_id) {
        case 0: _t->construct(); break;
        default: ;
        }
    }
    (void)_a;
}

I guess there's not much which can be done on the clang-tidy side here but I thought it might be worth reporting anyways since this should be a very common pattern in Qt applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions