Skip to content

Commit 7928483

Browse files
committed
CheckUnusedFunctions: added dedicated check() / avoid ambiguity of analyseWholeProgram()
1 parent ca95524 commit 7928483

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

lib/checkunusedfunctions.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,11 @@ Check::FileInfo *CheckUnusedFunctions::getFileInfo(const Tokenizer *tokenizer, c
384384
return nullptr;
385385
}
386386

387-
bool CheckUnusedFunctions::analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger)
387+
bool CheckUnusedFunctions::check(const Settings& settings, ErrorLogger &errorLogger)
388388
{
389-
(void)ctu;
390-
(void)fileInfo;
391389
CheckUnusedFunctions dummy(nullptr, &settings, &errorLogger);
392-
dummy.
393-
logChecker("CheckUnusedFunctions::analyseWholeProgram"); // unusedFunctions
394-
return check(&errorLogger, settings);
390+
dummy.logChecker("CheckUnusedFunctions::analyseWholeProgram");
391+
return instance.check(&errorLogger, settings);
395392
}
396393

397394
CheckUnusedFunctions::FunctionDecl::FunctionDecl(const Function *f)
@@ -421,7 +418,7 @@ namespace {
421418
};
422419
}
423420

424-
void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir)
421+
void CheckUnusedFunctions::analyseWholeProgram2(const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir)
425422
{
426423
std::map<std::string, Location> decls;
427424
std::set<std::string> calls;

lib/checkunusedfunctions.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,17 @@ class CPPCHECKLIB CheckUnusedFunctions : public Check {
6868
/** @brief Parse current TU and extract file info */
6969
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const override;
7070

71-
/** @brief Analyse all file infos for all TU */
72-
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) override;
73-
7471
std::string analyzerInfo() const;
7572

7673
/** @brief Combine and analyze all analyzerInfos for all TUs */
77-
static void analyseWholeProgram(const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir);
74+
static void analyseWholeProgram2(const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir);
7875

7976
static void getErrorMessages(ErrorLogger *errorLogger) {
8077
unusedFunctionError(errorLogger, emptyString, 0, 0, "funcName");
8178
}
8279

80+
static bool check(const Settings& settings, ErrorLogger &errorLogger);
81+
8382
private:
8483
static void clear();
8584

lib/cppcheck.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,9 +1778,13 @@ bool CppCheck::analyseWholeProgram()
17781778
ctu.nestedCalls.insert(ctu.nestedCalls.end(), fi2->nestedCalls.cbegin(), fi2->nestedCalls.cend());
17791779
}
17801780
}
1781+
17811782
// cppcheck-suppress shadowFunction - TODO: fix this
17821783
for (Check *check : Check::instances())
17831784
errors |= check->analyseWholeProgram(&ctu, mFileInfo, mSettings, *this); // TODO: ctu
1785+
1786+
errors |= CheckUnusedFunctions::check(mSettings, *this);
1787+
17841788
return errors && (mExitCode > 0);
17851789
}
17861790

@@ -1792,7 +1796,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<
17921796
return;
17931797
}
17941798
if (mSettings.checks.isEnabled(Checks::unusedFunction))
1795-
CheckUnusedFunctions::analyseWholeProgram(mSettings, this, buildDir);
1799+
CheckUnusedFunctions::analyseWholeProgram2(mSettings, this, buildDir);
17961800
std::list<Check::FileInfo*> fileInfoList;
17971801
CTU::FileInfo ctuFileInfo;
17981802

@@ -1845,6 +1849,8 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<
18451849
for (Check *check : Check::instances())
18461850
check->analyseWholeProgram(&ctuFileInfo, fileInfoList, mSettings, *this);
18471851

1852+
CheckUnusedFunctions::check(mSettings, *this);
1853+
18481854
for (Check::FileInfo *fi : fileInfoList)
18491855
delete fi;
18501856
}

0 commit comments

Comments
 (0)