Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Checks: >
-objc-*,
-openmp-*,
-zircon-*,
cppcoreguidelines-avoid-const-or-ref-data-members,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-rvalue-reference-param-not-moved,
google-explicit-constructor,
Expand Down
282 changes: 143 additions & 139 deletions Makefile

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ Does not improve the readability.
To be evaluated (need to remove exclusion).

`cppcoreguidelines-missing-std-forward`<br/>
`cppcoreguidelines-avoid-const-or-ref-data-members`<br/>
`cppcoreguidelines-macro-usage`<br/>
`cppcoreguidelines-pro-type-member-init`<br/>
`cppcoreguidelines-prefer-member-initializer`<br/>
Expand Down
652 changes: 326 additions & 326 deletions cli/cmdlineparser.cpp

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "cmdlinelogger.h"
#include "filesettings.h"
#include "nonnullptr.h"
#include "standards.h"
#include "utils.h"

Expand Down Expand Up @@ -117,11 +118,11 @@ class CmdLineParser {
T tmp;
std::string err;
if (!strToInt(arg + offset, tmp, &err)) {
mLogger.printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + ".");
mLogger->printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + ".");
return false;
}
if (mustBePositive && tmp < 0) {
mLogger.printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer.");
mLogger->printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer.");
return false;
}
num = tmp;
Expand Down Expand Up @@ -152,10 +153,10 @@ class CmdLineParser {

void outputFormatOptionMixingError() const;

CmdLineLogger &mLogger;
NonNullPtr<CmdLineLogger> mLogger;

Settings &mSettings;
Suppressions &mSuppressions;
NonNullPtr<Settings> mSettings;
NonNullPtr<Suppressions> mSuppressions;

protected:
std::vector<std::string> mPathNames;
Expand Down
4 changes: 2 additions & 2 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ namespace {
writeToPipeInternal(type, data.c_str(), len);
}

const int mWpipe;
const bool mDebug;
int mWpipe;
bool mDebug;
};
}

Expand Down
3 changes: 2 additions & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "infer.h"
#include "library.h"
#include "mathlib.h"
#include "nonnullptr.h"
#include "settings.h"
#include "symboldatabase.h"
#include "token.h"
Expand Down Expand Up @@ -3142,7 +3143,7 @@ namespace {
};

struct ExpressionChangedSkipDeadCode {
const Library& library;
NonNullPtr<const Library> library;
const std::function<std::vector<MathLib::bigint>(const Token* tok)>* evaluate;
ExpressionChangedSkipDeadCode(const Library& library,
const std::function<std::vector<MathLib::bigint>(const Token* tok)>& evaluate)
Expand Down
18 changes: 9 additions & 9 deletions lib/checkersreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ void CheckersReport::countCheckers()
mActiveCheckersCount = mAllCheckersCount = 0;

for (const auto& checkReq: checkers::allCheckers) {
if (mActiveCheckers.count(checkReq.first) > 0)
if (mActiveCheckers->count(checkReq.first) > 0)
++mActiveCheckersCount;
++mAllCheckersCount;
}
for (const auto& addonInfo: mSettings.addonInfos) {
for (const auto& addonInfo: mSettings->addonInfos) {
for (const auto& checkReq: addonInfo.checkers) {
if (mActiveCheckers.count(checkReq.first) > 0)
if (mActiveCheckers->count(checkReq.first) > 0)
++mActiveCheckersCount;
++mAllCheckersCount;
}
}

if (mSettings.addons.count("misra")) {
if (mSettings->addons.count("misra")) {
const bool doUnusedFunctionOnly = Settings::unusedFunctionOnly();
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
Expand Down Expand Up @@ -185,20 +185,20 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
}
for (const auto& checkReq: checkers::allCheckers) {
const std::string& checker = checkReq.first;
const bool active = mActiveCheckers.count(checkReq.first) > 0;
const bool active = mActiveCheckers->count(checkReq.first) > 0;
const std::string& req = checkReq.second;
fout << (active ? "Yes " : "No ") << checker;
if (!active && !req.empty())
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
fout << std::endl;
}

for (const auto& addonInfo: mSettings.addonInfos) {
for (const auto& addonInfo: mSettings->addonInfos) {
if (addonInfo.checkers.empty())
continue;
fout << std::endl << std::endl;
std::string title;
if (mSettings.premium && addonInfo.name == "premiumaddon.json")
if (mSettings->premium && addonInfo.name == "premiumaddon.json")
title = "Cppcheck Premium";
else {
title = addonInfo.name;
Expand All @@ -217,7 +217,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const

for (const auto& checkReq: addonInfo.checkers) {
const std::string& checker = checkReq.first;
const bool active = mActiveCheckers.count(checkReq.first) > 0;
const bool active = mActiveCheckers->count(checkReq.first) > 0;
const std::string& req = checkReq.second;
fout << (active ? "Yes " : "No ") << checker;
if (!active && !req.empty())
Expand All @@ -238,7 +238,7 @@ std::string CheckersReport::getXmlReport(const std::string& criticalErrors) cons
ret += " <critical-errors/>\n";
ret += " <checkers-report>\n";
const int misraCVersion = getMisraCVersion(mSettings);
for (std::string checker: mActiveCheckers) {
for (std::string checker: *mActiveCheckers) {
if (checker.compare(0,8,"Misra C:") == 0)
checker = "Misra C " + std::to_string(misraCVersion) + ":" + checker.substr(8);
ret += " <checker id=\"" + checker + "\"/>\n";
Expand Down
5 changes: 3 additions & 2 deletions lib/checkersreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define checkersReportH

#include "config.h"
#include "nonnullptr.h"

#include <set>
#include <string>
Expand All @@ -37,8 +38,8 @@ class CPPCHECKLIB CheckersReport {
std::string getXmlReport(const std::string& criticalErrors) const;

private:
const Settings& mSettings;
const std::set<std::string>& mActiveCheckers;
NonNullPtr<const Settings> mSettings;
NonNullPtr<const std::set<std::string>> mActiveCheckers;

void countCheckers();

Expand Down
7 changes: 4 additions & 3 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "fwdanalysis.h"
#include "library.h"
#include "mathlib.h"
#include "nonnullptr.h"
#include "platform.h"
#include "settings.h"
#include "standards.h"
Expand Down Expand Up @@ -4513,7 +4514,7 @@ struct UnionMember {
: name(name)
, size(size) {}

const std::string &name;
NonNullPtr<const std::string> name;
size_t size;
};

Expand All @@ -4523,7 +4524,7 @@ struct Union {
, name(scope.className) {}

const Scope *scope;
const std::string &name;
NonNullPtr<const std::string> name;
std::vector<UnionMember> members;

const UnionMember *largestMember() const {
Expand Down Expand Up @@ -4632,7 +4633,7 @@ void CheckOtherImpl::unionZeroInitError(const Token *tok,
"Zero initializing union '$symbol' does not guarantee " +
"its complete storage to be zero initialized as its largest member " +
"is not declared as the first member. Consider making " +
largestMember.name + " the first member or favor memset().");
*largestMember.name + " the first member or favor memset().");
}

//-----------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "nonnullptr.h"
#include "pathanalysis.h"
#include "settings.h"
#include "standards.h"
Expand Down Expand Up @@ -2872,7 +2873,7 @@ namespace {
private:
const Token* mBodyTok;
const Token* mLoopVar{};
const Settings& mSettings;
NonNullPtr<const Settings> mSettings;
std::set<nonneg int> mVarsChanged;

public:
Expand All @@ -2895,7 +2896,7 @@ namespace {
int n = 1 + (astIsPointer(tok) ? 1 : 0);
for (int i = 0; i < n; i++) {
bool inconclusive = false;
if (isVariableChangedByFunctionCall(tok, i, mSettings.library, &inconclusive))
if (isVariableChangedByFunctionCall(tok, i, mSettings->library, &inconclusive))
return true;
if (inconclusive)
return true;
Expand Down
21 changes: 11 additions & 10 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "errortypes.h"
#include "mathlib.h"
#include "nonnullptr.h"
#include "standards.h"
#include "symboldatabase.h"
#include "token.h"
Expand Down Expand Up @@ -233,8 +234,8 @@ namespace clangimport {
, mSymbolDatabase(symbolDatabase)
{}

const Settings &mSettings;
SymbolDatabase &mSymbolDatabase;
NonNullPtr<const Settings> mSettings;
NonNullPtr<SymbolDatabase> mSymbolDatabase;

int enumValue = 0;

Expand Down Expand Up @@ -643,7 +644,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const s
for (const Token *typeToken = tokenList.back(); Token::Match(typeToken, "&|*|%name%"); typeToken = typeToken->previous()) {
if (!typeToken->isName())
continue;
const ::Type *recordType = scope->symdb.findVariableType(scope, typeToken);
const ::Type *recordType = scope->symdb->findVariableType(scope, typeToken);
if (recordType) {
const_cast<Token*>(typeToken)->type(recordType);
return recordType;
Expand Down Expand Up @@ -672,7 +673,7 @@ void clangimport::AstNode::addFullScopeNameTokens(TokenList &tokenList, const Sc
const Scope *clangimport::AstNode::getNestedInScope(TokenList &tokenList)
{
if (!tokenList.back())
return &mData->mSymbolDatabase.scopeList.front();
return &mData->mSymbolDatabase->scopeList.front();
if (tokenList.back()->str() == "}" && mData->mNotScope.find(tokenList.back()) == mData->mNotScope.end())
return tokenList.back()->scope()->nestedIn;
return tokenList.back()->scope();
Expand Down Expand Up @@ -1071,8 +1072,8 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
const_cast<Token *>(enumscope->bodyEnd)->deletePrevious();

// Create enum type
mData->mSymbolDatabase.typeList.emplace_back(enumtok, enumscope, enumtok->scope());
enumscope->definedType = &mData->mSymbolDatabase.typeList.back();
mData->mSymbolDatabase->typeList.emplace_back(enumtok, enumscope, enumtok->scope());
enumscope->definedType = &mData->mSymbolDatabase->typeList.back();
if (nametok)
const_cast<Scope *>(enumtok->scope())->definedTypesMap[nametok->str()] = enumscope->definedType;

Expand Down Expand Up @@ -1238,8 +1239,8 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
}

Scope *recordScope = createScope(tokenList, ScopeType::eStruct, children, classDef);
mData->mSymbolDatabase.typeList.emplace_back(classDef, recordScope, classDef->scope());
recordScope->definedType = &mData->mSymbolDatabase.typeList.back();
mData->mSymbolDatabase->typeList.emplace_back(classDef, recordScope, classDef->scope());
recordScope->definedType = &mData->mSymbolDatabase->typeList.back();
if (!recordName.empty()) {
recordScope->className = recordName;
const_cast<Scope *>(classDef->scope())->definedTypesMap[recordName] = recordScope->definedType;
Expand Down Expand Up @@ -1520,8 +1521,8 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList &tokenList)
const std::string addr = mExtTokens[0];
mData->scopeDecl(addr, scope);
scope->className = className;
mData->mSymbolDatabase.typeList.emplace_back(classToken, scope, classToken->scope());
scope->definedType = &mData->mSymbolDatabase.typeList.back();
mData->mSymbolDatabase->typeList.emplace_back(classToken, scope, classToken->scope());
scope->definedType = &mData->mSymbolDatabase->typeList.back();
const_cast<Scope *>(classToken->scope())->definedTypesMap[className] = scope->definedType;
}
addtoken(tokenList, ";");
Expand Down
1 change: 1 addition & 0 deletions lib/cppcheck.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<ClInclude Include="library.h" />
<ClInclude Include="matchcompiler.h" />
<ClInclude Include="mathlib.h" />
<ClInclude Include="nonnullptr.h" />
<ClInclude Include="path.h" />
<ClInclude Include="pathanalysis.h" />
<ClInclude Include="pathmatch.h" />
Expand Down
13 changes: 7 additions & 6 deletions lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "config.h"
#include "errortypes.h"
#include "nonnullptr.h"

#include <cstdint>
#include <ctime>
Expand Down Expand Up @@ -301,25 +302,25 @@
~ProgressReporter() {
if (mReportProgressInterval < 0)
return;
mErrorLogger.reportProgress(mFilename, mStage.c_str(), 100);
mErrorLogger->reportProgress(mFilename, mStage.c_str(), 100);

Check warning

Code scanning / Cppcheck Premium

Use meaningful symbolic constants to represent literal values. Warning

Use meaningful symbolic constants to represent literal values.
}

void report(int value) {
if (mReportProgressInterval < 0 || value == mLastValue)
return;
const std::time_t t = std::time(nullptr);
if (t >= mLastTime + mReportProgressInterval) {
mErrorLogger.reportProgress(mFilename, mStage.c_str(), value);
mErrorLogger->reportProgress(mFilename, mStage.c_str(), value);
mLastTime = t;
mLastValue = value;
}
}

private:
ErrorLogger& mErrorLogger;
const int mReportProgressInterval;
const std::string mFilename;
const std::string mStage;
NonNullPtr<ErrorLogger> mErrorLogger;
int mReportProgressInterval;
std::string mFilename;
std::string mStage;
std::time_t mLastTime{0};
int mLastValue{-1};
};
Expand Down
Loading
Loading