Skip to content

Commit d41c05c

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

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
@@ -1777,9 +1777,13 @@ bool CppCheck::analyseWholeProgram()
17771777
ctu.nestedCalls.insert(ctu.nestedCalls.end(), fi2->nestedCalls.cbegin(), fi2->nestedCalls.cend());
17781778
}
17791779
}
1780+
17801781
// cppcheck-suppress shadowFunction - TODO: fix this
17811782
for (Check *check : Check::instances())
17821783
errors |= check->analyseWholeProgram(&ctu, mFileInfo, mSettings, *this); // TODO: ctu
1784+
1785+
errors |= CheckUnusedFunctions::check(mSettings, *this);
1786+
17831787
return errors && (mExitCode > 0);
17841788
}
17851789

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

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

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

0 commit comments

Comments
 (0)