From 5f171b96738f475f63c84097e2411f4236c911c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 17 Aug 2022 09:50:14 +0200 Subject: [PATCH] fixed some `modernize-use-emplace` false negatives with `std::stack` / removed `internalStlUsage` check (#4346) --- gui/test/data/benchmark/simple.cpp | 4 ++-- lib/checkinternal.cpp | 13 ------------- lib/checkinternal.h | 4 ---- lib/symboldatabase.cpp | 6 +++--- lib/tokenize.cpp | 10 +++++----- lib/utils.cpp | 2 +- 6 files changed, 11 insertions(+), 28 deletions(-) diff --git a/gui/test/data/benchmark/simple.cpp b/gui/test/data/benchmark/simple.cpp index b1a8bd99e..4c90985e7 100644 --- a/gui/test/data/benchmark/simple.cpp +++ b/gui/test/data/benchmark/simple.cpp @@ -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; diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp index a47a00b22..5412934bd 100644 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -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", diff --git a/lib/checkinternal.h b/lib/checkinternal.h index ce74ae079..939e7327b 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -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); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5fccbec83..11a04d087 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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(); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 65ad81481..94690bdd2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3466,7 +3466,7 @@ public: void VariableMap::enterScope() { - mScopeInfo.push(std::vector>()); + mScopeInfo.emplace(/*std::vector>()*/); } bool VariableMap::leaveScope() @@ -3840,7 +3840,7 @@ void Tokenizer::setVarIdPass1() std::stack scopeStack; - scopeStack.push(VarIdScopeInfo()); + scopeStack.emplace(/*VarIdScopeInfo()*/); std::stack 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()*/); } } } diff --git a/lib/utils.cpp b/lib/utils.cpp index e5b31d98b..a2a87a650 100644 --- a/lib/utils.cpp +++ b/lib/utils.cpp @@ -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 '?':