Bug 359000

Summary: new check: warn about unused Qt objects
Product: [Developer tools] clazy Reporter: Nyall Dawson <nyall.dawson>
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED FIXED    
Severity: wishlist CC: smartins
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Nyall Dawson 2016-02-04 22:15:47 UTC
I'd find a check which warns on certain unused Qt objects which are created but never used very helpful.

For instance, QString, Qt containers, QColor, QVariant. Interestingly, Qt Creator highlights these unused variables but I can't find any way of listing them in bulk for removal...
Comment 1 Sergio Martins 2016-02-11 21:25:31 UTC
can you attach a test-case ?
Comment 2 Sergio Martins 2016-02-15 19:04:41 UTC
clang already warns on unused variables, so clazy won't duplicate functionality
Comment 3 Nyall Dawson 2016-02-18 00:06:40 UTC
Here's a simple test case:

#include <QVariant>
#include <QIcon>

int main(int, char **)
{
    QString string; //no warning
    QList<int> list; //no warning
    QVariant var; //no warning
    QIcon i; //no warning

    int num; //warning
}

building this with clang 3.7 warns only about the unused int variable, not the unused QString/QList/QVariant etc.
Comment 4 Sergio Martins 2016-02-18 10:33:10 UTC
We could have a [warn_unused] attribute and tag Qt containers with it:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55203
Comment 5 Sergio Martins 2016-02-28 13:33:37 UTC
Git commit ff28b66ce5ce8b6f76487c62c21063676df41cc0 by Sergio Martins.
Committed on 28/02/2016 at 13:32.
Pushed by smartins into branch 'master'.

Introduce unused-non-trivial-variable check

Because the compilers don't warn for unused non-trivial Qt value classes.
This check has a whitelist of classes and warns when they there are unused
variables.

M  +2    -1    CMakeLists.txt
A  +8    -0    checks/README-unused-non-trivial-variable
A  +95   -0    checks/unused-non-trivial-variable.cpp     [License: LGPL (v2+)]
A  +49   -0    checks/unused-non-trivial-variable.h     [License: LGPL (v2+)]
M  +11   -11   tests/clazy/test_requested_checks.sh.expected
A  +7    -0    tests/unused-non-trivial-variable/config.json
A  +36   -0    tests/unused-non-trivial-variable/main.cpp     [License: UNKNOWN]  *
A  +2    -0    tests/unused-non-trivial-variable/main.cpp.expected

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.


http://commits.kde.org/clazy/ff28b66ce5ce8b6f76487c62c21063676df41cc0