Refactorizations:

- Replace several push_back-calls by emplace_back
- Replace some x = x.substr(0, y) calls by x.erase(y)
This commit is contained in:
PKEuS 2018-04-11 09:44:35 +02:00
parent 8aa71d62a0
commit d2146844dd
19 changed files with 122 additions and 124 deletions

View File

@ -294,7 +294,7 @@ unsigned int ThreadExecutor::check()
oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat);
std::list<ErrorLogger::ErrorMessage::FileLocation> locations;
locations.push_back(ErrorLogger::ErrorMessage::FileLocation(childname, 0));
locations.emplace_back(childname, 0);
const ErrorLogger::ErrorMessage errmsg(locations,
emptyString,
Severity::error,

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {

View File

@ -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 Token *>::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 Token *>::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";

View File

@ -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

View File

@ -1069,16 +1069,16 @@ void CheckStl::string_c_str()
for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
for (std::list<Function>::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<Variable>::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);
}
}
}

View File

@ -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()];

View File

@ -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<unsigned int>());
_varReadInScope.push_back(std::set<unsigned int>());
_varAddedInScope.emplace_back();
_varReadInScope.emplace_back();
}
void Variables::leaveScope(bool insideLoop)

View File

@ -89,7 +89,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& 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<const Token*>& 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<Suppressions::Supp
std::list<ErrorLogger::ErrorMessage::FileLocation> 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));
}
}

View File

@ -481,7 +481,7 @@ static void loadVisualStudioProperties(const std::string &props, std::map<std::s
} else if (std::strcmp(node->Name(),"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::map<std::str
if (std::strcmp(cfg->Name(), "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::map<std::str
}
}
} else if (std::strcmp(node->Name(), "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) {

View File

@ -36,7 +36,7 @@ static std::vector<std::string> getnames(const char *names)
{
std::vector<std::string> 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)

View File

@ -424,13 +424,11 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
std::set<std::string> Preprocessor::getConfigs(const simplecpp::TokenList &tokens) const
{
std::set<std::string> ret;
ret.insert("");
std::set<std::string> ret = { "" };
if (!tokens.cfront())
return ret;
std::set<std::string> defined;
defined.insert("__cplusplus");
std::set<std::string> defined = { "__cplusplus" };
::getConfigs(tokens, defined, _settings.userDefines, _settings.userUndefs, ret);

View File

@ -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

View File

@ -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(),
varlist.emplace_back(token_, start_, end_, varlist.size(),
access_,
type_, scope_, lib));
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;

View File

@ -483,7 +483,7 @@ static void setScopeInfo(const Token *tok, std::list<ScopeInfo2> *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::TokenAndName> 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::TokenAndName> 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::TokenAndName> TemplateSimplifier::getTemplateInsta
const std::string fullName = scopeName + (scopeName.empty()?"":" :: ") + tok->str();
const std::list<TokenAndName>::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::list<TemplateSimplifier::T
tok2 = tok2->next();
}
args.push_back(std::pair<Token *, Token *>(start, tok2));
args.emplace_back(start, tok2);
if (tok2 && tok2->str() == ",") {
tok2 = tok2->next();
} else {
@ -813,7 +813,7 @@ void TemplateSimplifier::simplifyTemplateAliases(std::list<TemplateSimplifier::T
templateInstantiations->end(),
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<Token*,Token*>(nameTok, tok2->next()));
removeTokens.emplace_back(nameTok, tok2->next());
}
nameTok = tok2;

View File

@ -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 Token *>::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<std::string, const Token *>(name, nameTok));
unknowns.emplace(name, nameTok);
}
}

View File

@ -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<ValueFlow::Value> 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<ValueFlow::Value> values;
values.push_back(value);
@ -2319,7 +2319,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat
std::list<ValueFlow::Value> values = tok->astOperand2()->values();
for (std::list<ValueFlow::Value>::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<ValueFlow::Value> 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<ValueFlow::Value> 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<ValueFlow::Value> 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<ValueFlow::Value>::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<ValueFlow::Value> 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,7 +3209,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
for (std::list<ValueFlow::Value>::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,
it->errorPath.emplace_back(argtok,
"Calling function '" +
calledFunction->name() +
"', " +
@ -3217,7 +3217,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
" argument '" +
argvar->name() +
"' value is " +
it->infoString()));
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

View File

@ -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());
}