Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
firewave opened this issue Sep 2, 2022 · 1 comment
Labels
clang-tidy false-positive Warning fires when it should not

Comments

@firewave
Copy link

firewave commented Sep 2, 2022

#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.

@EugeneZelenko EugeneZelenko added clang-tidy false-positive Warning fires when it should not and removed new issue labels Sep 2, 2022
@llvmbot
Copy link
Member

llvmbot commented Sep 2, 2022

@llvm/issue-subscribers-clang-tidy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

3 participants