diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 73d2f74f8..3ce615dc8 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -294,7 +294,7 @@ unsigned int ThreadExecutor::check() oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat); std::list locations; - locations.push_back(ErrorLogger::ErrorMessage::FileLocation(childname, 0)); + locations.emplace_back(childname, 0); const ErrorLogger::ErrorMessage errmsg(locations, emptyString, Severity::error, diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index bda60a38d..81cd343bc 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -90,7 +90,7 @@ static bool skipAnalysis(const std::string &analyzerInfoFile, unsigned long long for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) { if (std::strcmp(e->Name(), "error") == 0) - errors->push_back(ErrorLogger::ErrorMessage(e)); + errors->emplace_back(e); } return true; diff --git a/lib/check.h b/lib/check.h index ef07a07d6..c75429f55 100644 --- a/lib/check.h +++ b/lib/check.h @@ -162,16 +162,16 @@ protected: ErrorPath getErrorPath(const Token *errtok, const ValueFlow::Value *value, const std::string &bug) const { ErrorPath errorPath; if (!value) { - errorPath.push_back(ErrorPathItem(errtok,bug)); + errorPath.emplace_back(errtok,bug); } else if (_settings->verbose || _settings->xml || _settings->outputFormat == "daca2") { errorPath = value->errorPath; - errorPath.push_back(ErrorPathItem(errtok,bug)); + errorPath.emplace_back(errtok,bug); } else { if (value->condition) - errorPath.push_back(ErrorPathItem(value->condition, "condition '" + value->condition->expressionString() + "'")); + errorPath.emplace_back(value->condition, "condition '" + value->condition->expressionString() + "'"); //else if (!value->isKnown() || value->defaultArg) // errorPath = value->callstack; - errorPath.push_back(ErrorPathItem(errtok,bug)); + errorPath.emplace_back(errtok,bug); } return errorPath; } diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 93a0951ed..4deed3817 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -103,14 +103,14 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra std::string nr; if (index.size() > 1U) nr = "(" + MathLib::toString(i + 1) + getOrdinalText(i + 1) + " array index) "; - errorPath.push_back(ErrorPathItem(it->first, nr + info)); + errorPath.emplace_back(it->first, nr + info); } } - errorPath.push_back(ErrorPathItem(tok,"Array index out of bounds")); + errorPath.emplace_back(tok,"Array index out of bounds"); } else { - errorPath.push_back(ErrorPathItem(tok, "Array index out of bounds")); + errorPath.emplace_back(tok, "Array index out of bounds"); if (condition) - errorPath.push_back(ErrorPathItem(condition, "Assuming that condition '" + condition->expressionString() + "' is not redundant")); + errorPath.emplace_back(condition, "Assuming that condition '" + condition->expressionString() + "' is not redundant"); } if (condition != nullptr) { diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 15bc46264..57517023e 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2115,13 +2115,13 @@ void CheckClass::initializerListOrder() if (Token::Match(tok, "%name% (|{")) { const Variable *var = scope->getVariable(tok->str()); if (var) - vars.push_back(VarInfo(var, tok)); + vars.emplace_back(var, tok); if (Token::Match(tok->tokAt(2), "%name% =")) { var = scope->getVariable(tok->strAt(2)); if (var) - vars.push_back(VarInfo(var, tok->tokAt(2))); + vars.emplace_back(var, tok->tokAt(2)); } tok = tok->next()->link()->next(); } else @@ -2303,7 +2303,7 @@ void CheckClass::virtualFunctionCallInConstructorError( ErrorPath errorPath; int lineNumber = 1; for (std::list::const_iterator it = tokStack.begin(); it != tokStack.end(); ++it) - errorPath.push_back(ErrorPathItem(*it, "Calling " + (*it)->str())); + errorPath.emplace_back(*it, "Calling " + (*it)->str()); if (!errorPath.empty()) { lineNumber = errorPath.front().first->linenr(); errorPath.back().second = funcname + " is a virtual method"; @@ -2337,7 +2337,7 @@ void CheckClass::pureVirtualFunctionCallInConstructorError( ErrorPath errorPath; for (std::list::const_iterator it = tokStack.begin(); it != tokStack.end(); ++it) - errorPath.push_back(ErrorPathItem(*it, "Calling " + (*it)->str())); + errorPath.emplace_back(*it, "Calling " + (*it)->str()); if (!errorPath.empty()) errorPath.back().second = purefuncname + " is a pure virtual method without body"; diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5a716d064..cd269709a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -354,9 +354,9 @@ void CheckOther::invalidPointerCast() if (toType->isIntegral() && fromType->isIntegral()) continue; std::string toStr = toType->isIntegral() ? "integer *" : toType->str(); - toStr = toStr.substr(0, toStr.size()-2); + toStr.erase(toStr.size()-2); std::string fromStr = fromType->isIntegral() ? "integer *" : fromType->str(); - fromStr = fromStr.substr(0, fromStr.size() - 2); + fromStr.erase(fromStr.size() - 2); invalidPointerCastError(tok, fromStr, toStr, toType->type == ValueType::Type::CHAR); } @@ -1829,7 +1829,7 @@ void CheckOther::checkInvalidFree() // Keep track of which variables were assigned addresses to newly-allocated memory if (Token::Match(tok, "%var% = malloc|g_malloc|new")) { - allocatedVariables.insert(std::make_pair(tok->varId(), false)); + allocatedVariables.emplace(tok->varId(), false); } // If a previously-allocated pointer is incremented or decremented, any subsequent diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f013c2cfc..b5cae2a8f 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1069,16 +1069,16 @@ void CheckStl::string_c_str() for (std::list::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { for (std::list::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { if (c_strFuncParam.erase(func->tokenDef->str()) != 0) { // Check if function with this name was already found - c_strFuncParam.insert(std::make_pair(func->tokenDef->str(), 0)); // Disable, because there are overloads. TODO: Handle overloads + c_strFuncParam.emplace(func->tokenDef->str(), 0); // Disable, because there are overloads. TODO: Handle overloads continue; } unsigned int numpar = 0; - c_strFuncParam.insert(std::make_pair(func->tokenDef->str(), numpar)); // Insert function as dummy, to indicate that there is at least one function with that name + c_strFuncParam.emplace(func->tokenDef->str(), numpar); // Insert function as dummy, to indicate that there is at least one function with that name for (std::list::const_iterator var = func->argumentList.cbegin(); var != func->argumentList.cend(); ++var) { numpar++; if (var->isStlStringType() && (!var->isReference() || var->isConst())) - c_strFuncParam.insert(std::make_pair(func->tokenDef->str(), numpar)); + c_strFuncParam.emplace(func->tokenDef->str(), numpar); } } } diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index f1c20aed0..b52270c30 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -68,7 +68,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi if (tokenizer.isCPP() && func->retDef->str() == "template") continue; - _functionDecl.push_back(FunctionDecl(func)); + _functionDecl.emplace_back(func); FunctionUsage &usage = _functions[func->name()]; diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 7b440f25b..4735474a9 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -247,7 +247,7 @@ void Variables::addVar(const Variable *var, { if (var->declarationId() > 0) { _varAddedInScope.back().insert(var->declarationId()); - _varUsage.insert(std::make_pair(var->declarationId(), VariableUsage(var, type, false, write_, false))); + _varUsage.emplace(var->declarationId(), VariableUsage(var, type, false, write_, false)); } } @@ -382,8 +382,8 @@ Variables::VariableUsage *Variables::find(unsigned int varid) void Variables::enterScope() { - _varAddedInScope.push_back(std::set()); - _varReadInScope.push_back(std::set()); + _varAddedInScope.emplace_back(); + _varReadInScope.emplace_back(); } void Variables::leaveScope(bool insideLoop) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index a65bddd6d..23caeb2a2 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -89,7 +89,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list& callstack if (!(*it)) continue; - _callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(*it, list)); + _callStack.emplace_back(*it, list); } if (list && !list->getFiles().empty()) @@ -108,7 +108,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list& callstack if (!(*it)) continue; - _callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(*it, list)); + _callStack.emplace_back(*it, list); } if (list && !list->getFiles().empty()) @@ -127,7 +127,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenL // --errorlist can provide null values here if (tok) - _callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(tok, info, tokenList)); + _callStack.emplace_back(tok, info, tokenList); } if (tokenList && !tokenList->getFiles().empty()) @@ -170,7 +170,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errms const char *file = strfile ? strfile : unknown; const char *info = strinfo ? strinfo : ""; const int line = strline ? std::atoi(strline) : 0; - _callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(file, info, line)); + _callStack.emplace_back(file, info, line); } } } @@ -537,7 +537,7 @@ void ErrorLogger::reportUnmatchedSuppressions(const std::list callStack; if (!i->fileName.empty()) - callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->fileName, i->lineNumber)); + callStack.emplace_back(i->fileName, i->lineNumber); reportErr(ErrorLogger::ErrorMessage(callStack, emptyString, Severity::information, "Unmatched suppression: " + i->errorId, "unmatchedSuppression", false)); } } diff --git a/lib/importproject.cpp b/lib/importproject.cpp index f3aee718e..998275245 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -481,7 +481,7 @@ static void loadVisualStudioProperties(const std::string &props, std::mapName(),"PropertyGroup")==0) { importPropertyGroup(node, variables, includePath, nullptr); } else if (std::strcmp(node->Name(),"ItemDefinitionGroup")==0) { - itemDefinitionGroupList.push_back(ItemDefinitionGroup(node, additionalIncludeDirectories)); + itemDefinitionGroupList.emplace_back(node, additionalIncludeDirectories); } } } @@ -512,7 +512,7 @@ void ImportProject::importVcxproj(const std::string &filename, std::mapName(), "ProjectConfiguration") == 0) { const ProjectConfiguration p(cfg); if (p.platform != ProjectConfiguration::Unknown) - projectConfigurationList.push_back(ProjectConfiguration(cfg)); + projectConfigurationList.emplace_back(cfg); } } } else { @@ -525,7 +525,7 @@ void ImportProject::importVcxproj(const std::string &filename, std::mapName(), "ItemDefinitionGroup") == 0) { - itemDefinitionGroupList.push_back(ItemDefinitionGroup(node, additionalIncludeDirectories)); + itemDefinitionGroupList.emplace_back(node, additionalIncludeDirectories); } else if (std::strcmp(node->Name(), "PropertyGroup") == 0) { importPropertyGroup(node, &variables, &includePath, &useOfMfc); } else if (std::strcmp(node->Name(), "ImportGroup") == 0) { diff --git a/lib/library.cpp b/lib/library.cpp index 16e6642ef..045b6fffd 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -36,7 +36,7 @@ static std::vector getnames(const char *names) { std::vector ret; while (const char *p = std::strchr(names,',')) { - ret.push_back(std::string(names, p-names)); + ret.emplace_back(names, p-names); names = p + 1; } ret.push_back(names); @@ -626,7 +626,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co return Error(BAD_ATTRIBUTE_VALUE, argattr); ac.minsizes.reserve(type == ArgumentChecks::MinSize::MUL ? 2 : 1); - ac.minsizes.push_back(ArgumentChecks::MinSize(type,argattr[0]-'0')); + ac.minsizes.emplace_back(type,argattr[0]-'0'); if (type == ArgumentChecks::MinSize::MUL) { const char *arg2attr = argnode->Attribute("arg2"); if (!arg2attr) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e87d8e3e5..b02f751f2 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -424,13 +424,11 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set std::set Preprocessor::getConfigs(const simplecpp::TokenList &tokens) const { - std::set ret; - ret.insert(""); + std::set ret = { "" }; if (!tokens.cfront()) return ret; - std::set defined; - defined.insert("__cplusplus"); + std::set defined = { "__cplusplus" }; ::getConfigs(tokens, defined, _settings.userDefines, _settings.userUndefs, ret); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 1c326eda1..7139cdf1b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -67,7 +67,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti void SymbolDatabase::createSymbolDatabaseFindAllScopes() { // create global scope - scopeList.push_back(Scope(this, nullptr, nullptr)); + scopeList.emplace_back(this, nullptr, nullptr); // pointer to current scope Scope *scope = &scopeList.back(); @@ -169,7 +169,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() scope = new_scope; tok = tok2; } else { - scopeList.push_back(Scope(this, tok, scope)); + scopeList.emplace_back(this, tok, scope); new_scope = &scopeList.back(); if (tok->str() == "class") @@ -181,7 +181,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() if (new_scope->isClassOrStructOrUnion() || new_scope->type == Scope::eEnum) { Type* new_type = findType(tok->next(), scope); if (!new_type) { - typeList.push_back(Type(new_scope->classDef, new_scope, scope)); + typeList.emplace_back(new_scope->classDef, new_scope, scope); new_type = &typeList.back(); scope->definedTypesMap[new_type->name()] = new_type; } else @@ -232,7 +232,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() Token::Match(tok, "namespace %name% %type% (") && tok->tokAt(2)->isUpperCaseName() && Token::simpleMatch(tok->linkAt(3), ") {")) { - scopeList.push_back(Scope(this, tok, scope)); + scopeList.emplace_back(this, tok, scope); Scope *new_scope = &scopeList.back(); access[new_scope] = Public; @@ -260,7 +260,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() tok->strAt(-1) != "friend") { if (!findType(tok->next(), scope)) { // fill typeList.. - typeList.push_back(Type(tok, nullptr, scope)); + typeList.emplace_back(tok, nullptr, scope); Type* new_type = &typeList.back(); scope->definedTypesMap[new_type->name()] = new_type; } @@ -291,7 +291,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() else if (_tokenizer->isCPP() && Token::Match(tok, "using %name% =")) { if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) { // fill typeList.. - typeList.push_back(Type(tok, nullptr, scope)); + typeList.emplace_back(tok, nullptr, scope); Type* new_type = &typeList.back(); scope->definedTypesMap[new_type->name()] = new_type; } @@ -305,7 +305,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // unnamed struct and union else if (Token::Match(tok, "struct|union {") && Token::Match(tok->next()->link(), "} *|&| %name% ;|[")) { - scopeList.push_back(Scope(this, tok, scope)); + scopeList.emplace_back(this, tok, scope); Scope *new_scope = &scopeList.back(); access[new_scope] = Public; @@ -317,7 +317,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() varNameTok = varNameTok->next(); } - typeList.push_back(Type(tok, new_scope, scope)); + typeList.emplace_back(tok, new_scope, scope); { Type* new_type = &typeList.back(); new_scope->definedType = new_type; @@ -348,7 +348,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() else if ((Token::Match(tok, "struct|union {") && Token::simpleMatch(tok->next()->link(), "} ;")) || Token::simpleMatch(tok, "namespace {")) { - scopeList.push_back(Scope(this, tok, scope)); + scopeList.emplace_back(this, tok, scope); Scope *new_scope = &scopeList.back(); access[new_scope] = Public; @@ -358,7 +358,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() new_scope->classStart = tok2; new_scope->classEnd = tok2->link(); - typeList.push_back(Type(tok, new_scope, scope)); + typeList.emplace_back(tok, new_scope, scope); { Type* new_type = &typeList.back(); new_scope->definedType = new_type; @@ -380,7 +380,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // forward declared enum else if (Token::Match(tok, "enum class| %name% ;") || Token::Match(tok, "enum class| %name% : %name% ;")) { - typeList.push_back(Type(tok, nullptr, scope)); + typeList.emplace_back(tok, nullptr, scope); Type* new_type = &typeList.back(); scope->definedTypesMap[new_type->name()] = new_type; tok = tok->tokAt(2); @@ -801,11 +801,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() if (Token::Match(tok, "else|try|do {")) { const Token* tok1 = tok->next(); if (tok->str() == "else") - scopeList.push_back(Scope(this, tok, scope, Scope::eElse, tok1)); + scopeList.emplace_back(this, tok, scope, Scope::eElse, tok1); else if (tok->str() == "do") - scopeList.push_back(Scope(this, tok, scope, Scope::eDo, tok1)); + scopeList.emplace_back(this, tok, scope, Scope::eDo, tok1); else //if (tok->str() == "try") - scopeList.push_back(Scope(this, tok, scope, Scope::eTry, tok1)); + scopeList.emplace_back(this, tok, scope, Scope::eTry, tok1); tok = tok1; scope->nestedList.push_back(&scopeList.back()); @@ -813,15 +813,15 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } else if (Token::Match(tok, "if|for|while|catch|switch (") && Token::simpleMatch(tok->next()->link(), ") {")) { const Token *scopeStartTok = tok->next()->link()->next(); if (tok->str() == "if") - scopeList.push_back(Scope(this, tok, scope, Scope::eIf, scopeStartTok)); + scopeList.emplace_back(this, tok, scope, Scope::eIf, scopeStartTok); else if (tok->str() == "for") { - scopeList.push_back(Scope(this, tok, scope, Scope::eFor, scopeStartTok)); + scopeList.emplace_back(this, tok, scope, Scope::eFor, scopeStartTok); } else if (tok->str() == "while") - scopeList.push_back(Scope(this, tok, scope, Scope::eWhile, scopeStartTok)); + scopeList.emplace_back(this, tok, scope, Scope::eWhile, scopeStartTok); else if (tok->str() == "catch") { - scopeList.push_back(Scope(this, tok, scope, Scope::eCatch, scopeStartTok)); + scopeList.emplace_back(this, tok, scope, Scope::eCatch, scopeStartTok); } else // if (tok->str() == "switch") - scopeList.push_back(Scope(this, tok, scope, Scope::eSwitch, scopeStartTok)); + scopeList.emplace_back(this, tok, scope, Scope::eSwitch, scopeStartTok); scope->nestedList.push_back(&scopeList.back()); scope = &scopeList.back(); @@ -841,11 +841,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() tok2 = nullptr; // No lambda if (tok2 && tok2->str() == ")" && tok2->link()->strAt(-1) == "]") { - scopeList.push_back(Scope(this, tok2->link()->linkAt(-1), scope, Scope::eLambda, tok)); + scopeList.emplace_back(this, tok2->link()->linkAt(-1), scope, Scope::eLambda, tok); scope->nestedList.push_back(&scopeList.back()); scope = &scopeList.back(); } else if (!Token::Match(tok->previous(), "=|,|(|return") && !(tok->strAt(-1) == ")" && Token::Match(tok->linkAt(-1)->previous(), "=|,|(|return"))) { - scopeList.push_back(Scope(this, tok, scope, Scope::eUnconditional, tok)); + scopeList.emplace_back(this, tok, scope, Scope::eUnconditional, tok); scope->nestedList.push_back(&scopeList.back()); scope = &scopeList.back(); } else { @@ -2288,7 +2288,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok) { const Token *tok1 = *tok; - scopeList.push_back(Scope(this, tok1, *scope)); + scopeList.emplace_back(this, tok1, *scope); Scope *newScope = &scopeList.back(); // find start of function '{' @@ -3163,7 +3163,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s while (Token::Match(startTok, "enum|struct|const")) startTok = startTok->next(); - argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, argType, functionScope, &symbolDatabase->_settings->library)); + argumentList.emplace_back(nameTok, startTok, endTok, count++, Argument, argType, functionScope, &symbolDatabase->_settings->library); if (tok->str() == ")") { // check for a variadic function diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 06b61adbe..fd22a08c1 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -993,9 +993,9 @@ public: void addVariable(const Token *token_, const Token *start_, const Token *end_, AccessControl access_, const Type *type_, const Scope *scope_, const Library* lib) { - varlist.push_back(Variable(token_, start_, end_, varlist.size(), - access_, - type_, scope_, lib)); + varlist.emplace_back(token_, start_, end_, varlist.size(), + access_, + type_, scope_, lib); } /** @brief initialize varlist */ @@ -1008,7 +1008,7 @@ public: const Function * back = &functionList.back(); - functionMap.insert(make_pair(back->tokenDef->str(), back)); + functionMap.emplace(back->tokenDef->str(), back); } bool hasDefaultConstructor() const; diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 6aebb7713..6507dd466 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -483,7 +483,7 @@ static void setScopeInfo(const Token *tok, std::list *scopeInfo) // ... } if (tok && tok->str() == "{") { - scopeInfo->push_back(ScopeInfo2(classname,tok->link())); + scopeInfo->emplace_back(classname,tok->link()); } } @@ -515,7 +515,7 @@ std::list TemplateSimplifier::getTemplateDecla else if (tok2->str() == "{") { const int namepos = getTemplateNamePosition(parmEnd); if (namepos > 0) - declarations.push_back(TokenAndName(tok, getScopeName(scopeInfo), getFullName(scopeInfo, parmEnd->strAt(namepos)))); + declarations.emplace_back(tok, getScopeName(scopeInfo), getFullName(scopeInfo, parmEnd->strAt(namepos))); break; } } @@ -563,7 +563,7 @@ std::list TemplateSimplifier::getTemplateInsta for (; tok2 && tok2 != tok; tok2 = tok2->previous()) { if (Token::Match(tok2, ", %name% <") && TemplateSimplifier::templateParameters(tok2->tokAt(2))) { - instantiations.push_back(TokenAndName(tok2->next(), getScopeName(scopeList), getFullName(scopeList, tok2->strAt(1)))); + instantiations.emplace_back(tok2->next(), getScopeName(scopeList), getFullName(scopeList, tok2->strAt(1))); } } @@ -574,11 +574,11 @@ std::list TemplateSimplifier::getTemplateInsta const std::string fullName = scopeName + (scopeName.empty()?"":" :: ") + tok->str(); const std::list::const_iterator it = std::find_if(declarations.begin(), declarations.end(), FindName(fullName)); if (it != declarations.end()) { - instantiations.push_back(TokenAndName(tok, getScopeName(scopeList), fullName)); + instantiations.emplace_back(tok, getScopeName(scopeList), fullName); break; } else { if (scopeName.empty()) { - instantiations.push_back(TokenAndName(tok, getScopeName(scopeList), scopeName1 + (scopeName1.empty()?"":" :: ") + tok->str())); + instantiations.emplace_back(tok, getScopeName(scopeList), scopeName1 + (scopeName1.empty()?"":" :: ") + tok->str()); break; } const std::string::size_type pos = scopeName.rfind(" :: "); @@ -781,7 +781,7 @@ void TemplateSimplifier::simplifyTemplateAliases(std::listnext(); } - args.push_back(std::pair(start, tok2)); + args.emplace_back(start, tok2); if (tok2 && tok2->str() == ",") { tok2 = tok2->next(); } else { @@ -813,7 +813,7 @@ void TemplateSimplifier::simplifyTemplateAliases(std::listend(), FindToken(tok1)); if (it != templateInstantiations->end()) - templateInstantiations->push_back(TokenAndName(tok2, it->scope, it->name)); + templateInstantiations->emplace_back(tok2, it->scope, it->name); } continue; } @@ -1075,7 +1075,7 @@ void TemplateSimplifier::expandTemplate( std::string name = tok3->str(); for (const Token *prev = tok3->tokAt(-2); Token::Match(prev, "%name% ::"); prev = prev->tokAt(-2)) name = prev->str() + " :: " + name; - templateInstantiations.push_back(TokenAndName(tokenlist.back(), getScopeName(scopeInfo), getFullName(scopeInfo, name))); + templateInstantiations.emplace_back(tokenlist.back(), getScopeName(scopeInfo), getFullName(scopeInfo, name)); } // link() newly tokens manually @@ -1719,7 +1719,7 @@ void TemplateSimplifier::replaceTemplateUsage(Token * const instantiationToken, } } } - removeTokens.push_back(std::pair(nameTok, tok2->next())); + removeTokens.emplace_back(nameTok, tok2->next()); } nameTok = tok2; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2f481d580..7cb23053b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2602,7 +2602,7 @@ void Tokenizer::setVarIdPass1() variableId.swap(scopeInfo.top()); scopeInfo.pop(); } else if (tok->str() == "{") - scopeStack.push(VarIdScopeInfo(true, scopeStack.top().isStructInit || tok->strAt(-1) == "=", /*isEnum=*/false, _varId)); + scopeStack.emplace(true, scopeStack.top().isStructInit || tok->strAt(-1) == "=", /*isEnum=*/false, _varId); } else if (!initlist && tok->str()=="(") { const Token * newFunctionDeclEnd = nullptr; if (!scopeStack.top().isExecutable) @@ -2638,7 +2638,7 @@ void Tokenizer::setVarIdPass1() scopeInfo.push(variableId); } initlist = false; - scopeStack.push(VarIdScopeInfo(isExecutable, scopeStack.top().isStructInit || tok->strAt(-1) == "=", isEnumStart(tok), _varId)); + scopeStack.emplace(isExecutable, scopeStack.top().isStructInit || tok->strAt(-1) == "=", isEnumStart(tok), _varId); } else { /* if (tok->str() == "}") */ bool isNamespace = false; for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous()) { @@ -3004,9 +3004,9 @@ void Tokenizer::setVarIdPass2() if (!tok->next()) syntaxError(tok); if (Token::Match(tok, "%name% (")) - allMemberFunctions.push_back(Member(scope, usingnamespaces, tok1)); + allMemberFunctions.emplace_back(scope, usingnamespaces, tok1); else - allMemberVars.push_back(Member(scope, usingnamespaces, tok1)); + allMemberVars.emplace_back(scope, usingnamespaces, tok1); } } @@ -3055,7 +3055,7 @@ void Tokenizer::setVarIdPass2() // What member variables are there in this class? for (std::list::const_iterator it = classnameTokens.begin(); it != classnameTokens.end(); ++it) - scopeInfo.push_back(ScopeInfo2((*it)->str(), tokStart->link())); + scopeInfo.emplace_back((*it)->str(), tokStart->link()); for (Token *tok2 = tokStart->next(); tok2 && tok2 != tokStart->link(); tok2 = tok2->next()) { // skip parentheses.. @@ -9945,7 +9945,7 @@ void Tokenizer::printUnknownTypes() const } } - unknowns.insert(std::pair(name, nameTok)); + unknowns.emplace(name, nameTok); } } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 2c456b192..37b77a374 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1098,7 +1098,7 @@ static void valueFlowReverse(TokenList *tokenlist, if (inc != 0) { val.intvalue += inc; const std::string info(tok2->str() + " is " + std::string(inc==1 ? "decremented" : "incremented") + ", before this " + (inc==1?"decrement":"increment") + " the value is " + val.infoString()); - val.errorPath.push_back(ErrorPathItem(tok2, info)); + val.errorPath.emplace_back(tok2, info); } // compound assignment @@ -1124,7 +1124,7 @@ static void valueFlowReverse(TokenList *tokenlist, } const std::string info("Compound assignment '" + assignToken->str() + "', before assignment value is " + val.infoString()); - val.errorPath.push_back(ErrorPathItem(tok2, info)); + val.errorPath.emplace_back(tok2, info); } // bailout: variable is used in rhs in assignment to itself @@ -1971,7 +1971,7 @@ static bool valueFlowForward(Token * const startToken, it = values.erase(it); } else { const std::string info("Compound assignment '" + assign + "', assigned value is " + it->infoString()); - it->errorPath.push_back(ErrorPathItem(tok2, info)); + it->errorPath.emplace_back(tok2, info); ++it; } @@ -2080,7 +2080,7 @@ static bool valueFlowForward(Token * const startToken, if (pre) setTokenValue(op, *it, settings); const std::string info(tok2->str() + " is " + std::string(inc ? "incremented" : "decremented") + "', new value is " + it->infoString()); - it->errorPath.push_back(ErrorPathItem(tok2, info)); + it->errorPath.emplace_back(tok2, info); } } @@ -2231,7 +2231,7 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab ValueFlow::Value value; value.valueType = ValueFlow::Value::MOVED; value.moveKind = ValueFlow::Value::NonMovedVariable; - value.errorPath.push_back(ErrorPathItem(tok, "Calling " + tok->next()->expressionString() + " makes " + tok->str() + " 'non-moved'")); + value.errorPath.emplace_back(tok, "Calling " + tok->next()->expressionString() + " makes " + tok->str() + " 'non-moved'"); value.setKnown(); std::list values; values.push_back(value); @@ -2269,9 +2269,9 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab value.valueType = ValueFlow::Value::MOVED; value.moveKind = moveKind; if (moveKind == ValueFlow::Value::MovedVariable) - value.errorPath.push_back(ErrorPathItem(tok, "Calling std::move(" + varTok->str() + ")")); + value.errorPath.emplace_back(tok, "Calling std::move(" + varTok->str() + ")"); else // if (moveKind == ValueFlow::Value::ForwardedVariable) - value.errorPath.push_back(ErrorPathItem(tok, "Calling std::forward(" + varTok->str() + ")")); + value.errorPath.emplace_back(tok, "Calling std::forward(" + varTok->str() + ")"); value.setKnown(); std::list values; values.push_back(value); @@ -2319,7 +2319,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat std::list values = tok->astOperand2()->values(); for (std::list::iterator it = values.begin(); it != values.end(); ++it) { const std::string info = "Assignment '" + tok->expressionString() + "', assigned value is " + it->infoString(); - it->errorPath.push_back(ErrorPathItem(tok->astOperand2(), info)); + it->errorPath.emplace_back(tok->astOperand2(), info); } const bool constValue = tok->astOperand2()->isNumber(); @@ -2441,21 +2441,21 @@ static void valueFlowAfterCondition(TokenList *tokenlist, SymbolDatabase* symbol std::list false_values; // TODO: We should add all known values if (numtok) { - false_values.push_back(ValueFlow::Value(tok, numtok->values().front().intvalue)); - true_values.push_back(ValueFlow::Value(tok, numtok->values().front().intvalue)); + false_values.emplace_back(tok, numtok->values().front().intvalue); + true_values.emplace_back(tok, numtok->values().front().intvalue); } else if (lowertok) { long long v = lowertok->values().front().intvalue; - true_values.push_back(ValueFlow::Value(tok, v+1)); - false_values.push_back(ValueFlow::Value(tok, v)); + true_values.emplace_back(tok, v+1); + false_values.emplace_back(tok, v); } else if (uppertok) { long long v = uppertok->values().front().intvalue; - true_values.push_back(ValueFlow::Value(tok, v-1)); - false_values.push_back(ValueFlow::Value(tok, v)); + true_values.emplace_back(tok, v-1); + false_values.emplace_back(tok, v); } else { - true_values.push_back(ValueFlow::Value(tok, 0LL)); - false_values.push_back(ValueFlow::Value(tok, 0LL)); + true_values.emplace_back(tok, 0LL); + false_values.emplace_back(tok, 0LL); } @@ -2965,8 +2965,8 @@ static void valueFlowForLoopSimplifyAfter(Token *fortok, unsigned int varid, con endToken = fortok->scope()->classEnd; std::list values; - values.push_back(ValueFlow::Value(num)); - values.back().errorPath.push_back(ErrorPathItem(fortok,"After for loop, " + var->name() + " has value " + values.back().infoString())); + values.emplace_back(num); + values.back().errorPath.emplace_back(fortok,"After for loop, " + var->name() + " has value " + values.back().infoString()); valueFlowForward(fortok->linkAt(1)->linkAt(1)->next(), endToken, @@ -3067,10 +3067,10 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol } if (Token::Match(tok, "case %num% :")) { std::list values; - values.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str()))); + values.emplace_back(MathLib::toLongNumber(tok->next()->str())); values.back().condition = tok; const std::string info("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here."); - values.back().errorPath.push_back(ErrorPathItem(tok, info)); + values.back().errorPath.emplace_back(tok, info); bool known = false; if ((Token::simpleMatch(tok->previous(), "{") || Token::simpleMatch(tok->tokAt(-2), "break ;")) && !Token::Match(tok->tokAt(3), ";| case")) known = true; @@ -3079,10 +3079,10 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol tok = tok->tokAt(3); if (!tok->isName()) tok = tok->next(); - values.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str()))); + values.emplace_back(MathLib::toLongNumber(tok->next()->str())); values.back().condition = tok; const std::string info2("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here."); - values.back().errorPath.push_back(ErrorPathItem(tok, info2)); + values.back().errorPath.emplace_back(tok, info2); } for (std::list::const_iterator val = values.begin(); val != values.end(); ++val) { valueFlowReverse(tokenlist, @@ -3196,8 +3196,8 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger, // passing value(s) to function std::list argvalues; if (Token::Match(argtok, "%comp%|%oror%|&&|!") && !argtok->hasKnownIntValue()) { - argvalues.push_back(ValueFlow::Value(0)); - argvalues.push_back(ValueFlow::Value(1)); + argvalues.emplace_back(0); + argvalues.emplace_back(1); } else { argvalues = argtok->values(); } @@ -3209,15 +3209,15 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger, for (std::list::iterator it = argvalues.begin(); it != argvalues.end(); ++it) { const std::string nr = MathLib::toString(argnr + 1) + getOrdinalText(argnr + 1); - it->errorPath.push_back(ErrorPathItem(argtok, - "Calling function '" + - calledFunction->name() + - "', " + - nr + - " argument '" + - argvar->name() + - "' value is " + - it->infoString())); + it->errorPath.emplace_back(argtok, + "Calling function '" + + calledFunction->name() + + "', " + + nr + + " argument '" + + argvar->name() + + "' value is " + + it->infoString()); } // passed values are not "known".. @@ -3382,7 +3382,7 @@ ValueFlow::Value::Value(const Token *c, long long val) defaultArg(false), valueKind(ValueKind::Possible) { - errorPath.push_back(ErrorPathItem(c, "Assuming that condition '" + c->expressionString() + "' is not redundant")); + errorPath.emplace_back(c, "Assuming that condition '" + c->expressionString() + "' is not redundant"); } std::string ValueFlow::Value::infoString() const diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 877e88650..fde974684 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -300,40 +300,40 @@ private: // suppress all unmatchedSuppression errout.str(""); suppressions.clear(); - suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U)); - suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "*", 0U)); + suppressions.emplace_back("abc", "a.c", 10U); + suppressions.emplace_back("unmatchedSuppression", "*", 0U); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("", errout.str()); // suppress all unmatchedSuppression in a.c errout.str(""); suppressions.clear(); - suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U)); - suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "a.c", 0U)); + suppressions.emplace_back("abc", "a.c", 10U); + suppressions.emplace_back("unmatchedSuppression", "a.c", 0U); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("", errout.str()); // suppress unmatchedSuppression in a.c at line 10 errout.str(""); suppressions.clear(); - suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U)); - suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "a.c", 10U)); + suppressions.emplace_back("abc", "a.c", 10U); + suppressions.emplace_back("unmatchedSuppression", "a.c", 10U); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("", errout.str()); // don't suppress unmatchedSuppression when file is mismatching errout.str(""); suppressions.clear(); - suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U)); - suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "b.c", 0U)); + suppressions.emplace_back("abc", "a.c", 10U); + suppressions.emplace_back("unmatchedSuppression", "b.c", 0U); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str()); // don't suppress unmatchedSuppression when line is mismatching errout.str(""); suppressions.clear(); - suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U)); - suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "a.c", 1U)); + suppressions.emplace_back("abc", "a.c", 10U); + suppressions.emplace_back("unmatchedSuppression", "a.c", 1U); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str()); }