Small optimization in checkmemoryleak.cpp: Allow passing literals to addtoken()

Ran AStyle
This commit is contained in:
PKEuS 2018-05-14 10:15:50 +02:00
parent 7ef714b0c6
commit 4d549553b0
3 changed files with 22 additions and 22 deletions

View File

@ -426,42 +426,42 @@ bool isWithoutSideEffects(bool cpp, const Token* tok)
bool isUniqueExpression(const Token* tok)
{
if(!tok)
if (!tok)
return true;
if(tok->function()) {
if (tok->function()) {
const Function * fun = tok->function();
const Scope * scope = fun->nestedIn;
if(!scope)
if (!scope)
return true;
for(const Function& f:scope->functionList) {
if(f.argumentList.size() == fun->argumentList.size() && f.name() != fun->name()) {
for (const Function& f:scope->functionList) {
if (f.argumentList.size() == fun->argumentList.size() && f.name() != fun->name()) {
return false;
}
}
} else if(tok->variable()) {
} else if (tok->variable()) {
const Variable * var = tok->variable();
const Scope * scope = var->scope();
if(!scope)
if (!scope)
return true;
const Type * varType = var->type();
// Iterate over the variables in scope and the parameters of the function if possible
const Function * fun = scope->function;
const std::list<Variable>* setOfVars[] = {&scope->varlist, fun ? &fun->argumentList : nullptr};
if (varType) {
for(const std::list<Variable>* vars:setOfVars) {
if(!vars)
for (const std::list<Variable>* vars:setOfVars) {
if (!vars)
continue;
for(const Variable& v:*vars) {
for (const Variable& v:*vars) {
if (v.type() && v.type()->name() == varType->name() && v.name() != var->name()) {
return false;
}
}
}
} else {
for(const std::list<Variable>* vars:setOfVars) {
if(!vars)
for (const std::list<Variable>* vars:setOfVars) {
if (!vars)
continue;
for(const Variable& v:*vars) {
for (const Variable& v:*vars) {
if (v.isFloatingType() == var->isFloatingType() &&
v.isEnumType() == var->isEnumType() &&
v.isClass() == var->isClass() &&
@ -472,7 +472,7 @@ bool isUniqueExpression(const Token* tok)
}
}
}
} else if(!isUniqueExpression(tok->astOperand1())) {
} else if (!isUniqueExpression(tok->astOperand1())) {
return false;
}

View File

@ -671,8 +671,8 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
return (eq || _settings->experimental) ? nullptr : "callfunc";
}
static void addtoken(Token **rettail, const Token *tok, const std::string &str)
template<typename T>
static void addtoken(Token **rettail, const Token *tok, T&& str)
{
(*rettail)->insertToken(str);
(*rettail) = (*rettail)->next();

View File

@ -860,16 +860,16 @@ private:
void tokenize37() { // #8550
const char codeC[] = "class name { public: static void init ( ) {} } ; "
"typedef class name N; "
"void foo ( ) { return N :: init ( ) ; }";
"typedef class name N; "
"void foo ( ) { return N :: init ( ) ; }";
const char expC [] = "class name { public: static void init ( ) { } } ; "
"void foo ( ) { return name :: init ( ) ; }";
"void foo ( ) { return name :: init ( ) ; }";
ASSERT_EQUALS(expC, tokenizeAndStringify(codeC));
const char codeS[] = "class name { public: static void init ( ) {} } ; "
"typedef struct name N; "
"void foo ( ) { return N :: init ( ) ; }";
"typedef struct name N; "
"void foo ( ) { return N :: init ( ) ; }";
const char expS [] = "class name { public: static void init ( ) { } } ; "
"void foo ( ) { return name :: init ( ) ; }";
"void foo ( ) { return name :: init ( ) ; }";
ASSERT_EQUALS(expS, tokenizeAndStringify(codeS));
}