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);
}
void CheckBool::returnValueOfFunctionReturningBool(void)
void CheckBool::returnValueOfFunctionReturningBool()
{
if (!mSettings->isEnabled(Settings::STYLE))
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) {
const char *include = e->Attribute("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) {
const char *filename = f->Attribute("FILENAME");
if (filename && Path::acceptFile(filename))
compileList.push_back(filename);
compileList.emplace_back(filename);
}
}
} 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);
names = p + 1;
}
ret.push_back(names);
ret.emplace_back(names);
return ret;
}
@ -96,7 +96,7 @@ Library::Error Library::load(const char exename[], const char path[])
std::list<std::string> cfgfolders;
#ifdef FILESDIR
cfgfolders.push_back(FILESDIR "/cfg");
cfgfolders.emplace_back(FILESDIR "/cfg");
#endif
if (exename) {
const std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(exename)));

View File

@ -134,7 +134,7 @@ std::string Path::getCurrentPath()
#ifndef _WIN32
if (getcwd(currentPath, 4096) != nullptr)
#else
if (_getcwd(currentPath, 4096) != 0)
if (_getcwd(currentPath, 4096) != nullptr)
#endif
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))
dui.defines.push_back("__cplusplus");
dui.defines.emplace_back("__cplusplus");
dui.undefined = mSettings.userUndefs; // -U
dui.includePaths = mSettings.includePaths; // -I

View File

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

View File

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

View File

@ -3420,7 +3420,7 @@ void TemplateSimplifier::printOut(const std::string & text) const
unsigned int decl1Index = 0;
for (const auto & decl1 : mTemplateDeclarations) {
if (decl1.isSpecialization() && mapItem.first == decl1.token()) {
bool found = 0;
bool found = false;
unsigned int decl2Index = 0;
for (const auto & decl2 : mTemplateDeclarations) {
if (mapItem.second == decl2.token()) {
@ -3455,7 +3455,7 @@ void TemplateSimplifier::printOut(const std::string & text) const
unsigned int decl1Index = 0;
for (const auto & decl1 : mTemplateDeclarations) {
if (mapItem.first == decl1.token()) {
bool found = 0;
bool found = false;
unsigned int decl2Index = 0;
for (const auto & decl2 : mTemplateDeclarations) {
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 the brace is immediately closed there is no point opening a new scope for it
if (tokenStr == "{") {
std::string nextScopeNameAddition = "";
std::string nextScopeNameAddition;
// This might be the opening of a member function
Token *tok1 = newToken;
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))

View File

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

View File

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

View File

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

View File

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

View File

@ -235,7 +235,7 @@ private:
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..
errout.str("");
@ -305,7 +305,7 @@ private:
void checkposix(const char code[]) {
static Settings settings;
settings.addEnabled("warning");
settings.libraries.push_back("posix");
settings.libraries.emplace_back("posix");
check(code,
nullptr, // filename

View File

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

View File

@ -833,14 +833,14 @@ private:
void isStandardType() const {
std::vector<std::string> standard_types;
standard_types.push_back("bool");
standard_types.push_back("char");
standard_types.push_back("short");
standard_types.push_back("int");
standard_types.push_back("long");
standard_types.push_back("float");
standard_types.push_back("double");
standard_types.push_back("size_t");
standard_types.emplace_back("bool");
standard_types.emplace_back("char");
standard_types.emplace_back("short");
standard_types.emplace_back("int");
standard_types.emplace_back("long");
standard_types.emplace_back("float");
standard_types.emplace_back("double");
standard_types.emplace_back("size_t");
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) {

View File

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