Bug 375239

Summary: connect-non-signal false positive when using macros to declare signals
Product: [Developer tools] clazy Reporter: nicolas.kniebihler
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED FIXED    
Severity: normal CC: nicolas.kniebihler, smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: MacPorts   
OS: macOS   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description nicolas.kniebihler 2017-01-18 14:27:25 UTC
connect-non-signal returns "MyClass::mySignal is not a signal" when we have something like this:

#define DECLARE_SIGNAL(name) \
    Q_SIGNALS: \
        void name();

class MyClass
{
    Q_OBJECT

public:
    explicit MyClass(QObject *parent = 0);
    DECLARE_SIGNAL(mySignal)

public slots:
    void mySlot();
}

MyClass::MyClass(QObject *parent) : QObject(parent)
{
    connect(this, &MyClass::mySignal, this, &MyClass::mySlot);
}

Detected on commit: 230c4a8299e1dfd7a505cbba681d4ba1c688c353
Comment 1 Sergio Martins 2017-01-18 19:30:23 UTC
Git commit 30febca0c99416b6433e8ff20e9f2ffd18b397f5 by Sergio Martins.
Committed on 18/01/2017 at 19:28.
Pushed by smartins into branch 'master'.

connect-non-signal: Add unit-test for a reported bug

A  +22   -0    tests/connect-non-signal/bug375239.cpp     [License: UNKNOWN]  *
M  +5    -0    tests/connect-non-signal/config.json

The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://commits.kde.org/clazy/30febca0c99416b6433e8ff20e9f2ffd18b397f5
Comment 2 Sergio Martins 2017-01-19 11:22:49 UTC
Git commit 181013368411278e7fd3210cc024b4009418f3aa by Sergio Martins.
Committed on 19/01/2017 at 11:11.
Pushed by smartins into branch 'master'.

connect-non-signal: Don't warn if the method decl comes from a macro

This is very hard to support, since both the method and the signal macro
will have the same source location. Maybe it can be done by falling back to
comparing the spelling location whenever the locs are the same, but would mean
a very large rewrite

Anyway, someone using a macro that spits "Q_SIGNALS: void myMethod()" will
never be affected by connect-non-signal because it always has the Q_SIGNALS
keyword.

M  +1    -1    AccessSpecifierManager.cpp
M  +1    -4    checks/level0/connect-non-signal.cpp
M  +1    -3    checks/level1/incorrect-emit.cpp
A  +0    -0    tests/connect-non-signal/bug375239.cpp.expected
M  +1    -2    tests/connect-non-signal/config.json

https://commits.kde.org/clazy/181013368411278e7fd3210cc024b4009418f3aa