Bug 373947 - Signals false positive
Summary: Signals false positive
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-20 10:09 UTC by eric.lemanissier
Modified: 2016-12-28 14:04 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eric.lemanissier 2016-12-20 10:09:53 UTC
clazy-incorrect-emit has the following false positives:
"Emit keyword being used with non-signal" triggers for signals declared with "Q_SIGNAL" macro (singular form)

"Emitting inside constructor has no effect" triggers for signals emitted in a lambda defined in a constructor, even if the lambda is called outside of the constructor

"Missing emit keyword on signal call" seems to trigger for classes having multiple base classes

"Missing emit keyword on signal call" wrongly interprets as signals public methods declared after a Q_SIGNALS section

clazy-incorrect-emit has the same problem with "Q_SIGNAL". Also, it gives the error "QObject::destroyed is not a signal"
Comment 1 Sergio Martins 2016-12-20 15:11:27 UTC
thanks, I'll investigate
Comment 2 Sergio Martins 2016-12-20 15:15:10 UTC
Git commit 234daa48b88a93c12a7e8d08e5ab8b83ca02099e by Sergio Martins.
Committed on 20/12/2016 at 15:14.
Pushed by smartins into branch 'master'.

incorrect-emit: Move to level2 until false-positives are fixed

M  +1    -1    checks/level1/incorrect-emit.cpp

https://commits.kde.org/clazy/234daa48b88a93c12a7e8d08e5ab8b83ca02099e
Comment 3 Sergio Martins 2016-12-21 23:26:43 UTC
Git commit 789c9eb0cd108ddcc839815901462e12cd60c825 by Sergio Martins.
Committed on 21/12/2016 at 23:25.
Pushed by smartins into branch 'master'.

incorrect-emit: Don't warn about emit in CTOR if inside a lambda

The emit can be inside a lambda, which is fine, since it probably
will be emitted later and not when CTOR is being run.

M  +3    -0    checks/level1/incorrect-emit.cpp
M  +1    -0    tests/incorrect-emit/main.cpp

https://commits.kde.org/clazy/789c9eb0cd108ddcc839815901462e12cd60c825
Comment 4 Sergio Martins 2016-12-24 10:17:35 UTC
Git commit ca5af76d638c6582ed2466809d6edb0dfb34730e by Sergio Martins.
Committed on 24/12/2016 at 10:17.
Pushed by smartins into branch 'master'.

incorrect-emit: Also honour Q_SLOT and Q_SIGNAL keywords

M  +42   -12   AccessSpecifierManager.cpp
M  +1    -0    CMakeLists.txt
M  +9    -0    tests/incorrect-emit/main.cpp
M  +7    -5    tests/incorrect-emit/main.cpp.expected

https://commits.kde.org/clazy/ca5af76d638c6582ed2466809d6edb0dfb34730e
Comment 5 Sergio Martins 2016-12-27 17:43:55 UTC
this seems fixed, anything missing ?

re-open with a testcase if you spot something, thanks
Comment 6 eric.lemanissier 2016-12-27 19:23:14 UTC
The following example triggers

testCase.cpp:13:14: warning: Missing emit keyword on signal call TestClass::otherMethod [-Wclazy-incorrect-emit]
      return otherMethod();


#include <qobject.h>


class TestClass : public QObject
{
    Q_OBJECT
public:
    explicit TestClass(QObject *parent = 0 ) noexcept;


    int method()
    {
      return otherMethod();
    }
Q_SIGNALS:

    void someSignal();


public:
    int otherMethod()
    {
        return 1000;
    }
};
Comment 7 Sergio Martins 2016-12-28 13:23:51 UTC
Git commit 968595ee454e1b7c51635d0b1ced3902c8ab3984 by Sergio Martins.
Committed on 28/12/2016 at 13:22.
Pushed by smartins into branch 'master'.

incorrect-emit: Add unit-test for a bug that should be fixed

M  +14   -0    tests/incorrect-emit/main.cpp

https://commits.kde.org/clazy/968595ee454e1b7c51635d0b1ced3902c8ab3984
Comment 8 Sergio Martins 2016-12-28 14:04:02 UTC
Git commit 2e8846f7c58d4f1ea3655057933d17942bd38943 by Sergio Martins.
Committed on 28/12/2016 at 14:00.
Pushed by smartins into branch 'master'.

incorrect-emit: Fix false-positives with inline method definitions

When the methods were defined inside the class it could happen
that we were checking a method call before we had gathered
all access specifiers.

The solution is to visit all access specifiers as soon as we
visit the class.

Tests pass now too.

M  +18   -24   AccessSpecifierManager.cpp

https://commits.kde.org/clazy/2e8846f7c58d4f1ea3655057933d17942bd38943