Various clang-tidy fixes (#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
This commit is contained in:
Oliver Stöneberg 2019-09-25 15:25:19 +02:00 committed by Daniel Marjamäki
parent ca5f2562fc
commit eac040a00b
17 changed files with 38 additions and 39 deletions

View File

@ -440,7 +440,7 @@ void CheckBool::assignBoolToFloatError(const Token *tok)
"Boolean value assigned to floating point variable.", CWE704, false); "Boolean value assigned to floating point variable.", CWE704, false);
} }
void CheckBool::returnValueOfFunctionReturningBool(void) void CheckBool::returnValueOfFunctionReturningBool()
{ {
if (!mSettings->isEnabled(Settings::STYLE)) if (!mSettings->isEnabled(Settings::STYLE))
return; return;

View File

@ -626,7 +626,7 @@ void ImportProject::importVcxproj(const std::string &filename, std::map<std::str
if (std::strcmp(e->Name(), "ClCompile") == 0) { if (std::strcmp(e->Name(), "ClCompile") == 0) {
const char *include = e->Attribute("Include"); const char *include = e->Attribute("Include");
if (include && Path::acceptFile(include)) if (include && Path::acceptFile(include))
compileList.push_back(include); compileList.emplace_back(include);
} }
} }
} }
@ -700,7 +700,7 @@ void ImportProject::importBcb6Prj(const std::string &projectFilename)
if (std::strcmp(f->Name(), "FILE") == 0) { if (std::strcmp(f->Name(), "FILE") == 0) {
const char *filename = f->Attribute("FILENAME"); const char *filename = f->Attribute("FILENAME");
if (filename && Path::acceptFile(filename)) if (filename && Path::acceptFile(filename))
compileList.push_back(filename); compileList.emplace_back(filename);
} }
} }
} else if (std::strcmp(node->Name(), "MACROS") == 0) { } else if (std::strcmp(node->Name(), "MACROS") == 0) {

View File

@ -39,7 +39,7 @@ static std::vector<std::string> getnames(const char *names)
ret.emplace_back(names, p-names); ret.emplace_back(names, p-names);
names = p + 1; names = p + 1;
} }
ret.push_back(names); ret.emplace_back(names);
return ret; return ret;
} }
@ -96,7 +96,7 @@ Library::Error Library::load(const char exename[], const char path[])
std::list<std::string> cfgfolders; std::list<std::string> cfgfolders;
#ifdef FILESDIR #ifdef FILESDIR
cfgfolders.push_back(FILESDIR "/cfg"); cfgfolders.emplace_back(FILESDIR "/cfg");
#endif #endif
if (exename) { if (exename) {
const std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(exename))); const std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(exename)));

View File

@ -134,7 +134,7 @@ std::string Path::getCurrentPath()
#ifndef _WIN32 #ifndef _WIN32
if (getcwd(currentPath, 4096) != nullptr) if (getcwd(currentPath, 4096) != nullptr)
#else #else
if (_getcwd(currentPath, 4096) != 0) if (_getcwd(currentPath, 4096) != nullptr)
#endif #endif
return std::string(currentPath); return std::string(currentPath);

View File

@ -543,7 +543,7 @@ static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cf
} }
if (Path::isCPP(filename)) if (Path::isCPP(filename))
dui.defines.push_back("__cplusplus"); dui.defines.emplace_back("__cplusplus");
dui.undefined = mSettings.userUndefs; // -U dui.undefined = mSettings.userUndefs; // -U
dui.includePaths = mSettings.includePaths; // -I dui.includePaths = mSettings.includePaths; // -I

View File

@ -56,7 +56,7 @@ struct Standards {
} }
return false; return false;
} }
const std::string getC(void) const { const std::string getC() const {
switch (c) { switch (c) {
case C89: case C89:
return "c89"; return "c89";
@ -90,7 +90,7 @@ struct Standards {
} }
return false; return false;
} }
const std::string getCPP(void) const { const std::string getCPP() const {
switch (cpp) { switch (cpp) {
case CPP03: case CPP03:
return "c++03"; return "c++03";

View File

@ -715,13 +715,13 @@ void SymbolDatabase::createSymbolDatabaseClassInfo()
// fill in base class info // fill in base class info
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) { for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
// finish filling in base class info // finish filling in base class info
for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) { for (Type::BaseInfo & i : it->derivedFrom) {
const Type* found = findType(it->derivedFrom[i].nameTok, it->enclosingScope); const Type* found = findType(i.nameTok, it->enclosingScope);
if (found && found->findDependency(&(*it))) { if (found && found->findDependency(&(*it))) {
// circular dependency // circular dependency
//mTokenizer->syntaxError(nullptr); //mTokenizer->syntaxError(nullptr);
} else { } else {
it->derivedFrom[i].type = found; i.type = found;
} }
} }
} }
@ -842,7 +842,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
Scope *scope = &(*it); Scope *scope = &(*it);
if (!scope->definedType) { if (!scope->definedType) {
mBlankTypes.push_back(Type()); mBlankTypes.emplace_back();
scope->definedType = &mBlankTypes.back(); scope->definedType = &mBlankTypes.back();
} }
@ -3344,8 +3344,8 @@ const Function *Function::getOverriddenFunction(bool *foundAllBaseClasses) const
const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType, bool *foundAllBaseClasses) const const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType, bool *foundAllBaseClasses) const
{ {
// check each base class // check each base class
for (std::size_t i = 0; i < baseType->derivedFrom.size(); ++i) { for (const ::Type::BaseInfo & i : baseType->derivedFrom) {
const ::Type* derivedFromType = baseType->derivedFrom[i].type; const ::Type* derivedFromType = i.type;
// check if base class exists in database // check if base class exists in database
if (!derivedFromType || !derivedFromType->classScope) { if (!derivedFromType || !derivedFromType->classScope) {
if (foundAllBaseClasses) if (foundAllBaseClasses)

View File

@ -3420,7 +3420,7 @@ void TemplateSimplifier::printOut(const std::string & text) const
unsigned int decl1Index = 0; unsigned int decl1Index = 0;
for (const auto & decl1 : mTemplateDeclarations) { for (const auto & decl1 : mTemplateDeclarations) {
if (decl1.isSpecialization() && mapItem.first == decl1.token()) { if (decl1.isSpecialization() && mapItem.first == decl1.token()) {
bool found = 0; bool found = false;
unsigned int decl2Index = 0; unsigned int decl2Index = 0;
for (const auto & decl2 : mTemplateDeclarations) { for (const auto & decl2 : mTemplateDeclarations) {
if (mapItem.second == decl2.token()) { if (mapItem.second == decl2.token()) {
@ -3455,7 +3455,7 @@ void TemplateSimplifier::printOut(const std::string & text) const
unsigned int decl1Index = 0; unsigned int decl1Index = 0;
for (const auto & decl1 : mTemplateDeclarations) { for (const auto & decl1 : mTemplateDeclarations) {
if (mapItem.first == decl1.token()) { if (mapItem.first == decl1.token()) {
bool found = 0; bool found = false;
unsigned int decl2Index = 0; unsigned int decl2Index = 0;
for (const auto & decl2 : mTemplateDeclarations) { for (const auto & decl2 : mTemplateDeclarations) {
if (mapItem.second == decl2.token()) { if (mapItem.second == decl2.token()) {

View File

@ -1016,7 +1016,7 @@ void Token::insertToken(const std::string &tokenStr, const std::string &original
if (mImpl->mScopeInfo) { if (mImpl->mScopeInfo) {
// If the brace is immediately closed there is no point opening a new scope for it // If the brace is immediately closed there is no point opening a new scope for it
if (tokenStr == "{") { if (tokenStr == "{") {
std::string nextScopeNameAddition = ""; std::string nextScopeNameAddition;
// This might be the opening of a member function // This might be the opening of a member function
Token *tok1 = newToken; Token *tok1 = newToken;
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept")) while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))

View File

@ -867,7 +867,7 @@ void Tokenizer::simplifyTypedef()
if (tokOffset->next()->str() == "(") if (tokOffset->next()->str() == "(")
tokOffset = tokOffset->next(); tokOffset = tokOffset->next();
else if (Token::simpleMatch(tokOffset, "( * (")) { else if (Token::simpleMatch(tokOffset, "( * (")) {
pointers.push_back("*"); pointers.emplace_back("*");
tokOffset = tokOffset->tokAt(2); tokOffset = tokOffset->tokAt(2);
} }
@ -2837,7 +2837,7 @@ void Tokenizer::calculateScopes()
for (auto tok = list.front(); tok; tok = tok->next()) for (auto tok = list.front(); tok; tok = tok->next())
tok->scopeInfo(nullptr); tok->scopeInfo(nullptr);
std::string nextScopeNameAddition = ""; std::string nextScopeNameAddition;
std::shared_ptr<ScopeInfo2> primaryScope = std::make_shared<ScopeInfo2>("", nullptr); std::shared_ptr<ScopeInfo2> primaryScope = std::make_shared<ScopeInfo2>("", nullptr);
list.front()->scopeInfo(primaryScope); list.front()->scopeInfo(primaryScope);
@ -2847,7 +2847,7 @@ void Tokenizer::calculateScopes()
tok->scopeInfo(tok->previous()->scopeInfo()); tok->scopeInfo(tok->previous()->scopeInfo());
if (Token::Match(tok, "using namespace %name% ::|<|;")) { if (Token::Match(tok, "using namespace %name% ::|<|;")) {
std::string usingNamespaceName = ""; std::string usingNamespaceName;
for (const Token* namespaceNameToken = tok->tokAt(2); for (const Token* namespaceNameToken = tok->tokAt(2);
!Token::simpleMatch(namespaceNameToken, ";"); !Token::simpleMatch(namespaceNameToken, ";");
namespaceNameToken = namespaceNameToken->next()) { namespaceNameToken = namespaceNameToken->next()) {
@ -7993,7 +7993,6 @@ bool Tokenizer::simplifyRedundantParentheses()
tok->deleteNext(); tok->deleteNext();
tok2->deleteThis(); tok2->deleteThis();
ret = true; ret = true;
continue;
} }
if (Token::simpleMatch(tok->previous(), "? (") && Token::simpleMatch(tok->link(), ") :")) { if (Token::simpleMatch(tok->previous(), "? (") && Token::simpleMatch(tok->link(), ") :")) {

View File

@ -38,7 +38,7 @@ private:
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("warning"); settings.addEnabled("warning");
settings.addEnabled("portability"); settings.addEnabled("portability");
settings.libraries.push_back("posix"); settings.libraries.emplace_back("posix");
settings.standards.c = Standards::C11; settings.standards.c = Standards::C11;
settings.standards.cpp = Standards::CPP11; settings.standards.cpp = Standards::CPP11;
LOAD_LIB_2(settings.library, "std.cfg"); LOAD_LIB_2(settings.library, "std.cfg");

View File

@ -704,7 +704,7 @@ private:
ASSERT_EQUALS(false, MathLib::isIntHex("")); ASSERT_EQUALS(false, MathLib::isIntHex(""));
} }
void isValidIntegerSuffix(void) const { void isValidIntegerSuffix() const {
// negative testing // negative testing
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("")); ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix(""));
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("ux")); ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("ux"));
@ -889,7 +889,7 @@ private:
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142) ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142)
} }
void isdec(void) const { void isdec() const {
// positive testing // positive testing
ASSERT_EQUALS(true, MathLib::isDec("1")); ASSERT_EQUALS(true, MathLib::isDec("1"));
ASSERT_EQUALS(true, MathLib::isDec("+1")); ASSERT_EQUALS(true, MathLib::isDec("+1"));

View File

@ -2066,7 +2066,7 @@ private:
void run() OVERRIDE { void run() OVERRIDE {
settings.inconclusive = true; settings.inconclusive = true;
settings.libraries.push_back("posix"); settings.libraries.emplace_back("posix");
settings.addEnabled("warning"); settings.addEnabled("warning");
LOAD_LIB_2(settings.library, "std.cfg"); LOAD_LIB_2(settings.library, "std.cfg");

View File

@ -235,7 +235,7 @@ private:
TEST_CASE(unusedVariableValueTemplate); // #8994 TEST_CASE(unusedVariableValueTemplate); // #8994
} }
void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = 0) { void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
@ -305,7 +305,7 @@ private:
void checkposix(const char code[]) { void checkposix(const char code[]) {
static Settings settings; static Settings settings;
settings.addEnabled("warning"); settings.addEnabled("warning");
settings.libraries.push_back("posix"); settings.libraries.emplace_back("posix");
check(code, check(code,
nullptr, // filename nullptr, // filename

View File

@ -509,7 +509,7 @@ private:
settings.addEnabled("style"); settings.addEnabled("style");
settings.inlineSuppressions = true; settings.inlineSuppressions = true;
settings.relativePaths = true; settings.relativePaths = true;
settings.basePaths.push_back("/somewhere"); settings.basePaths.emplace_back("/somewhere");
const char code[] = const char code[] =
"struct Point\n" "struct Point\n"
"{\n" "{\n"

View File

@ -833,14 +833,14 @@ private:
void isStandardType() const { void isStandardType() const {
std::vector<std::string> standard_types; std::vector<std::string> standard_types;
standard_types.push_back("bool"); standard_types.emplace_back("bool");
standard_types.push_back("char"); standard_types.emplace_back("char");
standard_types.push_back("short"); standard_types.emplace_back("short");
standard_types.push_back("int"); standard_types.emplace_back("int");
standard_types.push_back("long"); standard_types.emplace_back("long");
standard_types.push_back("float"); standard_types.emplace_back("float");
standard_types.push_back("double"); standard_types.emplace_back("double");
standard_types.push_back("size_t"); standard_types.emplace_back("size_t");
std::vector<std::string>::const_iterator test_op, test_ops_end = standard_types.end(); std::vector<std::string>::const_iterator test_op, test_ops_end = standard_types.end();
for (test_op = standard_types.begin(); test_op != test_ops_end; ++test_op) { for (test_op = standard_types.begin(); test_op != test_ops_end; ++test_op) {

View File

@ -489,7 +489,7 @@ private:
// filter out ValueFlow messages.. // filter out ValueFlow messages..
const std::string debugwarnings = errout.str(); const std::string debugwarnings = errout.str();
errout.str(""); errout.str("");
std::istringstream istr2(debugwarnings.c_str()); std::istringstream istr2(debugwarnings);
std::string line; std::string line;
while (std::getline(istr2,line)) { while (std::getline(istr2,line)) {
if (line.find("valueflow.cpp") == std::string::npos) if (line.find("valueflow.cpp") == std::string::npos)
@ -519,7 +519,7 @@ private:
// filter out ValueFlow messages.. // filter out ValueFlow messages..
const std::string debugwarnings = errout.str(); const std::string debugwarnings = errout.str();
errout.str(""); errout.str("");
std::istringstream istr2(debugwarnings.c_str()); std::istringstream istr2(debugwarnings);
std::string line; std::string line;
while (std::getline(istr2,line)) { while (std::getline(istr2,line)) {
if (line.find("valueflow.cpp") == std::string::npos) if (line.find("valueflow.cpp") == std::string::npos)