Bug 355593

Summary: Do not fix connects to static member functions with -fix-old-style-connect
Product: [Developer tools] clazy Reporter: Tobias Hunger <tobias.hunger>
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED FIXED    
Severity: normal CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Testcase in a more convenient form

Description Tobias Hunger 2015-11-19 14:56:59 UTC
Please do not fix old style connects to static member functions. The connect will actually compile, but the disconnect won't, so it is IMHO better to not touch these.

E.g.: The following connect/disconnect should be left alone:

#include <QObject>

class TestClass : public QObject
{
public slots:
    TestClass(QObject *parent = nullptr) : QObject(parent) { }

     static void test(QObject *obj) { Q_UNUSED(obj); }
};

int main(int argc, char** argv) {
    auto test = new TestClass;
    connect(test, SIGNAL(destroyed(QObject*)), test, SLOT(test(QObject*)));
    disconnect(test, SIGNAL(destroyed(QObject*)), test, SLOT(test(QObject*)));
}
Comment 1 Sergio Martins 2015-11-19 15:01:13 UTC
Lets leave the disconnect alone, but the connect is fine, no ?
Comment 2 Tobias Hunger 2015-11-19 15:06:24 UTC
Created attachment 95602 [details]
Testcase in a more convenient form

Basically the same test case as found inline, but with a .pro-file and without warnings and build errors.
Comment 3 Tobias Hunger 2015-11-19 15:08:19 UTC
I think the connect is implicitly converted into a lambda, which can't be disconnected later. So to be safe you should leave both the connect and disconnect alone.
Comment 4 Sergio Martins 2015-11-20 19:18:53 UTC
Git commit 70d3f22d0c9039dad8e61bcc0138e66fab879708 by Sergio Martins.
Committed on 20/11/2015 at 19:18.
Pushed by smartins into branch 'master'.

old-style-connect: Don't fix connects to static slots

Only connect works, disconnect doesn't build.
And you can't use old-style disconnect to break a new-style connect.
The only solution is to not apply fixits to {dis}connects to static slots.

M  +3    -0    checks/oldstyleconnect.cpp
M  +23   -0    tests/old-style-connect/main.cpp
M  +2    -0    tests/old-style-connect/test.expected

http://commits.kde.org/clazy/70d3f22d0c9039dad8e61bcc0138e66fab879708