Skip to content

Commit eac040a

Browse files
firewavedanmar
authored andcommitted
Various clang-tidy fixes (danmar#2192)
* use range loops * removed redundant string initializations * use nullptr * use proper boolean false * removed unnecessary continue from end of loop * removed unnecessary c_str() usage * use emplace_back() * removed redundant void arguments
1 parent ca5f256 commit eac040a

17 files changed

+38
-39
lines changed

lib/checkbool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void CheckBool::assignBoolToFloatError(const Token *tok)
440440
"Boolean value assigned to floating point variable.", CWE704, false);
441441
}
442442

443-
void CheckBool::returnValueOfFunctionReturningBool(void)
443+
void CheckBool::returnValueOfFunctionReturningBool()
444444
{
445445
if (!mSettings->isEnabled(Settings::STYLE))
446446
return;

lib/importproject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void ImportProject::importVcxproj(const std::string &filename, std::map<std::str
626626
if (std::strcmp(e->Name(), "ClCompile") == 0) {
627627
const char *include = e->Attribute("Include");
628628
if (include && Path::acceptFile(include))
629-
compileList.push_back(include);
629+
compileList.emplace_back(include);
630630
}
631631
}
632632
}
@@ -700,7 +700,7 @@ void ImportProject::importBcb6Prj(const std::string &projectFilename)
700700
if (std::strcmp(f->Name(), "FILE") == 0) {
701701
const char *filename = f->Attribute("FILENAME");
702702
if (filename && Path::acceptFile(filename))
703-
compileList.push_back(filename);
703+
compileList.emplace_back(filename);
704704
}
705705
}
706706
} else if (std::strcmp(node->Name(), "MACROS") == 0) {

lib/library.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static std::vector<std::string> getnames(const char *names)
3939
ret.emplace_back(names, p-names);
4040
names = p + 1;
4141
}
42-
ret.push_back(names);
42+
ret.emplace_back(names);
4343
return ret;
4444
}
4545

@@ -96,7 +96,7 @@ Library::Error Library::load(const char exename[], const char path[])
9696

9797
std::list<std::string> cfgfolders;
9898
#ifdef FILESDIR
99-
cfgfolders.push_back(FILESDIR "/cfg");
99+
cfgfolders.emplace_back(FILESDIR "/cfg");
100100
#endif
101101
if (exename) {
102102
const std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(exename)));

lib/path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ std::string Path::getCurrentPath()
134134
#ifndef _WIN32
135135
if (getcwd(currentPath, 4096) != nullptr)
136136
#else
137-
if (_getcwd(currentPath, 4096) != 0)
137+
if (_getcwd(currentPath, 4096) != nullptr)
138138
#endif
139139
return std::string(currentPath);
140140

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cf
543543
}
544544

545545
if (Path::isCPP(filename))
546-
dui.defines.push_back("__cplusplus");
546+
dui.defines.emplace_back("__cplusplus");
547547

548548
dui.undefined = mSettings.userUndefs; // -U
549549
dui.includePaths = mSettings.includePaths; // -I

lib/standards.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct Standards {
5656
}
5757
return false;
5858
}
59-
const std::string getC(void) const {
59+
const std::string getC() const {
6060
switch (c) {
6161
case C89:
6262
return "c89";
@@ -90,7 +90,7 @@ struct Standards {
9090
}
9191
return false;
9292
}
93-
const std::string getCPP(void) const {
93+
const std::string getCPP() const {
9494
switch (cpp) {
9595
case CPP03:
9696
return "c++03";

lib/symboldatabase.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,13 @@ void SymbolDatabase::createSymbolDatabaseClassInfo()
715715
// fill in base class info
716716
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
717717
// finish filling in base class info
718-
for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) {
719-
const Type* found = findType(it->derivedFrom[i].nameTok, it->enclosingScope);
718+
for (Type::BaseInfo & i : it->derivedFrom) {
719+
const Type* found = findType(i.nameTok, it->enclosingScope);
720720
if (found && found->findDependency(&(*it))) {
721721
// circular dependency
722722
//mTokenizer->syntaxError(nullptr);
723723
} else {
724-
it->derivedFrom[i].type = found;
724+
i.type = found;
725725
}
726726
}
727727
}
@@ -842,7 +842,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
842842
Scope *scope = &(*it);
843843

844844
if (!scope->definedType) {
845-
mBlankTypes.push_back(Type());
845+
mBlankTypes.emplace_back();
846846
scope->definedType = &mBlankTypes.back();
847847
}
848848

@@ -3344,8 +3344,8 @@ const Function *Function::getOverriddenFunction(bool *foundAllBaseClasses) const
33443344
const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType, bool *foundAllBaseClasses) const
33453345
{
33463346
// check each base class
3347-
for (std::size_t i = 0; i < baseType->derivedFrom.size(); ++i) {
3348-
const ::Type* derivedFromType = baseType->derivedFrom[i].type;
3347+
for (const ::Type::BaseInfo & i : baseType->derivedFrom) {
3348+
const ::Type* derivedFromType = i.type;
33493349
// check if base class exists in database
33503350
if (!derivedFromType || !derivedFromType->classScope) {
33513351
if (foundAllBaseClasses)

lib/templatesimplifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,7 +3420,7 @@ void TemplateSimplifier::printOut(const std::string & text) const
34203420
unsigned int decl1Index = 0;
34213421
for (const auto & decl1 : mTemplateDeclarations) {
34223422
if (decl1.isSpecialization() && mapItem.first == decl1.token()) {
3423-
bool found = 0;
3423+
bool found = false;
34243424
unsigned int decl2Index = 0;
34253425
for (const auto & decl2 : mTemplateDeclarations) {
34263426
if (mapItem.second == decl2.token()) {
@@ -3455,7 +3455,7 @@ void TemplateSimplifier::printOut(const std::string & text) const
34553455
unsigned int decl1Index = 0;
34563456
for (const auto & decl1 : mTemplateDeclarations) {
34573457
if (mapItem.first == decl1.token()) {
3458-
bool found = 0;
3458+
bool found = false;
34593459
unsigned int decl2Index = 0;
34603460
for (const auto & decl2 : mTemplateDeclarations) {
34613461
if (mapItem.second == decl2.token()) {

lib/token.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ void Token::insertToken(const std::string &tokenStr, const std::string &original
10161016
if (mImpl->mScopeInfo) {
10171017
// If the brace is immediately closed there is no point opening a new scope for it
10181018
if (tokenStr == "{") {
1019-
std::string nextScopeNameAddition = "";
1019+
std::string nextScopeNameAddition;
10201020
// This might be the opening of a member function
10211021
Token *tok1 = newToken;
10221022
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))

lib/tokenize.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ void Tokenizer::simplifyTypedef()
867867
if (tokOffset->next()->str() == "(")
868868
tokOffset = tokOffset->next();
869869
else if (Token::simpleMatch(tokOffset, "( * (")) {
870-
pointers.push_back("*");
870+
pointers.emplace_back("*");
871871
tokOffset = tokOffset->tokAt(2);
872872
}
873873

@@ -2837,7 +2837,7 @@ void Tokenizer::calculateScopes()
28372837
for (auto tok = list.front(); tok; tok = tok->next())
28382838
tok->scopeInfo(nullptr);
28392839

2840-
std::string nextScopeNameAddition = "";
2840+
std::string nextScopeNameAddition;
28412841
std::shared_ptr<ScopeInfo2> primaryScope = std::make_shared<ScopeInfo2>("", nullptr);
28422842
list.front()->scopeInfo(primaryScope);
28432843

@@ -2847,7 +2847,7 @@ void Tokenizer::calculateScopes()
28472847
tok->scopeInfo(tok->previous()->scopeInfo());
28482848

28492849
if (Token::Match(tok, "using namespace %name% ::|<|;")) {
2850-
std::string usingNamespaceName = "";
2850+
std::string usingNamespaceName;
28512851
for (const Token* namespaceNameToken = tok->tokAt(2);
28522852
!Token::simpleMatch(namespaceNameToken, ";");
28532853
namespaceNameToken = namespaceNameToken->next()) {
@@ -7993,7 +7993,6 @@ bool Tokenizer::simplifyRedundantParentheses()
79937993
tok->deleteNext();
79947994
tok2->deleteThis();
79957995
ret = true;
7996-
continue;
79977996
}
79987997

79997998
if (Token::simpleMatch(tok->previous(), "? (") && Token::simpleMatch(tok->link(), ") :")) {

0 commit comments

Comments
 (0)