fixed some `modernize-use-emplace` false negatives with `std::stack` / removed `internalStlUsage` check (#4346)
This commit is contained in:
parent
5b4c6c1e73
commit
5f171b9673
|
@ -357,7 +357,7 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||
break;
|
||||
}
|
||||
ifnest.push(std::make_pair(tok2->link(), false));
|
||||
ifnest.emplace(tok2->link(), false);
|
||||
justbreak = false;
|
||||
} else if (Token::simpleMatch(tok2, "while (")) {
|
||||
tok2 = tok2->tokAt(1)->link()->next();
|
||||
|
@ -420,7 +420,7 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||
break;
|
||||
}
|
||||
ifnest.push(std::make_pair(tok2->link(), justbreak));
|
||||
ifnest.emplace(tok2->link(), justbreak);
|
||||
justbreak = false;
|
||||
} else {
|
||||
justbreak &= ifnest.top().second;
|
||||
|
|
|
@ -343,19 +343,6 @@ void CheckInternal::checkExtraWhitespace()
|
|||
}
|
||||
}
|
||||
|
||||
void CheckInternal::checkStlUsage()
|
||||
{
|
||||
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||
for (const Scope *scope : symbolDatabase->functionScopes) {
|
||||
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, ". emplace ("))
|
||||
reportError(tok, Severity::error, "internalStlUsage", "The 'emplace' function shall be avoided for now. It is not available e.g. in Slackware 14.0. 'emplace_back' is fine.");
|
||||
//if (Token::simpleMatch(tok, ". back ( )") && tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->container && Token::simpleMatch(tok->astOperand1()->valueType()->container, "std :: string"))
|
||||
// reportError(tok, Severity::error, "internalStlUsage", "The 'std::string::back()' function shall be avoided for now.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckInternal::multiComparePatternError(const Token* tok, const std::string& pattern, const std::string &funcname)
|
||||
{
|
||||
reportError(tok, Severity::error, "multiComparePatternError",
|
||||
|
|
|
@ -55,7 +55,6 @@ public:
|
|||
checkInternal.checkRedundantNextPrevious();
|
||||
checkInternal.checkExtraWhitespace();
|
||||
checkInternal.checkRedundantTokCheck();
|
||||
checkInternal.checkStlUsage();
|
||||
}
|
||||
|
||||
/** @brief %Check if a simple pattern is used inside Token::Match or Token::findmatch */
|
||||
|
@ -78,9 +77,6 @@ public:
|
|||
|
||||
/** @brief %Check if there is a redundant check for none-nullness of parameter before Match functions, such as (tok && Token::Match(tok, "foo")) */
|
||||
void checkRedundantTokCheck();
|
||||
|
||||
/** @brief Try to avoid some new functions that are not fully supported in Linux */
|
||||
void checkStlUsage();
|
||||
private:
|
||||
void multiComparePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
|
||||
void simplePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
|
||||
|
|
|
@ -699,7 +699,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
|||
scope->checkVariable(tok->tokAt(2), AccessControl::Throw, mSettings); // check for variable declaration and add it to new scope if found
|
||||
tok = scopeStartTok;
|
||||
} else if (Token::Match(tok, "%var% {")) {
|
||||
endInitList.push(std::make_pair(tok->next()->link(), scope));
|
||||
endInitList.emplace(tok->next()->link(), scope);
|
||||
tok = tok->next();
|
||||
} else if (const Token *lambdaEndToken = findLambdaEndToken(tok)) {
|
||||
const Token *lambdaStartToken = lambdaEndToken->link();
|
||||
|
@ -711,13 +711,13 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
|||
tok = lambdaStartToken;
|
||||
} else if (tok->str() == "{") {
|
||||
if (inInitList()) {
|
||||
endInitList.push(std::make_pair(tok->link(), scope));
|
||||
endInitList.emplace(tok->link(), scope);
|
||||
} else if (isExecutableScope(tok)) {
|
||||
scopeList.emplace_back(this, tok, scope, Scope::eUnconditional, tok);
|
||||
scope->nestedList.push_back(&scopeList.back());
|
||||
scope = &scopeList.back();
|
||||
} else if (scope->isExecutable()) {
|
||||
endInitList.push(std::make_pair(tok->link(), scope));
|
||||
endInitList.emplace(tok->link(), scope);
|
||||
} else {
|
||||
tok = tok->link();
|
||||
}
|
||||
|
|
|
@ -3466,7 +3466,7 @@ public:
|
|||
|
||||
void VariableMap::enterScope()
|
||||
{
|
||||
mScopeInfo.push(std::vector<std::pair<std::string, nonneg int>>());
|
||||
mScopeInfo.emplace(/*std::vector<std::pair<std::string, nonneg int>>()*/);
|
||||
}
|
||||
|
||||
bool VariableMap::leaveScope()
|
||||
|
@ -3840,7 +3840,7 @@ void Tokenizer::setVarIdPass1()
|
|||
|
||||
std::stack<VarIdScopeInfo> scopeStack;
|
||||
|
||||
scopeStack.push(VarIdScopeInfo());
|
||||
scopeStack.emplace(/*VarIdScopeInfo()*/);
|
||||
std::stack<const Token *> functionDeclEndStack;
|
||||
const Token *functionDeclEndToken = nullptr;
|
||||
bool initlist = false;
|
||||
|
@ -3864,7 +3864,7 @@ void Tokenizer::setVarIdPass1()
|
|||
if (!variableMap.leaveScope())
|
||||
cppcheckError(tok);
|
||||
} else if (tok->str() == "{") {
|
||||
scopeStack.push(VarIdScopeInfo(true, scopeStack.top().isStructInit || tok->strAt(-1) == "=", /*isEnum=*/ false, *variableMap.getVarId()));
|
||||
scopeStack.emplace(true, scopeStack.top().isStructInit || tok->strAt(-1) == "=", /*isEnum=*/ false, *variableMap.getVarId());
|
||||
|
||||
// check if this '{' is a start of an "if" body
|
||||
const Token * ifToken = tok->previous();
|
||||
|
@ -3918,7 +3918,7 @@ void Tokenizer::setVarIdPass1()
|
|||
variableMap.enterScope();
|
||||
}
|
||||
initlist = false;
|
||||
scopeStack.push(VarIdScopeInfo(isExecutable, scopeStack.top().isStructInit || tok->strAt(-1) == "=", isEnumStart(tok), *variableMap.getVarId()));
|
||||
scopeStack.emplace(isExecutable, scopeStack.top().isStructInit || tok->strAt(-1) == "=", isEnumStart(tok), *variableMap.getVarId());
|
||||
} else { /* if (tok->str() == "}") */
|
||||
bool isNamespace = false;
|
||||
for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous()) {
|
||||
|
@ -3952,7 +3952,7 @@ void Tokenizer::setVarIdPass1()
|
|||
|
||||
scopeStack.pop();
|
||||
if (scopeStack.empty()) { // should be impossible
|
||||
scopeStack.push(VarIdScopeInfo());
|
||||
scopeStack.emplace(/*VarIdScopeInfo()*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ bool matchglob(const std::string& pattern, const std::string& name)
|
|||
}
|
||||
if (*n != '\0') {
|
||||
// If this isn't the last possibility, save it for later
|
||||
backtrack.push(std::make_pair(p, n));
|
||||
backtrack.emplace(p, n);
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
|
|
Loading…
Reference in New Issue