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:
parent
8aa71d62a0
commit
d2146844dd
|
@ -294,7 +294,7 @@ unsigned int ThreadExecutor::check()
|
||||||
oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat);
|
oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat);
|
||||||
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locations;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locations;
|
||||||
locations.push_back(ErrorLogger::ErrorMessage::FileLocation(childname, 0));
|
locations.emplace_back(childname, 0);
|
||||||
const ErrorLogger::ErrorMessage errmsg(locations,
|
const ErrorLogger::ErrorMessage errmsg(locations,
|
||||||
emptyString,
|
emptyString,
|
||||||
Severity::error,
|
Severity::error,
|
||||||
|
|
|
@ -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()) {
|
for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) {
|
||||||
if (std::strcmp(e->Name(), "error") == 0)
|
if (std::strcmp(e->Name(), "error") == 0)
|
||||||
errors->push_back(ErrorLogger::ErrorMessage(e));
|
errors->emplace_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -162,16 +162,16 @@ protected:
|
||||||
ErrorPath getErrorPath(const Token *errtok, const ValueFlow::Value *value, const std::string &bug) const {
|
ErrorPath getErrorPath(const Token *errtok, const ValueFlow::Value *value, const std::string &bug) const {
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
errorPath.push_back(ErrorPathItem(errtok,bug));
|
errorPath.emplace_back(errtok,bug);
|
||||||
} else if (_settings->verbose || _settings->xml || _settings->outputFormat == "daca2") {
|
} else if (_settings->verbose || _settings->xml || _settings->outputFormat == "daca2") {
|
||||||
errorPath = value->errorPath;
|
errorPath = value->errorPath;
|
||||||
errorPath.push_back(ErrorPathItem(errtok,bug));
|
errorPath.emplace_back(errtok,bug);
|
||||||
} else {
|
} else {
|
||||||
if (value->condition)
|
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)
|
//else if (!value->isKnown() || value->defaultArg)
|
||||||
// errorPath = value->callstack;
|
// errorPath = value->callstack;
|
||||||
errorPath.push_back(ErrorPathItem(errtok,bug));
|
errorPath.emplace_back(errtok,bug);
|
||||||
}
|
}
|
||||||
return errorPath;
|
return errorPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,14 +103,14 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
|
||||||
std::string nr;
|
std::string nr;
|
||||||
if (index.size() > 1U)
|
if (index.size() > 1U)
|
||||||
nr = "(" + MathLib::toString(i + 1) + getOrdinalText(i + 1) + " array index) ";
|
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 {
|
} else {
|
||||||
errorPath.push_back(ErrorPathItem(tok, "Array index out of bounds"));
|
errorPath.emplace_back(tok, "Array index out of bounds");
|
||||||
if (condition)
|
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) {
|
if (condition != nullptr) {
|
||||||
|
|
|
@ -2115,13 +2115,13 @@ void CheckClass::initializerListOrder()
|
||||||
if (Token::Match(tok, "%name% (|{")) {
|
if (Token::Match(tok, "%name% (|{")) {
|
||||||
const Variable *var = scope->getVariable(tok->str());
|
const Variable *var = scope->getVariable(tok->str());
|
||||||
if (var)
|
if (var)
|
||||||
vars.push_back(VarInfo(var, tok));
|
vars.emplace_back(var, tok);
|
||||||
|
|
||||||
if (Token::Match(tok->tokAt(2), "%name% =")) {
|
if (Token::Match(tok->tokAt(2), "%name% =")) {
|
||||||
var = scope->getVariable(tok->strAt(2));
|
var = scope->getVariable(tok->strAt(2));
|
||||||
|
|
||||||
if (var)
|
if (var)
|
||||||
vars.push_back(VarInfo(var, tok->tokAt(2)));
|
vars.emplace_back(var, tok->tokAt(2));
|
||||||
}
|
}
|
||||||
tok = tok->next()->link()->next();
|
tok = tok->next()->link()->next();
|
||||||
} else
|
} else
|
||||||
|
@ -2303,7 +2303,7 @@ void CheckClass::virtualFunctionCallInConstructorError(
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
int lineNumber = 1;
|
int lineNumber = 1;
|
||||||
for (std::list<const Token *>::const_iterator it = tokStack.begin(); it != tokStack.end(); ++it)
|
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()) {
|
if (!errorPath.empty()) {
|
||||||
lineNumber = errorPath.front().first->linenr();
|
lineNumber = errorPath.front().first->linenr();
|
||||||
errorPath.back().second = funcname + " is a virtual method";
|
errorPath.back().second = funcname + " is a virtual method";
|
||||||
|
@ -2337,7 +2337,7 @@ void CheckClass::pureVirtualFunctionCallInConstructorError(
|
||||||
|
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
for (std::list<const Token *>::const_iterator it = tokStack.begin(); it != tokStack.end(); ++it)
|
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())
|
if (!errorPath.empty())
|
||||||
errorPath.back().second = purefuncname + " is a pure virtual method without body";
|
errorPath.back().second = purefuncname + " is a pure virtual method without body";
|
||||||
|
|
||||||
|
|
|
@ -354,9 +354,9 @@ void CheckOther::invalidPointerCast()
|
||||||
if (toType->isIntegral() && fromType->isIntegral())
|
if (toType->isIntegral() && fromType->isIntegral())
|
||||||
continue;
|
continue;
|
||||||
std::string toStr = toType->isIntegral() ? "integer *" : toType->str();
|
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();
|
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);
|
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
|
// Keep track of which variables were assigned addresses to newly-allocated memory
|
||||||
if (Token::Match(tok, "%var% = malloc|g_malloc|new")) {
|
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
|
// If a previously-allocated pointer is incremented or decremented, any subsequent
|
||||||
|
|
|
@ -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<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) {
|
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
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int numpar = 0;
|
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) {
|
for (std::list<Variable>::const_iterator var = func->argumentList.cbegin(); var != func->argumentList.cend(); ++var) {
|
||||||
numpar++;
|
numpar++;
|
||||||
if (var->isStlStringType() && (!var->isReference() || var->isConst()))
|
if (var->isStlStringType() && (!var->isReference() || var->isConst()))
|
||||||
c_strFuncParam.insert(std::make_pair(func->tokenDef->str(), numpar));
|
c_strFuncParam.emplace(func->tokenDef->str(), numpar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
|
||||||
if (tokenizer.isCPP() && func->retDef->str() == "template")
|
if (tokenizer.isCPP() && func->retDef->str() == "template")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_functionDecl.push_back(FunctionDecl(func));
|
_functionDecl.emplace_back(func);
|
||||||
|
|
||||||
FunctionUsage &usage = _functions[func->name()];
|
FunctionUsage &usage = _functions[func->name()];
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ void Variables::addVar(const Variable *var,
|
||||||
{
|
{
|
||||||
if (var->declarationId() > 0) {
|
if (var->declarationId() > 0) {
|
||||||
_varAddedInScope.back().insert(var->declarationId());
|
_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()
|
void Variables::enterScope()
|
||||||
{
|
{
|
||||||
_varAddedInScope.push_back(std::set<unsigned int>());
|
_varAddedInScope.emplace_back();
|
||||||
_varReadInScope.push_back(std::set<unsigned int>());
|
_varReadInScope.emplace_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Variables::leaveScope(bool insideLoop)
|
void Variables::leaveScope(bool insideLoop)
|
||||||
|
|
|
@ -89,7 +89,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack
|
||||||
if (!(*it))
|
if (!(*it))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(*it, list));
|
_callStack.emplace_back(*it, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list && !list->getFiles().empty())
|
if (list && !list->getFiles().empty())
|
||||||
|
@ -108,7 +108,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack
|
||||||
if (!(*it))
|
if (!(*it))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(*it, list));
|
_callStack.emplace_back(*it, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list && !list->getFiles().empty())
|
if (list && !list->getFiles().empty())
|
||||||
|
@ -127,7 +127,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenL
|
||||||
|
|
||||||
// --errorlist can provide null values here
|
// --errorlist can provide null values here
|
||||||
if (tok)
|
if (tok)
|
||||||
_callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(tok, info, tokenList));
|
_callStack.emplace_back(tok, info, tokenList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenList && !tokenList->getFiles().empty())
|
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 *file = strfile ? strfile : unknown;
|
||||||
const char *info = strinfo ? strinfo : "";
|
const char *info = strinfo ? strinfo : "";
|
||||||
const int line = strline ? std::atoi(strline) : 0;
|
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;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
||||||
if (!i->fileName.empty())
|
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));
|
reportErr(ErrorLogger::ErrorMessage(callStack, emptyString, Severity::information, "Unmatched suppression: " + i->errorId, "unmatchedSuppression", false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,7 +481,7 @@ static void loadVisualStudioProperties(const std::string &props, std::map<std::s
|
||||||
} else if (std::strcmp(node->Name(),"PropertyGroup")==0) {
|
} else if (std::strcmp(node->Name(),"PropertyGroup")==0) {
|
||||||
importPropertyGroup(node, variables, includePath, nullptr);
|
importPropertyGroup(node, variables, includePath, nullptr);
|
||||||
} else if (std::strcmp(node->Name(),"ItemDefinitionGroup")==0) {
|
} 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) {
|
if (std::strcmp(cfg->Name(), "ProjectConfiguration") == 0) {
|
||||||
const ProjectConfiguration p(cfg);
|
const ProjectConfiguration p(cfg);
|
||||||
if (p.platform != ProjectConfiguration::Unknown)
|
if (p.platform != ProjectConfiguration::Unknown)
|
||||||
projectConfigurationList.push_back(ProjectConfiguration(cfg));
|
projectConfigurationList.emplace_back(cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -525,7 +525,7 @@ void ImportProject::importVcxproj(const std::string &filename, std::map<std::str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (std::strcmp(node->Name(), "ItemDefinitionGroup") == 0) {
|
} 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) {
|
} else if (std::strcmp(node->Name(), "PropertyGroup") == 0) {
|
||||||
importPropertyGroup(node, &variables, &includePath, &useOfMfc);
|
importPropertyGroup(node, &variables, &includePath, &useOfMfc);
|
||||||
} else if (std::strcmp(node->Name(), "ImportGroup") == 0) {
|
} else if (std::strcmp(node->Name(), "ImportGroup") == 0) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ static std::vector<std::string> getnames(const char *names)
|
||||||
{
|
{
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> ret;
|
||||||
while (const char *p = std::strchr(names,',')) {
|
while (const char *p = std::strchr(names,',')) {
|
||||||
ret.push_back(std::string(names, p-names));
|
ret.emplace_back(names, p-names);
|
||||||
names = p + 1;
|
names = p + 1;
|
||||||
}
|
}
|
||||||
ret.push_back(names);
|
ret.push_back(names);
|
||||||
|
@ -626,7 +626,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
||||||
return Error(BAD_ATTRIBUTE_VALUE, argattr);
|
return Error(BAD_ATTRIBUTE_VALUE, argattr);
|
||||||
|
|
||||||
ac.minsizes.reserve(type == ArgumentChecks::MinSize::MUL ? 2 : 1);
|
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) {
|
if (type == ArgumentChecks::MinSize::MUL) {
|
||||||
const char *arg2attr = argnode->Attribute("arg2");
|
const char *arg2attr = argnode->Attribute("arg2");
|
||||||
if (!arg2attr)
|
if (!arg2attr)
|
||||||
|
|
|
@ -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> Preprocessor::getConfigs(const simplecpp::TokenList &tokens) const
|
||||||
{
|
{
|
||||||
std::set<std::string> ret;
|
std::set<std::string> ret = { "" };
|
||||||
ret.insert("");
|
|
||||||
if (!tokens.cfront())
|
if (!tokens.cfront())
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
std::set<std::string> defined;
|
std::set<std::string> defined = { "__cplusplus" };
|
||||||
defined.insert("__cplusplus");
|
|
||||||
|
|
||||||
::getConfigs(tokens, defined, _settings.userDefines, _settings.userUndefs, ret);
|
::getConfigs(tokens, defined, _settings.userDefines, _settings.userUndefs, ret);
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
{
|
{
|
||||||
// create global scope
|
// create global scope
|
||||||
scopeList.push_back(Scope(this, nullptr, nullptr));
|
scopeList.emplace_back(this, nullptr, nullptr);
|
||||||
|
|
||||||
// pointer to current scope
|
// pointer to current scope
|
||||||
Scope *scope = &scopeList.back();
|
Scope *scope = &scopeList.back();
|
||||||
|
@ -169,7 +169,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
scope = new_scope;
|
scope = new_scope;
|
||||||
tok = tok2;
|
tok = tok2;
|
||||||
} else {
|
} else {
|
||||||
scopeList.push_back(Scope(this, tok, scope));
|
scopeList.emplace_back(this, tok, scope);
|
||||||
new_scope = &scopeList.back();
|
new_scope = &scopeList.back();
|
||||||
|
|
||||||
if (tok->str() == "class")
|
if (tok->str() == "class")
|
||||||
|
@ -181,7 +181,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
if (new_scope->isClassOrStructOrUnion() || new_scope->type == Scope::eEnum) {
|
if (new_scope->isClassOrStructOrUnion() || new_scope->type == Scope::eEnum) {
|
||||||
Type* new_type = findType(tok->next(), scope);
|
Type* new_type = findType(tok->next(), scope);
|
||||||
if (!new_type) {
|
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();
|
new_type = &typeList.back();
|
||||||
scope->definedTypesMap[new_type->name()] = new_type;
|
scope->definedTypesMap[new_type->name()] = new_type;
|
||||||
} else
|
} else
|
||||||
|
@ -232,7 +232,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
Token::Match(tok, "namespace %name% %type% (") &&
|
Token::Match(tok, "namespace %name% %type% (") &&
|
||||||
tok->tokAt(2)->isUpperCaseName() &&
|
tok->tokAt(2)->isUpperCaseName() &&
|
||||||
Token::simpleMatch(tok->linkAt(3), ") {")) {
|
Token::simpleMatch(tok->linkAt(3), ") {")) {
|
||||||
scopeList.push_back(Scope(this, tok, scope));
|
scopeList.emplace_back(this, tok, scope);
|
||||||
|
|
||||||
Scope *new_scope = &scopeList.back();
|
Scope *new_scope = &scopeList.back();
|
||||||
access[new_scope] = Public;
|
access[new_scope] = Public;
|
||||||
|
@ -260,7 +260,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
tok->strAt(-1) != "friend") {
|
tok->strAt(-1) != "friend") {
|
||||||
if (!findType(tok->next(), scope)) {
|
if (!findType(tok->next(), scope)) {
|
||||||
// fill typeList..
|
// fill typeList..
|
||||||
typeList.push_back(Type(tok, nullptr, scope));
|
typeList.emplace_back(tok, nullptr, scope);
|
||||||
Type* new_type = &typeList.back();
|
Type* new_type = &typeList.back();
|
||||||
scope->definedTypesMap[new_type->name()] = new_type;
|
scope->definedTypesMap[new_type->name()] = new_type;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
else if (_tokenizer->isCPP() && Token::Match(tok, "using %name% =")) {
|
else if (_tokenizer->isCPP() && Token::Match(tok, "using %name% =")) {
|
||||||
if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) {
|
if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) {
|
||||||
// fill typeList..
|
// fill typeList..
|
||||||
typeList.push_back(Type(tok, nullptr, scope));
|
typeList.emplace_back(tok, nullptr, scope);
|
||||||
Type* new_type = &typeList.back();
|
Type* new_type = &typeList.back();
|
||||||
scope->definedTypesMap[new_type->name()] = new_type;
|
scope->definedTypesMap[new_type->name()] = new_type;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
// unnamed struct and union
|
// unnamed struct and union
|
||||||
else if (Token::Match(tok, "struct|union {") &&
|
else if (Token::Match(tok, "struct|union {") &&
|
||||||
Token::Match(tok->next()->link(), "} *|&| %name% ;|[")) {
|
Token::Match(tok->next()->link(), "} *|&| %name% ;|[")) {
|
||||||
scopeList.push_back(Scope(this, tok, scope));
|
scopeList.emplace_back(this, tok, scope);
|
||||||
|
|
||||||
Scope *new_scope = &scopeList.back();
|
Scope *new_scope = &scopeList.back();
|
||||||
access[new_scope] = Public;
|
access[new_scope] = Public;
|
||||||
|
@ -317,7 +317,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
varNameTok = varNameTok->next();
|
varNameTok = varNameTok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
typeList.push_back(Type(tok, new_scope, scope));
|
typeList.emplace_back(tok, new_scope, scope);
|
||||||
{
|
{
|
||||||
Type* new_type = &typeList.back();
|
Type* new_type = &typeList.back();
|
||||||
new_scope->definedType = new_type;
|
new_scope->definedType = new_type;
|
||||||
|
@ -348,7 +348,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
else if ((Token::Match(tok, "struct|union {") &&
|
else if ((Token::Match(tok, "struct|union {") &&
|
||||||
Token::simpleMatch(tok->next()->link(), "} ;")) ||
|
Token::simpleMatch(tok->next()->link(), "} ;")) ||
|
||||||
Token::simpleMatch(tok, "namespace {")) {
|
Token::simpleMatch(tok, "namespace {")) {
|
||||||
scopeList.push_back(Scope(this, tok, scope));
|
scopeList.emplace_back(this, tok, scope);
|
||||||
|
|
||||||
Scope *new_scope = &scopeList.back();
|
Scope *new_scope = &scopeList.back();
|
||||||
access[new_scope] = Public;
|
access[new_scope] = Public;
|
||||||
|
@ -358,7 +358,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
new_scope->classStart = tok2;
|
new_scope->classStart = tok2;
|
||||||
new_scope->classEnd = tok2->link();
|
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();
|
Type* new_type = &typeList.back();
|
||||||
new_scope->definedType = new_type;
|
new_scope->definedType = new_type;
|
||||||
|
@ -380,7 +380,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
|
|
||||||
// forward declared enum
|
// forward declared enum
|
||||||
else if (Token::Match(tok, "enum class| %name% ;") || Token::Match(tok, "enum class| %name% : %name% ;")) {
|
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();
|
Type* new_type = &typeList.back();
|
||||||
scope->definedTypesMap[new_type->name()] = new_type;
|
scope->definedTypesMap[new_type->name()] = new_type;
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
|
@ -801,11 +801,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
if (Token::Match(tok, "else|try|do {")) {
|
if (Token::Match(tok, "else|try|do {")) {
|
||||||
const Token* tok1 = tok->next();
|
const Token* tok1 = tok->next();
|
||||||
if (tok->str() == "else")
|
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")
|
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")
|
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;
|
tok = tok1;
|
||||||
scope->nestedList.push_back(&scopeList.back());
|
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(), ") {")) {
|
} else if (Token::Match(tok, "if|for|while|catch|switch (") && Token::simpleMatch(tok->next()->link(), ") {")) {
|
||||||
const Token *scopeStartTok = tok->next()->link()->next();
|
const Token *scopeStartTok = tok->next()->link()->next();
|
||||||
if (tok->str() == "if")
|
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") {
|
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")
|
} 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") {
|
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")
|
} 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->nestedList.push_back(&scopeList.back());
|
||||||
scope = &scopeList.back();
|
scope = &scopeList.back();
|
||||||
|
@ -841,11 +841,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
||||||
tok2 = nullptr; // No lambda
|
tok2 = nullptr; // No lambda
|
||||||
|
|
||||||
if (tok2 && tok2->str() == ")" && tok2->link()->strAt(-1) == "]") {
|
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->nestedList.push_back(&scopeList.back());
|
||||||
scope = &scopeList.back();
|
scope = &scopeList.back();
|
||||||
} else if (!Token::Match(tok->previous(), "=|,|(|return") && !(tok->strAt(-1) == ")" && Token::Match(tok->linkAt(-1)->previous(), "=|,|(|return"))) {
|
} 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->nestedList.push_back(&scopeList.back());
|
||||||
scope = &scopeList.back();
|
scope = &scopeList.back();
|
||||||
} else {
|
} else {
|
||||||
|
@ -2288,7 +2288,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
|
||||||
void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
|
void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
|
||||||
{
|
{
|
||||||
const Token *tok1 = *tok;
|
const Token *tok1 = *tok;
|
||||||
scopeList.push_back(Scope(this, tok1, *scope));
|
scopeList.emplace_back(this, tok1, *scope);
|
||||||
Scope *newScope = &scopeList.back();
|
Scope *newScope = &scopeList.back();
|
||||||
|
|
||||||
// find start of function '{'
|
// find start of function '{'
|
||||||
|
@ -3163,7 +3163,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
||||||
while (Token::Match(startTok, "enum|struct|const"))
|
while (Token::Match(startTok, "enum|struct|const"))
|
||||||
startTok = startTok->next();
|
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() == ")") {
|
if (tok->str() == ")") {
|
||||||
// check for a variadic function
|
// check for a variadic function
|
||||||
|
|
|
@ -993,9 +993,9 @@ public:
|
||||||
void addVariable(const Token *token_, const Token *start_,
|
void addVariable(const Token *token_, const Token *start_,
|
||||||
const Token *end_, AccessControl access_, const Type *type_,
|
const Token *end_, AccessControl access_, const Type *type_,
|
||||||
const Scope *scope_, const Library* lib) {
|
const Scope *scope_, const Library* lib) {
|
||||||
varlist.push_back(Variable(token_, start_, end_, varlist.size(),
|
varlist.emplace_back(token_, start_, end_, varlist.size(),
|
||||||
access_,
|
access_,
|
||||||
type_, scope_, lib));
|
type_, scope_, lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief initialize varlist */
|
/** @brief initialize varlist */
|
||||||
|
@ -1008,7 +1008,7 @@ public:
|
||||||
|
|
||||||
const Function * back = &functionList.back();
|
const Function * back = &functionList.back();
|
||||||
|
|
||||||
functionMap.insert(make_pair(back->tokenDef->str(), back));
|
functionMap.emplace(back->tokenDef->str(), back);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasDefaultConstructor() const;
|
bool hasDefaultConstructor() const;
|
||||||
|
|
|
@ -483,7 +483,7 @@ static void setScopeInfo(const Token *tok, std::list<ScopeInfo2> *scopeInfo)
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
if (tok && tok->str() == "{") {
|
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() == "{") {
|
else if (tok2->str() == "{") {
|
||||||
const int namepos = getTemplateNamePosition(parmEnd);
|
const int namepos = getTemplateNamePosition(parmEnd);
|
||||||
if (namepos > 0)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -563,7 +563,7 @@ std::list<TemplateSimplifier::TokenAndName> TemplateSimplifier::getTemplateInsta
|
||||||
for (; tok2 && tok2 != tok; tok2 = tok2->previous()) {
|
for (; tok2 && tok2 != tok; tok2 = tok2->previous()) {
|
||||||
if (Token::Match(tok2, ", %name% <") &&
|
if (Token::Match(tok2, ", %name% <") &&
|
||||||
TemplateSimplifier::templateParameters(tok2->tokAt(2))) {
|
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::string fullName = scopeName + (scopeName.empty()?"":" :: ") + tok->str();
|
||||||
const std::list<TokenAndName>::const_iterator it = std::find_if(declarations.begin(), declarations.end(), FindName(fullName));
|
const std::list<TokenAndName>::const_iterator it = std::find_if(declarations.begin(), declarations.end(), FindName(fullName));
|
||||||
if (it != declarations.end()) {
|
if (it != declarations.end()) {
|
||||||
instantiations.push_back(TokenAndName(tok, getScopeName(scopeList), fullName));
|
instantiations.emplace_back(tok, getScopeName(scopeList), fullName);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (scopeName.empty()) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
const std::string::size_type pos = scopeName.rfind(" :: ");
|
const std::string::size_type pos = scopeName.rfind(" :: ");
|
||||||
|
@ -781,7 +781,7 @@ void TemplateSimplifier::simplifyTemplateAliases(std::list<TemplateSimplifier::T
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
args.push_back(std::pair<Token *, Token *>(start, tok2));
|
args.emplace_back(start, tok2);
|
||||||
if (tok2 && tok2->str() == ",") {
|
if (tok2 && tok2->str() == ",") {
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -813,7 +813,7 @@ void TemplateSimplifier::simplifyTemplateAliases(std::list<TemplateSimplifier::T
|
||||||
templateInstantiations->end(),
|
templateInstantiations->end(),
|
||||||
FindToken(tok1));
|
FindToken(tok1));
|
||||||
if (it != templateInstantiations->end())
|
if (it != templateInstantiations->end())
|
||||||
templateInstantiations->push_back(TokenAndName(tok2, it->scope, it->name));
|
templateInstantiations->emplace_back(tok2, it->scope, it->name);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1075,7 +1075,7 @@ void TemplateSimplifier::expandTemplate(
|
||||||
std::string name = tok3->str();
|
std::string name = tok3->str();
|
||||||
for (const Token *prev = tok3->tokAt(-2); Token::Match(prev, "%name% ::"); prev = prev->tokAt(-2))
|
for (const Token *prev = tok3->tokAt(-2); Token::Match(prev, "%name% ::"); prev = prev->tokAt(-2))
|
||||||
name = prev->str() + " :: " + name;
|
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
|
// 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;
|
nameTok = tok2;
|
||||||
|
|
|
@ -2602,7 +2602,7 @@ void Tokenizer::setVarIdPass1()
|
||||||
variableId.swap(scopeInfo.top());
|
variableId.swap(scopeInfo.top());
|
||||||
scopeInfo.pop();
|
scopeInfo.pop();
|
||||||
} else if (tok->str() == "{")
|
} 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()=="(") {
|
} else if (!initlist && tok->str()=="(") {
|
||||||
const Token * newFunctionDeclEnd = nullptr;
|
const Token * newFunctionDeclEnd = nullptr;
|
||||||
if (!scopeStack.top().isExecutable)
|
if (!scopeStack.top().isExecutable)
|
||||||
|
@ -2638,7 +2638,7 @@ void Tokenizer::setVarIdPass1()
|
||||||
scopeInfo.push(variableId);
|
scopeInfo.push(variableId);
|
||||||
}
|
}
|
||||||
initlist = false;
|
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() == "}") */
|
} else { /* if (tok->str() == "}") */
|
||||||
bool isNamespace = false;
|
bool isNamespace = false;
|
||||||
for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous()) {
|
for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous()) {
|
||||||
|
@ -3004,9 +3004,9 @@ void Tokenizer::setVarIdPass2()
|
||||||
if (!tok->next())
|
if (!tok->next())
|
||||||
syntaxError(tok);
|
syntaxError(tok);
|
||||||
if (Token::Match(tok, "%name% ("))
|
if (Token::Match(tok, "%name% ("))
|
||||||
allMemberFunctions.push_back(Member(scope, usingnamespaces, tok1));
|
allMemberFunctions.emplace_back(scope, usingnamespaces, tok1);
|
||||||
else
|
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?
|
// What member variables are there in this class?
|
||||||
for (std::list<const Token *>::const_iterator it = classnameTokens.begin(); it != classnameTokens.end(); ++it)
|
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()) {
|
for (Token *tok2 = tokStart->next(); tok2 && tok2 != tokStart->link(); tok2 = tok2->next()) {
|
||||||
// skip parentheses..
|
// skip parentheses..
|
||||||
|
@ -9945,7 +9945,7 @@ void Tokenizer::printUnknownTypes() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unknowns.insert(std::pair<std::string, const Token *>(name, nameTok));
|
unknowns.emplace(name, nameTok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1098,7 +1098,7 @@ static void valueFlowReverse(TokenList *tokenlist,
|
||||||
if (inc != 0) {
|
if (inc != 0) {
|
||||||
val.intvalue += inc;
|
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());
|
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
|
// 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());
|
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
|
// bailout: variable is used in rhs in assignment to itself
|
||||||
|
@ -1971,7 +1971,7 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
it = values.erase(it);
|
it = values.erase(it);
|
||||||
} else {
|
} else {
|
||||||
const std::string info("Compound assignment '" + assign + "', assigned value is " + it->infoString());
|
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;
|
++it;
|
||||||
}
|
}
|
||||||
|
@ -2080,7 +2080,7 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
if (pre)
|
if (pre)
|
||||||
setTokenValue(op, *it, settings);
|
setTokenValue(op, *it, settings);
|
||||||
const std::string info(tok2->str() + " is " + std::string(inc ? "incremented" : "decremented") + "', new value is " + it->infoString());
|
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;
|
ValueFlow::Value value;
|
||||||
value.valueType = ValueFlow::Value::MOVED;
|
value.valueType = ValueFlow::Value::MOVED;
|
||||||
value.moveKind = ValueFlow::Value::NonMovedVariable;
|
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();
|
value.setKnown();
|
||||||
std::list<ValueFlow::Value> values;
|
std::list<ValueFlow::Value> values;
|
||||||
values.push_back(value);
|
values.push_back(value);
|
||||||
|
@ -2269,9 +2269,9 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab
|
||||||
value.valueType = ValueFlow::Value::MOVED;
|
value.valueType = ValueFlow::Value::MOVED;
|
||||||
value.moveKind = moveKind;
|
value.moveKind = moveKind;
|
||||||
if (moveKind == ValueFlow::Value::MovedVariable)
|
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)
|
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();
|
value.setKnown();
|
||||||
std::list<ValueFlow::Value> values;
|
std::list<ValueFlow::Value> values;
|
||||||
values.push_back(value);
|
values.push_back(value);
|
||||||
|
@ -2319,7 +2319,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat
|
||||||
std::list<ValueFlow::Value> values = tok->astOperand2()->values();
|
std::list<ValueFlow::Value> values = tok->astOperand2()->values();
|
||||||
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end(); ++it) {
|
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();
|
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();
|
const bool constValue = tok->astOperand2()->isNumber();
|
||||||
|
|
||||||
|
@ -2441,21 +2441,21 @@ static void valueFlowAfterCondition(TokenList *tokenlist, SymbolDatabase* symbol
|
||||||
std::list<ValueFlow::Value> false_values;
|
std::list<ValueFlow::Value> false_values;
|
||||||
// TODO: We should add all known values
|
// TODO: We should add all known values
|
||||||
if (numtok) {
|
if (numtok) {
|
||||||
false_values.push_back(ValueFlow::Value(tok, numtok->values().front().intvalue));
|
false_values.emplace_back(tok, numtok->values().front().intvalue);
|
||||||
true_values.push_back(ValueFlow::Value(tok, numtok->values().front().intvalue));
|
true_values.emplace_back(tok, numtok->values().front().intvalue);
|
||||||
} else if (lowertok) {
|
} else if (lowertok) {
|
||||||
long long v = lowertok->values().front().intvalue;
|
long long v = lowertok->values().front().intvalue;
|
||||||
true_values.push_back(ValueFlow::Value(tok, v+1));
|
true_values.emplace_back(tok, v+1);
|
||||||
false_values.push_back(ValueFlow::Value(tok, v));
|
false_values.emplace_back(tok, v);
|
||||||
|
|
||||||
} else if (uppertok) {
|
} else if (uppertok) {
|
||||||
long long v = uppertok->values().front().intvalue;
|
long long v = uppertok->values().front().intvalue;
|
||||||
true_values.push_back(ValueFlow::Value(tok, v-1));
|
true_values.emplace_back(tok, v-1);
|
||||||
false_values.push_back(ValueFlow::Value(tok, v));
|
false_values.emplace_back(tok, v);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
true_values.push_back(ValueFlow::Value(tok, 0LL));
|
true_values.emplace_back(tok, 0LL);
|
||||||
false_values.push_back(ValueFlow::Value(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;
|
endToken = fortok->scope()->classEnd;
|
||||||
|
|
||||||
std::list<ValueFlow::Value> values;
|
std::list<ValueFlow::Value> values;
|
||||||
values.push_back(ValueFlow::Value(num));
|
values.emplace_back(num);
|
||||||
values.back().errorPath.push_back(ErrorPathItem(fortok,"After for loop, " + var->name() + " has value " + values.back().infoString()));
|
values.back().errorPath.emplace_back(fortok,"After for loop, " + var->name() + " has value " + values.back().infoString());
|
||||||
|
|
||||||
valueFlowForward(fortok->linkAt(1)->linkAt(1)->next(),
|
valueFlowForward(fortok->linkAt(1)->linkAt(1)->next(),
|
||||||
endToken,
|
endToken,
|
||||||
|
@ -3067,10 +3067,10 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "case %num% :")) {
|
if (Token::Match(tok, "case %num% :")) {
|
||||||
std::list<ValueFlow::Value> values;
|
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;
|
values.back().condition = tok;
|
||||||
const std::string info("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
|
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;
|
bool known = false;
|
||||||
if ((Token::simpleMatch(tok->previous(), "{") || Token::simpleMatch(tok->tokAt(-2), "break ;")) && !Token::Match(tok->tokAt(3), ";| case"))
|
if ((Token::simpleMatch(tok->previous(), "{") || Token::simpleMatch(tok->tokAt(-2), "break ;")) && !Token::Match(tok->tokAt(3), ";| case"))
|
||||||
known = true;
|
known = true;
|
||||||
|
@ -3079,10 +3079,10 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
if (!tok->isName())
|
if (!tok->isName())
|
||||||
tok = tok->next();
|
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;
|
values.back().condition = tok;
|
||||||
const std::string info2("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
|
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) {
|
for (std::list<ValueFlow::Value>::const_iterator val = values.begin(); val != values.end(); ++val) {
|
||||||
valueFlowReverse(tokenlist,
|
valueFlowReverse(tokenlist,
|
||||||
|
@ -3196,8 +3196,8 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
// passing value(s) to function
|
// passing value(s) to function
|
||||||
std::list<ValueFlow::Value> argvalues;
|
std::list<ValueFlow::Value> argvalues;
|
||||||
if (Token::Match(argtok, "%comp%|%oror%|&&|!") && !argtok->hasKnownIntValue()) {
|
if (Token::Match(argtok, "%comp%|%oror%|&&|!") && !argtok->hasKnownIntValue()) {
|
||||||
argvalues.push_back(ValueFlow::Value(0));
|
argvalues.emplace_back(0);
|
||||||
argvalues.push_back(ValueFlow::Value(1));
|
argvalues.emplace_back(1);
|
||||||
} else {
|
} else {
|
||||||
argvalues = argtok->values();
|
argvalues = argtok->values();
|
||||||
}
|
}
|
||||||
|
@ -3209,15 +3209,15 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
for (std::list<ValueFlow::Value>::iterator it = argvalues.begin(); it != argvalues.end(); ++it) {
|
for (std::list<ValueFlow::Value>::iterator it = argvalues.begin(); it != argvalues.end(); ++it) {
|
||||||
const std::string nr = MathLib::toString(argnr + 1) + getOrdinalText(argnr + 1);
|
const std::string nr = MathLib::toString(argnr + 1) + getOrdinalText(argnr + 1);
|
||||||
|
|
||||||
it->errorPath.push_back(ErrorPathItem(argtok,
|
it->errorPath.emplace_back(argtok,
|
||||||
"Calling function '" +
|
"Calling function '" +
|
||||||
calledFunction->name() +
|
calledFunction->name() +
|
||||||
"', " +
|
"', " +
|
||||||
nr +
|
nr +
|
||||||
" argument '" +
|
" argument '" +
|
||||||
argvar->name() +
|
argvar->name() +
|
||||||
"' value is " +
|
"' value is " +
|
||||||
it->infoString()));
|
it->infoString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// passed values are not "known"..
|
// passed values are not "known"..
|
||||||
|
@ -3382,7 +3382,7 @@ ValueFlow::Value::Value(const Token *c, long long val)
|
||||||
defaultArg(false),
|
defaultArg(false),
|
||||||
valueKind(ValueKind::Possible)
|
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
|
std::string ValueFlow::Value::infoString() const
|
||||||
|
|
|
@ -300,40 +300,40 @@ private:
|
||||||
// suppress all unmatchedSuppression
|
// suppress all unmatchedSuppression
|
||||||
errout.str("");
|
errout.str("");
|
||||||
suppressions.clear();
|
suppressions.clear();
|
||||||
suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U));
|
suppressions.emplace_back("abc", "a.c", 10U);
|
||||||
suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "*", 0U));
|
suppressions.emplace_back("unmatchedSuppression", "*", 0U);
|
||||||
reportUnmatchedSuppressions(suppressions);
|
reportUnmatchedSuppressions(suppressions);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// suppress all unmatchedSuppression in a.c
|
// suppress all unmatchedSuppression in a.c
|
||||||
errout.str("");
|
errout.str("");
|
||||||
suppressions.clear();
|
suppressions.clear();
|
||||||
suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U));
|
suppressions.emplace_back("abc", "a.c", 10U);
|
||||||
suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "a.c", 0U));
|
suppressions.emplace_back("unmatchedSuppression", "a.c", 0U);
|
||||||
reportUnmatchedSuppressions(suppressions);
|
reportUnmatchedSuppressions(suppressions);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// suppress unmatchedSuppression in a.c at line 10
|
// suppress unmatchedSuppression in a.c at line 10
|
||||||
errout.str("");
|
errout.str("");
|
||||||
suppressions.clear();
|
suppressions.clear();
|
||||||
suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U));
|
suppressions.emplace_back("abc", "a.c", 10U);
|
||||||
suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "a.c", 10U));
|
suppressions.emplace_back("unmatchedSuppression", "a.c", 10U);
|
||||||
reportUnmatchedSuppressions(suppressions);
|
reportUnmatchedSuppressions(suppressions);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// don't suppress unmatchedSuppression when file is mismatching
|
// don't suppress unmatchedSuppression when file is mismatching
|
||||||
errout.str("");
|
errout.str("");
|
||||||
suppressions.clear();
|
suppressions.clear();
|
||||||
suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U));
|
suppressions.emplace_back("abc", "a.c", 10U);
|
||||||
suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "b.c", 0U));
|
suppressions.emplace_back("unmatchedSuppression", "b.c", 0U);
|
||||||
reportUnmatchedSuppressions(suppressions);
|
reportUnmatchedSuppressions(suppressions);
|
||||||
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());
|
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());
|
||||||
|
|
||||||
// don't suppress unmatchedSuppression when line is mismatching
|
// don't suppress unmatchedSuppression when line is mismatching
|
||||||
errout.str("");
|
errout.str("");
|
||||||
suppressions.clear();
|
suppressions.clear();
|
||||||
suppressions.push_back(Suppressions::Suppression("abc", "a.c", 10U));
|
suppressions.emplace_back("abc", "a.c", 10U);
|
||||||
suppressions.push_back(Suppressions::Suppression("unmatchedSuppression", "a.c", 1U));
|
suppressions.emplace_back("unmatchedSuppression", "a.c", 1U);
|
||||||
reportUnmatchedSuppressions(suppressions);
|
reportUnmatchedSuppressions(suppressions);
|
||||||
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());
|
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue