diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 084f1cb18..1908be260 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -1005,7 +1005,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) } if (!settings.checkConfiguration) { - cppcheck.tooManyConfigsError("",0U); + cppcheck.tooManyConfigsError(emptyString,0U); if (settings.checks.isEnabled(Checks::missingInclude) && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) { const std::list callStack; diff --git a/lib/analyzer.h b/lib/analyzer.h index 39deb6049..09fa98165 100644 --- a/lib/analyzer.h +++ b/lib/analyzer.h @@ -179,7 +179,7 @@ struct Analyzer { /// The condition that will be assumed during analysis virtual void assume(const Token* tok, bool state, unsigned int flags = 0) = 0; /// Return analyzer for expression at token - virtual ValuePtr reanalyze(Token* tok, const std::string& msg = "") const = 0; + virtual ValuePtr reanalyze(Token* tok, const std::string& msg = emptyString) const = 0; virtual ~Analyzer() {} }; diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index 638eeb22d..c5ebd9df0 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -95,7 +95,7 @@ public: void nullPointerError(const Token *tok) { ValueFlow::Value v(0); v.setKnown(); - nullPointerError(tok, "", &v, false); + nullPointerError(tok, emptyString, &v, false); } void nullPointerError(const Token *tok, const std::string &varname, const ValueFlow::Value* value, bool inconclusive); diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 39c3ff06b..5f77ff319 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3756,6 +3756,6 @@ void CheckOther::overlappingWriteUnion(const Token *tok) void CheckOther::overlappingWriteFunction(const Token *tok) { - const std::string funcname = tok ? tok->str() : ""; + const std::string &funcname = tok ? tok->str() : emptyString; reportError(tok, Severity::error, "overlappingWriteFunction", "Overlapping read/write in " + funcname + "() is undefined behavior"); } diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index fdf0bf5f6..e65743f23 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -191,7 +191,7 @@ void CheckStl::outOfBounds() } } -static std::string indexValueString(const ValueFlow::Value& indexValue, const std::string& containerName = "") +static std::string indexValueString(const ValueFlow::Value& indexValue, const std::string& containerName = emptyString) { if (indexValue.isIteratorStartValue()) return "at position " + MathLib::toString(indexValue.intvalue) + " from the beginning"; @@ -2342,7 +2342,7 @@ void CheckStl::checkDereferenceInvalidIterator2() outOfBoundsError(emptyAdvance, lValue.tokvalue->expressionString(), cValue, - advanceIndex ? advanceIndex->expressionString() : "", + advanceIndex ? advanceIndex->expressionString() : emptyString, nullptr); else outOfBoundsError(tok, lValue.tokvalue->expressionString(), cValue, tok->expressionString(), &value); @@ -2797,7 +2797,7 @@ void CheckStl::knownEmptyContainer() const Token* contTok = splitTok->astOperand2(); if (!isKnownEmptyContainer(contTok)) continue; - knownEmptyContainerError(contTok, ""); + knownEmptyContainerError(contTok, emptyString); } else { const std::vector args = getArguments(tok); if (args.empty()) diff --git a/lib/checkstl.h b/lib/checkstl.h index fc691150b..2bb7b80a5 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -268,8 +268,8 @@ private: c.uselessCallsRemoveError(nullptr, "remove"); c.dereferenceInvalidIteratorError(nullptr, "i"); c.readingEmptyStlContainerError(nullptr); - c.useStlAlgorithmError(nullptr, ""); - c.knownEmptyContainerError(nullptr, ""); + c.useStlAlgorithmError(nullptr, emptyString); + c.knownEmptyContainerError(nullptr, emptyString); c.globalLockGuardError(nullptr); c.localMutexError(nullptr); } diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index a0db23c49..8270b2bdd 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -636,7 +636,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var // Assert that the tokens are '} while (' if (!Token::simpleMatch(tok, "} while (")) { if (printDebug) - reportError(tok,Severity::debug,"","assertion failed '} while ('"); + reportError(tok,Severity::debug,emptyString,"assertion failed '} while ('"); break; } diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 0dfd6fbdb..cdacab5be 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -232,7 +232,7 @@ static std::string getDumpFileName(const Settings& settings, const std::string& if (!settings.dumpFile.empty()) return settings.dumpFile; if (!settings.dump && !settings.buildDir.empty()) - return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, filename, "") + ".dump"; + return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, filename, emptyString) + ".dump"; return filename + ".dump"; } @@ -432,7 +432,7 @@ unsigned int CppCheck::check(const std::string &path) mErrorLogger.reportOut(std::string("Checking ") + path + "...", Color::FgGreen); const std::string lang = Path::isCPP(path) ? "-x c++" : "-x c"; - const std::string analyzerInfo = mSettings.buildDir.empty() ? std::string() : AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, ""); + const std::string analyzerInfo = mSettings.buildDir.empty() ? std::string() : AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, emptyString); const std::string clangcmd = analyzerInfo + ".clang-cmd"; const std::string clangStderr = analyzerInfo + ".clang-stderr"; const std::string clangAst = analyzerInfo + ".clang-ast"; @@ -1586,10 +1586,10 @@ void CppCheck::getErrorMessages() s.severity.enable(Severity::performance); s.severity.enable(Severity::information); - purgedConfigurationMessage("",""); + purgedConfigurationMessage(emptyString,emptyString); mTooManyConfigs = true; - tooManyConfigsError("",0U); + tooManyConfigsError(emptyString,0U); // call all "getErrorMessages" in all registered Check classes for (std::list::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) @@ -1615,7 +1615,7 @@ void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings) const std::string args = "-quiet -checks=*,-clang-analyzer-*,-llvm* \"" + fileSettings.filename + "\" -- " + allIncludes + allDefines; std::string output; - if (!mExecuteCommand(exe, split(args), "", &output)) { + if (!mExecuteCommand(exe, split(args), emptyString, &output)) { std::cerr << "Failed to execute '" << exe << "'" << std::endl; return; } @@ -1625,7 +1625,7 @@ void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings) std::string line; if (!mSettings.buildDir.empty()) { - const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.filename, ""); + const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.filename, emptyString); std::ofstream fcmd(analyzerInfoFile + ".clang-tidy-cmd"); fcmd << istr.str(); } diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 179e7e4fc..ad927a59e 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -1183,7 +1183,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti suppressions.push_back(s); } } else if (strcmp(node->Name(), CppcheckXml::VSConfigurationElementName) == 0) - guiProject.checkVsConfigs = readXmlStringList(node, "", CppcheckXml::VSConfigurationName, nullptr); + guiProject.checkVsConfigs = readXmlStringList(node, emptyString, CppcheckXml::VSConfigurationName, nullptr); else if (strcmp(node->Name(), CppcheckXml::PlatformElementName) == 0) guiProject.platform = node->GetText(); else if (strcmp(node->Name(), CppcheckXml::AnalyzeAllVsConfigsElementName) == 0) @@ -1191,11 +1191,11 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti else if (strcmp(node->Name(), CppcheckXml::Parser) == 0) temp.clang = true; else if (strcmp(node->Name(), CppcheckXml::AddonsElementName) == 0) - temp.addons = readXmlStringList(node, "", CppcheckXml::AddonElementName, nullptr); + temp.addons = readXmlStringList(node, emptyString, CppcheckXml::AddonElementName, nullptr); else if (strcmp(node->Name(), CppcheckXml::TagsElementName) == 0) node->Attribute(CppcheckXml::TagElementName); // FIXME: Write some warning else if (strcmp(node->Name(), CppcheckXml::ToolsElementName) == 0) { - const std::list toolList = readXmlStringList(node, "", CppcheckXml::ToolElementName, nullptr); + const std::list toolList = readXmlStringList(node, emptyString, CppcheckXml::ToolElementName, nullptr); for (const std::string &toolName : toolList) { if (toolName == std::string(CppcheckXml::ClangTidy)) temp.clangTidy = true; diff --git a/lib/library.h b/lib/library.h index f05c00990..01032613d 100644 --- a/lib/library.h +++ b/lib/library.h @@ -550,7 +550,7 @@ public: */ std::string getFunctionName(const Token *ftok) const; - static bool isContainerYield(const Token * const cond, Library::Container::Yield y, const std::string& fallback=""); + static bool isContainerYield(const Token * const cond, Library::Container::Yield y, const std::string& fallback=emptyString); /** Suppress/check a type */ enum class TypeCheck { def, check, suppress }; diff --git a/lib/path.cpp b/lib/path.cpp index b76ebaa88..b61d1e909 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -128,7 +128,7 @@ std::string Path::getCurrentPath() #endif return std::string(currentPath); - return emptyString; + return ""; } bool Path::isAbsolute(const std::string& path) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c6bdb9dca..8ac5241b8 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -489,7 +489,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set } else if (cmdtok->str() == "error") { if (!configs_ifndef.empty() && !configs_ifndef.back().empty()) { if (configs_ifndef.size() == 1U) - ret.erase(""); + ret.erase(emptyString); std::vector configs(configs_if); configs.push_back(configs_ifndef.back()); ret.erase(cfg(configs, userDefines)); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 2033349ee..00c0b2005 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5548,7 +5548,7 @@ const Type* Scope::findType(const std::string & name) const return (*it).second; // is type defined in anonymous namespace.. - it = definedTypesMap.find(""); + it = definedTypesMap.find(emptyString); if (it != definedTypesMap.end()) { for (const Scope *scope : nestedList) { if (scope->className.empty() && (scope->type == eNamespace || scope->isClassOrStructOrUnion())) { diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 107ad43c1..bffb216bd 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -961,11 +961,11 @@ void TemplateSimplifier::getTemplateInstantiations() std::string::size_type offset = 0; std::string::size_type pos = 0; while ((pos = nameSpace.substr(offset).find(' ')) != std::string::npos) { - qualificationTok->insertToken(nameSpace.substr(offset, pos), "", true); + qualificationTok->insertToken(nameSpace.substr(offset, pos), emptyString, true); offset = offset + pos + 1; } - qualificationTok->insertToken(nameSpace.substr(offset), "", true); - qualificationTok->insertToken("::", "", true); + qualificationTok->insertToken(nameSpace.substr(offset), emptyString, true); + qualificationTok->insertToken("::", emptyString, true); addInstantiation(tok, it1->scope()); found = true; break; @@ -1530,7 +1530,7 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c } } else { if (insert) - mTokenList.back()->tokAt(offset)->insertToken(token, ""); + mTokenList.back()->tokAt(offset)->insertToken(token, emptyString); else mTokenList.addtoken(token, tok->linenr(), tok->column(), tok->fileIndex()); } @@ -1541,10 +1541,10 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c if (token != tokStart->str() || tok->strAt(-1) != "::") { if (insert) { if (!inTemplate) - mTokenList.back()->tokAt(offset)->insertToken(templateDeclaration.scope().substr(start), ""); + mTokenList.back()->tokAt(offset)->insertToken(templateDeclaration.scope().substr(start), emptyString); else mTokenList.back()->tokAt(offset)->str(mTokenList.back()->strAt(offset) + templateDeclaration.scope().substr(start)); - mTokenList.back()->tokAt(offset)->insertToken("::", ""); + mTokenList.back()->tokAt(offset)->insertToken("::", emptyString); } else { if (!inTemplate) mTokenList.addtoken(templateDeclaration.scope().substr(start), tok->linenr(), tok->column(), tok->fileIndex()); @@ -1596,9 +1596,9 @@ void TemplateSimplifier::expandTemplate( // add forward declarations if (copy && isClass) { - templateDeclaration.token()->insertToken(templateDeclarationToken->strAt(1), "", true); - templateDeclaration.token()->insertToken(newName, "", true); - templateDeclaration.token()->insertToken(";", "", true); + templateDeclaration.token()->insertToken(templateDeclarationToken->strAt(1), emptyString, true); + templateDeclaration.token()->insertToken(newName, emptyString, true); + templateDeclaration.token()->insertToken(";", emptyString, true); } else if ((isFunction && (copy || isSpecialization)) || (isVariable && !isSpecialization) || (isClass && isSpecialization && mTemplateSpecializationMap.find(templateDeclaration.token()) != mTemplateSpecializationMap.end())) { @@ -1662,7 +1662,7 @@ void TemplateSimplifier::expandTemplate( } if (isStatic) { - dst->insertToken("static", "", true); + dst->insertToken("static", emptyString, true); if (start) { dst->previous()->linenr(start->linenr()); dst->previous()->column(start->column()); @@ -1745,13 +1745,13 @@ void TemplateSimplifier::expandTemplate( !(templateDeclaration.isFunction() && templateDeclaration.scope().empty() && (start->strAt(-1) == "." || Token::simpleMatch(start->tokAt(-2), ". template")))) { if (start->strAt(1) != "<" || Token::Match(start, newName.c_str()) || !inAssignment) { - dst->insertToken(newName, "", true); + dst->insertToken(newName, emptyString, true); dst->previous()->linenr(start->linenr()); dst->previous()->column(start->column()); if (start->strAt(1) == "<") start = start->next()->findClosingBracket(); } else { - dst->insertToken(start->str(), "", true); + dst->insertToken(start->str(), emptyString, true); dst->previous()->linenr(start->linenr()); dst->previous()->column(start->column()); newInstantiations.emplace_back(dst->previous(), templateDeclaration.scope()); @@ -1774,7 +1774,7 @@ void TemplateSimplifier::expandTemplate( for (const auto & inst : mTemplateInstantiations) { if (Token::simpleMatch(inst.token(), name.c_str(), name.size())) { // use the instantiated name - dst->insertToken(name, "", true); + dst->insertToken(name, emptyString, true); dst->previous()->linenr(start->linenr()); dst->previous()->column(start->column()); start = closing; @@ -1820,7 +1820,7 @@ void TemplateSimplifier::expandTemplate( start = start->next(); } - dst->insertToken(";", "", true); + dst->insertToken(";", emptyString, true); dst->previous()->linenr(dst->tokAt(-2)->linenr()); dst->previous()->column(dst->tokAt(-2)->column() + 1); diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 727f5f81b..f48bc308d 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -485,7 +485,7 @@ private: void printOut( const TokenAndName &tokenAndName, const std::string &indent = " ") const; - void printOut(const std::string &text = "") const; + void printOut(const std::string &text = emptyString) const; Tokenizer *mTokenizer; TokenList &mTokenList; diff --git a/lib/token.h b/lib/token.h index 739deaab9..df41141a8 100644 --- a/lib/token.h +++ b/lib/token.h @@ -715,12 +715,12 @@ public: } bool isCChar() const { - return (((mTokType == eString) && isPrefixStringCharLiteral(mStr, '"', "")) || - ((mTokType == eChar) && isPrefixStringCharLiteral(mStr, '\'', "") && mStr.length() == 3)); + return (((mTokType == eString) && isPrefixStringCharLiteral(mStr, '"', emptyString)) || + ((mTokType == eChar) && isPrefixStringCharLiteral(mStr, '\'', emptyString) && mStr.length() == 3)); } bool isCMultiChar() const { - return (((mTokType == eChar) && isPrefixStringCharLiteral(mStr, '\'', "")) && + return (((mTokType == eChar) && isPrefixStringCharLiteral(mStr, '\'', emptyString)) && (mStr.length() > 3)); } /** diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 406cc766a..2ee5b6b3b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2016,7 +2016,7 @@ namespace { } if (!added) - *scopeInfo = (*scopeInfo)->addChild(ScopeInfo3::Other, "", tok, tok->link()); + *scopeInfo = (*scopeInfo)->addChild(ScopeInfo3::Other, emptyString, tok, tok->link()); } return; } @@ -2371,7 +2371,7 @@ bool Tokenizer::simplifyUsing() structEnd = structEnd->link(); // add ';' after end of struct - structEnd->insertToken(";", ""); + structEnd->insertToken(";", emptyString); // add name for anonymous struct if (!hasName) { @@ -2381,8 +2381,8 @@ bool Tokenizer::simplifyUsing() else newName = "Unnamed" + MathLib::toString(mUnnamedCount++); TokenList::copyTokens(structEnd->next(), tok, start); - structEnd->tokAt(5)->insertToken(newName, ""); - start->insertToken(newName, ""); + structEnd->tokAt(5)->insertToken(newName, emptyString); + start->insertToken(newName, emptyString); } else TokenList::copyTokens(structEnd->next(), tok, start->next()); @@ -3336,7 +3336,7 @@ void Tokenizer::calculateScopes() tok->scopeInfo(nullptr); std::string nextScopeNameAddition; - std::shared_ptr primaryScope = std::make_shared("", nullptr); + std::shared_ptr primaryScope = std::make_shared(emptyString, nullptr); list.front()->scopeInfo(primaryScope); for (Token* tok = list.front(); tok; tok = tok->next()) { diff --git a/lib/tokenize.h b/lib/tokenize.h index b8992ef46..e96364098 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -442,7 +442,7 @@ private: public: /** Syntax error */ - NORETURN void syntaxError(const Token *tok, const std::string &code = "") const; + NORETURN void syntaxError(const Token *tok, const std::string &code = emptyString) const; /** Syntax error. Unmatched character. */ NORETURN void unmatchedToken(const Token *tok) const; diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 4c03bab41..3decc2425 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -512,7 +512,7 @@ int main(int argc, char **argv) compilefiles(fout, libfiles, "${INCLUDE_FOR_LIB}"); compilefiles(fout, clifiles, "${INCLUDE_FOR_CLI}"); compilefiles(fout, testfiles, "${INCLUDE_FOR_TEST}"); - compilefiles(fout, extfiles, ""); + compilefiles(fout, extfiles, emptyString); compilefiles(fout, toolsfiles, "${INCLUDE_FOR_LIB}"); return 0;