CppEditor: Let users check for unused functions in (sub-)projects

Note that especially in C++, there can be a lot of false positives,
especially in template-heavy code bases. We filter out the most notorious
offenders, namely:
    - templates themselves
    - constructors and destructors
    - *begin() and *end()
    - qHash()
    - main()
Since the code model does not know about symbol visibility, the
functionality is quite useless for libraries, unless you want to check
your test coverage.
The procedure is rather slow, but that shouldn't matter so much, as it's
something you'll only run "once in a while".

Fixes: QTCREATORBUG-6772
Change-Id: If00a537b760a9b0babdda6c848133715c3240155
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2022-10-27 14:49:15 +02:00
parent 43b21595e9
commit bfecefabc0
18 changed files with 559 additions and 45 deletions

View File

@@ -1180,12 +1180,12 @@ void tst_FindUsages::templateClass_className()
findUsages(classTS);
QCOMPARE(findUsages.usages().size(), 7);
QCOMPARE(findUsages.usages().at(0).tags, Usage::Tag::Declaration);
QCOMPARE(findUsages.usages().at(1).tags, Usage::Tags());
QCOMPARE(findUsages.usages().at(2).tags, Usage::Tags());
QCOMPARE(findUsages.usages().at(1).tags, Usage::Tag::ConstructorDestructor);
QCOMPARE(findUsages.usages().at(2).tags, Usage::Tag::ConstructorDestructor);
QCOMPARE(findUsages.usages().at(3).tags, Usage::Tags());
QCOMPARE(findUsages.usages().at(4).tags, Usage::Tags());
QCOMPARE(findUsages.usages().at(4).tags, Usage::Tag::ConstructorDestructor);
QCOMPARE(findUsages.usages().at(5).tags, Usage::Tags());
QCOMPARE(findUsages.usages().at(6).tags, Usage::Tags());
QCOMPARE(findUsages.usages().at(6).tags, Usage::Tag::ConstructorDestructor);
}
void tst_FindUsages::templateFunctionParameters()
@@ -2324,7 +2324,7 @@ int main()
find(structS);
QCOMPARE(find.usages().size(), 18);
QCOMPARE(find.usages().at(0).tags, Usage::Tag::Declaration);
QCOMPARE(find.usages().at(1).tags, Usage::Tags());
QCOMPARE(find.usages().at(1).tags, Usage::Tag::ConstructorDestructor);
QCOMPARE(find.usages().at(2).tags, Usage::Tags());
QCOMPARE(find.usages().at(3).tags, Usage::Tags());
QCOMPARE(find.usages().at(4).tags, Usage::Tags());