From 25ef9eeb265443ae26874edf99517c02de17d327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sat, 9 Apr 2022 19:02:37 +0200 Subject: [PATCH] use std::string::empty() (#3910) --- cli/cmdlineparser.cpp | 2 +- lib/checkleakautovar.cpp | 2 +- lib/suppressions.cpp | 2 +- lib/tokenize.cpp | 2 +- lib/valueflow.cpp | 4 ++-- test/testsymboldatabase.cpp | 2 +- test/testunusedfunctions.cpp | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 67524bc46..6dfa4eede 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -637,7 +637,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings->platform(Settings::Unix64); else if (platform == "native") mSettings->platform(Settings::Native); - else if (platform == "unspecified" || platform == "Unspecified" || platform == "") + else if (platform == "unspecified" || platform == "Unspecified" || platform.empty()) ; else if (!mSettings->loadPlatformFile(projectFile.c_str(), platform) && !mSettings->loadPlatformFile(argv[0], platform)) { std::string message("unrecognized platform: \""); diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index a0ce1b1d3..fb9cb6167 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -755,7 +755,7 @@ const Token * CheckLeakAutoVar::checkTokenInsideExpression(const Token * const t if (rhs->varId() == tok->varId()) { // simple assignment varInfo->erase(tok->varId()); - } else if (rhs->str() == "(" && mSettings->library.returnValue(rhs->astOperand1()) != emptyString) { + } else if (rhs->str() == "(" && !mSettings->library.returnValue(rhs->astOperand1()).empty()) { // #9298, assignment through return value of a function const std::string &returnValue = mSettings->library.returnValue(rhs->astOperand1()); if (returnValue.compare(0, 3, "arg") == 0) { diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 782711f9d..c13624b98 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -258,7 +258,7 @@ std::string Suppressions::addSuppressions(const std::list &suppress { for (const auto &newSuppression : suppressions) { auto errmsg = addSuppression(newSuppression); - if (errmsg != "") + if (!errmsg.empty()) return errmsg; } return ""; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 08ba5166b..089dcd73d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3439,7 +3439,7 @@ void Tokenizer::calculateScopes() // New scope is opening, record it here std::shared_ptr newScopeInfo = std::make_shared(tok->scopeInfo()->name, tok->link(), tok->scopeInfo()->usingNamespaces); - if (newScopeInfo->name != "" && nextScopeNameAddition != "") + if (!newScopeInfo->name.empty() && !nextScopeNameAddition.empty()) newScopeInfo->name.append(" :: "); newScopeInfo->name.append(nextScopeNameAddition); nextScopeNameAddition = ""; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 2d852528a..7767dcd14 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -4564,7 +4564,7 @@ static bool isOpenParenthesisMemberFunctionCallOfVarId(const Token * openParenth { const Token * varTok = openParenthesisToken->tokAt(-3); return Token::Match(varTok, "%varid% . %name% (", varId) && - varTok->next()->originalName() == emptyString; + varTok->next()->originalName().empty(); } static const Token * findOpenParentesisOfMove(const Token * moveVarTok) @@ -4603,7 +4603,7 @@ static void valueFlowAfterMove(TokenList* tokenlist, SymbolDatabase* symboldatab for (Token* tok = const_cast(start); tok != scope->bodyEnd; tok = tok->next()) { Token * varTok; - if (Token::Match(tok, "%var% . reset|clear (") && tok->next()->originalName() == emptyString) { + if (Token::Match(tok, "%var% . reset|clear (") && tok->next()->originalName().empty()) { varTok = tok; ValueFlow::Value value; value.valueType = ValueFlow::Value::ValueType::MOVED; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 4c95fac28..2147e3aa1 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -2220,7 +2220,7 @@ private: const Scope* f = db->findScopeByName("f"); ASSERT(f && f->type == Scope::eFunction && f->function); - ASSERT(f->function->argumentList.size() == 2 && f->function->argumentList.front().index() == 0 && f->function->argumentList.front().name() == "" && f->function->argumentList.back().index() == 1); + ASSERT(f->function->argumentList.size() == 2 && f->function->argumentList.front().index() == 0 && f->function->argumentList.front().name().empty() && f->function->argumentList.back().index() == 1); ASSERT_EQUALS("", errout.str()); } { diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 590ce2b0e..060da66f7 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -88,7 +88,7 @@ private: checkUnusedFunctions.parseTokens(tokenizer, "someFile.c", &settings); // check() returns error if and only if errout is not empty. if ((checkUnusedFunctions.check)(this, settings)) { - ASSERT(errout.str() != ""); + ASSERT(!errout.str().empty()); } else { ASSERT_EQUALS("", errout.str()); }