Skip to content

Commit

Permalink
moved isUnusedFunctionCheckEnabled() from CppCheck to Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Feb 12, 2024
1 parent 07a516d commit 62bdd5c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);

if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
const bool err = reportSuppressions(settings, settings.nomsg, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *stdLogger);
const bool err = reportSuppressions(settings, settings.nomsg, settings.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *stdLogger);
if (err && returnValue == 0)
returnValue = settings.exitCode;
}
Expand Down
15 changes: 3 additions & 12 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string

try {
if (mSettings.library.markupFile(filename)) {
if (mSettings.checks.isEnabled(Checks::unusedFunction) &&
mSettings.useSingleJob() &&
mSettings.buildDir.empty()) {
if (mSettings.isUnusedFunctionCheckEnabled() && mSettings.buildDir.empty()) {
Tokenizer tokenizer(mSettings, this);
if (fileStream)
tokenizer.list.createTokens(*fileStream, filename);
Expand Down Expand Up @@ -1021,7 +1019,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
// In jointSuppressionReport mode, unmatched suppressions are
// collected after all files are processed
if (!mSettings.useSingleJob() && (mSettings.severity.isEnabled(Severity::information) || mSettings.checkConfiguration)) {
Suppressions::reportUnmatchedSuppressions(mSettings.nomsg.getUnmatchedLocalSuppressions(filename, isUnusedFunctionCheckEnabled()), *this);
Suppressions::reportUnmatchedSuppressions(mSettings.nomsg.getUnmatchedLocalSuppressions(filename, mSettings.isUnusedFunctionCheckEnabled()), *this);
}

mErrorList.clear();
Expand Down Expand Up @@ -1107,9 +1105,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mSettings.buildDir.empty()) {
unusedFunctionsChecker.parseTokens(tokenizer, tokenizer.list.getFiles().front().c_str(), mSettings);
}
if (mSettings.checks.isEnabled(Checks::unusedFunction) &&
mSettings.useSingleJob() &&
mSettings.buildDir.empty()) {
if (mSettings.isUnusedFunctionCheckEnabled() && mSettings.buildDir.empty()) {
CheckUnusedFunctions::parseTokens(tokenizer, mSettings);
}

Expand Down Expand Up @@ -1867,11 +1863,6 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<
delete fi;
}

bool CppCheck::isUnusedFunctionCheckEnabled() const
{
return (mSettings.useSingleJob() && mSettings.checks.isEnabled(Checks::unusedFunction));
}

void CppCheck::removeCtuInfoFiles(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings)
{
if (mSettings.buildDir.empty()) {
Expand Down
4 changes: 0 additions & 4 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
/** analyse whole program use .analyzeinfo files */
void analyseWholeProgram(const std::string &buildDir, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings);

/** Check if the user wants to check for unused functions
* and if it's possible at all */
bool isUnusedFunctionCheckEnabled() const;

/** Remove *.ctu-info files */
void removeCtuInfoFiles(const std::list<std::pair<std::string, std::size_t>>& files, const std::list<FileSettings>& fileSettings); // cppcheck-suppress functionConst // has side effects

Expand Down
7 changes: 7 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,13 @@ class CPPCHECKLIB WARN_UNUSED Settings {
return jobs == 1;
}

/** Check if the user wants to check for unused functions
* and if it's possible at all */
bool isUnusedFunctionCheckEnabled() const
{
return useSingleJob() && checks.isEnabled(Checks::unusedFunction);
}

void setCheckLevelExhaustive();
void setCheckLevelNormal();

Expand Down

0 comments on commit 62bdd5c

Please sign in to comment.