Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/signalhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
killid = getpid();
#endif

const auto it = utils::as_const(listofsignals).find(signo);
const auto it = listofsignals.find(signo);
const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str();
bool unexpectedSignal=true; // unexpected indicates program failure
bool terminate=true; // exit process/thread
Expand Down
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ void CheckLeakAutoVar::leakIfAllocated(const Token *vartok,
const std::map<int, VarInfo::AllocInfo> &alloctype = varInfo.alloctype;
const auto& possibleUsage = varInfo.possibleUsage;

const auto var = utils::as_const(alloctype).find(vartok->varId());
const auto var = alloctype.find(vartok->varId());
if (var != alloctype.cend() && var->second.status == VarInfo::ALLOC) {
const auto use = possibleUsage.find(vartok->varId());
if (use == possibleUsage.end()) {
Expand Down
4 changes: 2 additions & 2 deletions lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<nonneg i
if (tok->isName() || tok->str() == ".") {
while (tok && tok->str() == ".")
tok = tok->astOperand2();
const auto it = utils::as_const(variableValue).find(tok ? tok->varId() : ~0U);
const auto it = variableValue.find(tok ? tok->varId() : ~0U);
if (it != variableValue.end()) {
*alwaysTrue = (it->second != 0LL);
*alwaysFalse = (it->second == 0LL);
Expand All @@ -330,7 +330,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<nonneg i
while (vartok && vartok->str() == ".")
vartok = vartok->astOperand2();

const auto it = utils::as_const(variableValue).find(vartok ? vartok->varId() : ~0U);
const auto it = variableValue.find(vartok ? vartok->varId() : ~0U);
if (it == variableValue.end())
return;

Expand Down
2 changes: 1 addition & 1 deletion lib/ctu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static bool findPath(const std::string &callId,
if (index >= maxCtuDepth)
return false; // TODO: add bailout message?

const auto it = utils::as_const(callsMap).find(callId);
const auto it = callsMap.find(callId);
if (it == callsMap.end())
return false;

Expand Down
6 changes: 3 additions & 3 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Library::LibraryData
{
struct Platform {
const PlatformType *platform_type(const std::string &name) const {
const auto it = utils::as_const(mPlatformTypes).find(name);
const auto it = mPlatformTypes.find(name);
return (it != mPlatformTypes.end()) ? &(it->second) : nullptr;
}
std::map<std::string, PlatformType> mPlatformTypes;
Expand Down Expand Up @@ -1323,10 +1323,10 @@ const Library::ArgumentChecks * Library::getarg(const Token *ftok, int argnr) co
const Function* func = nullptr;
if (isNotLibraryFunction(ftok, &func))
return nullptr;
const auto it2 = utils::as_const(func->argumentChecks).find(argnr);
const auto it2 = func->argumentChecks.find(argnr);
if (it2 != func->argumentChecks.cend())
return &it2->second;
const auto it3 = utils::as_const(func->argumentChecks).find(-1);
const auto it3 = func->argumentChecks.find(-1);
if (it3 != func->argumentChecks.cend())
return &it3->second;
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions lib/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,21 @@ class CPPCHECKLIB Library {
bool startPatternHasStd{};

Action getAction(const std::string& function) const {
const auto i = utils::as_const(functions).find(function);
const auto i = functions.find(function);
if (i != functions.end())
return i->second.action;
return Action::NO_ACTION;
}

Yield getYield(const std::string& function) const {
const auto i = utils::as_const(functions).find(function);
const auto i = functions.find(function);
if (i != functions.end())
return i->second.yield;
return Yield::NO_YIELD;
}

const std::string& getReturnType(const std::string& function) const {
const auto i = utils::as_const(functions).find(function);
const auto i = functions.find(function);
return (i != functions.end()) ? i->second.returnType : mEmptyString;
}

Expand Down Expand Up @@ -482,7 +482,7 @@ class CPPCHECKLIB Library {
std::string getFunctionName(const Token *ftok, bool &error) const;

static const AllocFunc* getAllocDealloc(const std::map<std::string, AllocFunc> &data, const std::string &name) {
const auto it = utils::as_const(data).find(name);
const auto it = data.find(name);
return (it == data.end()) ? nullptr : &it->second;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress
}
const picojson::object& obj = json.get<picojson::object>();
{
const auto it = utils::as_const(obj).find("productName");
const auto it = obj.find("productName");
if (it != obj.cend()) {
const auto& v = it->second;
if (!v.is<std::string>())
Expand All @@ -118,7 +118,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress
}
}
{
const auto it = utils::as_const(obj).find("manualUrl");
const auto it = obj.find("manualUrl");
if (it != obj.cend()) {
const auto& v = it->second;
if (!v.is<std::string>())
Expand All @@ -127,7 +127,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress
}
}
{
const auto it = utils::as_const(obj).find("about");
const auto it = obj.find("about");
if (it != obj.cend()) {
const auto& v = it->second;
if (!v.is<std::string>())
Expand All @@ -136,7 +136,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress
}
}
{
const auto it = utils::as_const(obj).find("addons");
const auto it = obj.find("addons");
if (it != obj.cend()) {
const auto& entry = it->second;
if (!entry.is<picojson::array>())
Expand All @@ -154,7 +154,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress
}
}
{
const auto it = utils::as_const(obj).find("suppressions");
const auto it = obj.find("suppressions");
if (it != obj.cend()) {
const auto& entry = it->second;
if (!entry.is<picojson::array>())
Expand All @@ -171,7 +171,7 @@ std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppress
}
}
{
const auto it = utils::as_const(obj).find("safety");
const auto it = obj.find("safety");
if (it != obj.cend()) {
const auto& v = it->second;
if (!v.is<bool>())
Expand Down
16 changes: 8 additions & 8 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3860,7 +3860,7 @@ void SymbolDatabase::returnImplicitIntError(const Token *tok) const
const Function* Type::getFunction(const std::string& funcName) const
{
if (classScope) {
const auto it = utils::as_const(classScope->functionMap).find(funcName);
const auto it = classScope->functionMap.find(funcName);
if (it != classScope->functionMap.end())
return it->second;
}
Expand Down Expand Up @@ -4834,7 +4834,7 @@ std::vector<const Function*> Function::getOverloadedFunctions() const

while (scope) {
const bool isMemberFunction = scope->isClassOrStruct() && !isStatic();
for (auto it = utils::as_const(scope->functionMap).find(tokenDef->str());
for (auto it = scope->functionMap.find(tokenDef->str());
it != scope->functionMap.end() && it->first == tokenDef->str();
++it) {
const Function* func = it->second;
Expand Down Expand Up @@ -4885,7 +4885,7 @@ const Function * Function::getOverriddenFunctionRecursive(const ::Type* baseType
const Scope *parent = derivedFromType->classScope;

// check if function defined in base class
auto range = utils::as_const(parent->functionMap).equal_range(tokenDef->str());
auto range = parent->functionMap.equal_range(tokenDef->str());
for (auto it = range.first; it != range.second; ++it) {
const Function * func = it->second;
if (func->isImplicitlyVirtual()) { // Base is virtual and of same name
Expand Down Expand Up @@ -5832,7 +5832,7 @@ void Scope::findFunctionInBase(const Token* tok, nonneg int args, std::vector<co
if (base->classScope == this) // Ticket #5120, #5125: Recursive class; tok should have been found already
continue;

auto range = utils::as_const(base->classScope->functionMap).equal_range(tok->str());
auto range = base->classScope->functionMap.equal_range(tok->str());
for (auto it = range.first; it != range.second; ++it) {
const Function *func = it->second;
if (func->isDestructor() && !Token::simpleMatch(tok->tokAt(-1), "~"))
Expand Down Expand Up @@ -5994,7 +5994,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
const std::size_t args = arguments.size();

auto addMatchingFunctions = [&](const Scope *scope) {
auto range = utils::as_const(scope->functionMap).equal_range(tok->str());
auto range = scope->functionMap.equal_range(tok->str());
for (auto it = range.first; it != range.second; ++it) {
const Function *func = it->second;
if (ref == Reference::LValue && func->hasRvalRefQualifier())
Expand Down Expand Up @@ -6762,7 +6762,7 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n
const Function * function = nullptr;
const bool destructor = func->strAt(-1) == "~";

auto range = utils::as_const(ns->functionMap).equal_range(func->str());
auto range = ns->functionMap.equal_range(func->str());
for (auto it = range.first; it != range.second; ++it) {
if (it->second->argsMatch(ns, it->second->argDef, func->next(), path, path_length) &&
it->second->isDestructor() == destructor) {
Expand Down Expand Up @@ -7681,14 +7681,14 @@ static const Function *getOperatorFunction(const Token * const tok)

const Scope *classScope = getClassScope(tok->astOperand1());
if (classScope) {
auto it = utils::as_const(classScope->functionMap).find(functionName);
auto it = classScope->functionMap.find(functionName);
if (it != classScope->functionMap.end())
return it->second;
}

classScope = getClassScope(tok->astOperand2());
if (classScope) {
auto it = utils::as_const(classScope->functionMap).find(functionName);
auto it = classScope->functionMap.find(functionName);
if (it != classScope->functionMap.end())
return it->second;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Tokenizer::~Tokenizer()

nonneg int Tokenizer::sizeOfType(const std::string& type) const
{
const auto it = utils::as_const(mTypeSize).find(type);
const auto it = mTypeSize.find(type);
if (it == mTypeSize.end()) {
const Library::PodType* podtype = mSettings.library.podtype(type);
if (!podtype)
Expand All @@ -154,7 +154,7 @@ nonneg int Tokenizer::sizeOfType(const Token *type) const
if (type->tokType() == Token::eString)
return Token::getStrLength(type) + 1U;

const auto it = utils::as_const(mTypeSize).find(type->str());
const auto it = mTypeSize.find(type->str());
if (it == mTypeSize.end()) {
const Library::PodType* podtype = mSettings.library.podtype(type->str());
if (!podtype)
Expand Down Expand Up @@ -4629,7 +4629,7 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname,
if (Token::Match(tok2, "%name% ::"))
continue;

const auto it = utils::as_const(varlist).find(tok2->str());
const auto it = varlist.find(tok2->str());
if (it != varlist.end()) {
tok2->varId(it->second);
setVarIdStructMembers(tok2, structMembers, varId_);
Expand Down Expand Up @@ -7799,7 +7799,7 @@ bool Tokenizer::simplifyCAlternativeTokens()
if (!tok->isName())
continue;

const auto cOpIt = utils::as_const(cAlternativeTokens).find(tok->str());
const auto cOpIt = cAlternativeTokens.find(tok->str());
if (cOpIt != cAlternativeTokens.end()) {
alt.push_back(tok);

Expand Down Expand Up @@ -7841,7 +7841,7 @@ bool Tokenizer::simplifyCAlternativeTokens()
return false;

for (Token *tok: alt) {
const auto cOpIt = utils::as_const(cAlternativeTokens).find(tok->str());
const auto cOpIt = cAlternativeTokens.find(tok->str());
if (cOpIt != cAlternativeTokens.end())
tok->str(cOpIt->second);
else if (tok->str() == "not")
Expand Down Expand Up @@ -10442,7 +10442,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
if (tok->strAt(1) != "(")
continue;

const auto match = utils::as_const(apis).find(tok->str());
const auto match = apis.find(tok->str());
if (match!=apis.end()) {
tok->str(ansi ? match->second.mbcs : match->second.unicode);
tok->originalName(match->first);
Expand Down
1 change: 1 addition & 0 deletions lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ namespace utils {
template<class T>
constexpr typename std::add_const<T>::type & as_const(T& t) noexcept
{
static_assert(!std::is_const<T>::value, "object is already const");
// NOLINTNEXTLINE(bugprone-return-const-ref-from-parameter) - potential false positive
return t;
}
Expand Down
Loading