Skip to content

Commit ba1c24e

Browse files
IOBYTEdanmar
authored andcommitted
Fixed cppcheck-opensource#6422 (symbol database: put function flags into a single flag variable)
1 parent 2b018db commit ba1c24e

13 files changed

Lines changed: 328 additions & 154 deletions

lib/check64bit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void Check64BitPortability::pointerassignment()
5353
const std::size_t functions = symbolDatabase->functionScopes.size();
5454
for (std::size_t i = 0; i < functions; ++i) {
5555
const Scope * scope = symbolDatabase->functionScopes[i];
56-
if (scope->function == 0 || !scope->function->hasBody) // We only look for functions with a body
56+
if (scope->function == 0 || !scope->function->hasBody()) // We only look for functions with a body
5757
continue;
5858

5959
bool retPointer = false;

lib/checkassert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void CheckAssert::assertWithSideEffects()
4747
if (tmp->type() == Token::eFunction) {
4848
const Function* f = tmp->function();
4949

50-
if (f->nestedIn->isClassOrStruct() && !f->isStatic && !f->isConst)
50+
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst())
5151
sideEffectInAssertError(tmp, f->name()); // Non-const member function called
5252
else {
5353
const Scope* scope = f->functionScope;

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
367367
else if (arrayInfo.num().size() == 1) {
368368
const Function* const func = ftok.function();
369369

370-
if (func && func->hasBody) {
370+
if (func && func->hasBody()) {
371371
// Get corresponding parameter..
372372
const Variable* const parameter = func->getArgumentVar(par-1);
373373

lib/checkclass.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace {
5656

5757
inline bool isPureWithoutBody(Function const & func)
5858
{
59-
return func.isPure && !func.hasBody;
59+
return func.isPure() && !func.hasBody();
6060
}
6161
}
6262

@@ -120,8 +120,8 @@ void CheckClass::constructors()
120120
std::vector<Usage> usage(scope->varlist.size());
121121

122122
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
123-
if (!func->hasBody || !(func->isConstructor() ||
124-
func->type == Function::eOperatorEqual))
123+
if (!func->hasBody() || !(func->isConstructor() ||
124+
func->type == Function::eOperatorEqual))
125125
continue;
126126

127127
// Mark all variables not used
@@ -143,7 +143,7 @@ void CheckClass::constructors()
143143
if (usage[count].assign || usage[count].init || var->isStatic())
144144
continue;
145145

146-
if (var->isConst() && func->isOperator) // We can't set const members in assignment operator
146+
if (var->isConst() && func->isOperator()) // We can't set const members in assignment operator
147147
continue;
148148

149149
// Check if this is a class constructor
@@ -456,7 +456,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
456456
}
457457

458458
// member function has implementation
459-
if (member->hasBody) {
459+
if (member->hasBody()) {
460460
// initialize variable use list using member function
461461
callstack.push_back(member);
462462
initializeVarList(*member, callstack, scope, usage);
@@ -584,7 +584,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
584584
}
585585

586586
// member function has implementation
587-
if (member->hasBody) {
587+
if (member->hasBody()) {
588588
// initialize variable use list using member function
589589
callstack.push_back(member);
590590
initializeVarList(*member, callstack, scope, usage);
@@ -626,7 +626,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
626626
}
627627

628628
// member function has implementation
629-
if (member->hasBody) {
629+
if (member->hasBody()) {
630630
// initialize variable use list using member function
631631
callstack.push_back(member);
632632
initializeVarList(*member, callstack, scope, usage);
@@ -864,7 +864,7 @@ void CheckClass::privateFunctions()
864864
std::list<const Function*> privateFuncs;
865865
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
866866
// Get private functions..
867-
if (func->type == Function::eFunction && func->access == Private && !func->isOperator) // TODO: There are smarter ways to check private operator usage
867+
if (func->type == Function::eFunction && func->access == Private && !func->isOperator()) // TODO: There are smarter ways to check private operator usage
868868
privateFuncs.push_back(&*func);
869869
}
870870

@@ -1019,7 +1019,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
10191019
std::list<Function>::const_iterator func;
10201020

10211021
for (func = type->functionList.begin(); func != type->functionList.end(); ++func) {
1022-
if (func->isVirtual) {
1022+
if (func->isVirtual()) {
10231023
if (allocation)
10241024
mallocOnClassError(tok, tok->str(), type->classDef, "virtual method");
10251025
else
@@ -1119,7 +1119,7 @@ void CheckClass::operatorEq()
11191119
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
11201120
if (func->type == Function::eOperatorEqual && func->access == Public) {
11211121
// skip "deleted" functions - cannot be called anyway
1122-
if (func->isDelete)
1122+
if (func->isDelete())
11231123
continue;
11241124
// use definition for check so we don't have to deal with qualification
11251125
if (!(Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className)) {
@@ -1160,7 +1160,7 @@ void CheckClass::operatorEqRetRefThis()
11601160
std::list<Function>::const_iterator func;
11611161

11621162
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
1163-
if (func->type == Function::eOperatorEqual && func->hasBody) {
1163+
if (func->type == Function::eOperatorEqual && func->hasBody()) {
11641164
// make sure return signature is correct
11651165
if (Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className) {
11661166
checkReturnPtrThis(&(*scope), &(*func), func->functionScope->classStart, func->functionScope->classEnd);
@@ -1196,13 +1196,13 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
11961196
// check if it is a member function
11971197
for (it = scope->functionList.begin(); it != scope->functionList.end(); ++it) {
11981198
// check for a regular function with the same name and a body
1199-
if (it->type == Function::eFunction && it->hasBody &&
1199+
if (it->type == Function::eFunction && it->hasBody() &&
12001200
it->token->str() == tok->next()->str()) {
12011201
// check for the proper return type
12021202
if (it->tokenDef->previous()->str() == "&" &&
12031203
it->tokenDef->strAt(-2) == scope->className) {
12041204
// make sure it's not a const function
1205-
if (!it->isConst) {
1205+
if (!it->isConst()) {
12061206
/** @todo make sure argument types match */
12071207
// avoid endless recursions
12081208
if (analyzedFunctions.find(&*it) == analyzedFunctions.end()) {
@@ -1265,7 +1265,7 @@ void CheckClass::operatorEqToSelf()
12651265

12661266
std::list<Function>::const_iterator func;
12671267
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
1268-
if (func->type == Function::eOperatorEqual && func->hasBody) {
1268+
if (func->type == Function::eOperatorEqual && func->hasBody()) {
12691269
// make sure that the operator takes an object of the same type as *this, otherwise we can't detect self-assignment checks
12701270
if (func->argumentList.empty())
12711271
continue;
@@ -1381,10 +1381,10 @@ void CheckClass::virtualDestructor()
13811381
if (scope->definedType->derivedFrom.empty()) {
13821382
if (_settings->inconclusive) {
13831383
const Function *destructor = scope->getDestructor();
1384-
if (destructor && !destructor->isVirtual) {
1384+
if (destructor && !destructor->isVirtual()) {
13851385
std::list<Function>::const_iterator func;
13861386
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
1387-
if (func->isVirtual) {
1387+
if (func->isVirtual()) {
13881388
inconclusive_errors.push_back(destructor);
13891389
break;
13901390
}
@@ -1398,7 +1398,7 @@ void CheckClass::virtualDestructor()
13981398
const Function *destructor = scope->getDestructor();
13991399

14001400
// Check for destructor with implementation
1401-
if (!destructor || !destructor->hasBody)
1401+
if (!destructor || !destructor->hasBody())
14021402
continue;
14031403

14041404
// Empty destructor
@@ -1477,7 +1477,7 @@ void CheckClass::virtualDestructor()
14771477
if (found != inconclusive_errors.end())
14781478
inconclusive_errors.erase(found);
14791479
}
1480-
} else if (!base_destructor->isVirtual) {
1480+
} else if (!base_destructor->isVirtual()) {
14811481
// TODO: This is just a temporary fix, better solution is needed.
14821482
// Skip situations where base class has base classes of its own, because
14831483
// some of the base classes might have virtual destructor.
@@ -1564,7 +1564,7 @@ void CheckClass::checkConst()
15641564

15651565
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
15661566
// does the function have a body?
1567-
if (func->type == Function::eFunction && func->hasBody && !func->isFriend && !func->isStatic && !func->isVirtual) {
1567+
if (func->type == Function::eFunction && func->hasBody() && !func->isFriend() && !func->isStatic() && !func->isVirtual()) {
15681568
// get last token of return type
15691569
const Token *previous = func->tokenDef->previous();
15701570

@@ -1586,7 +1586,7 @@ void CheckClass::checkConst()
15861586

15871587
if (!foundConst)
15881588
continue;
1589-
} else if (func->isOperator && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
1589+
} else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
15901590
const std::string& opName = func->tokenDef->str();
15911591
if (opName.compare(8, 5, "const") != 0 && opName[opName.size()-1] == '&')
15921592
continue;
@@ -1621,11 +1621,11 @@ void CheckClass::checkConst()
16211621
else if (func->tokenDef->str() == "[")
16221622
functionName += "]";
16231623

1624-
if (!func->isConst || (!memberAccessed && !func->isOperator)) {
1625-
if (func->isInline)
1626-
checkConstError(func->token, classname, functionName, !memberAccessed && !func->isOperator);
1624+
if (!func->isConst() || (!memberAccessed && !func->isOperator())) {
1625+
if (func->isInline())
1626+
checkConstError(func->token, classname, functionName, !memberAccessed && !func->isOperator());
16271627
else // not inline
1628-
checkConstError2(func->token, func->tokenDef, classname, functionName, !memberAccessed && !func->isOperator);
1628+
checkConstError2(func->token, func->tokenDef, classname, functionName, !memberAccessed && !func->isOperator());
16291629
}
16301630
}
16311631
}
@@ -1688,7 +1688,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
16881688
bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const
16891689
{
16901690
if (tok->function() && tok->function()->nestedIn == scope)
1691-
return !tok->function()->isStatic;
1691+
return !tok->function()->isStatic();
16921692

16931693
// not found in this class
16941694
if (!scope->definedType->derivedFrom.empty()) {
@@ -1711,7 +1711,7 @@ bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const
17111711
bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
17121712
{
17131713
if (tok->function() && tok->function()->nestedIn == scope)
1714-
return tok->function()->isConst;
1714+
return tok->function()->isConst();
17151715

17161716
// not found in this class
17171717
if (!scope->definedType->derivedFrom.empty()) {
@@ -1919,7 +1919,7 @@ void CheckClass::initializerListOrder()
19191919

19201920
// iterate through all member functions looking for constructors
19211921
for (func = info->functionList.begin(); func != info->functionList.end(); ++func) {
1922-
if ((func->isConstructor()) && func->hasBody) {
1922+
if ((func->isConstructor()) && func->hasBody()) {
19231923
// check for initializer list
19241924
const Token *tok = func->arg->link()->next();
19251925

@@ -2015,7 +2015,7 @@ void CheckClass::checkPureVirtualFunctionCall()
20152015
std::map<const Function *, std::list<const Token *> > callsPureVirtualFunctionMap;
20162016
for (std::size_t i = 0; i < functions; ++i) {
20172017
const Scope * scope = symbolDatabase->functionScopes[i];
2018-
if (scope->function == 0 || !scope->function->hasBody ||
2018+
if (scope->function == 0 || !scope->function->hasBody() ||
20192019
!(scope->function->isConstructor() ||
20202020
scope->function->isDestructor()))
20212021
continue;
@@ -2041,7 +2041,7 @@ const std::list<const Token *> & CheckClass::callsPureVirtualFunction(const Func
20412041
callsPureVirtualFunctionMap.insert(std::pair<const Function *, std::list< const Token *> >(&function, std::list<const Token *>()));
20422042
std::list<const Token *> & pureFunctionCalls = found.first->second;
20432043
if (found.second) {
2044-
if (function.hasBody) {
2044+
if (function.hasBody()) {
20452045
for (const Token *tok = function.arg->link();
20462046
tok && tok != function.functionScope->classEnd;
20472047
tok = tok->next()) {

lib/checkcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ void CheckCondition::oppositeInnerCondition()
429429
if (tok->variable() &&
430430
Token::Match(tok, "%var% . %var% (") &&
431431
!tok->variable()->isConst() &&
432-
!(tok->tokAt(2)->function() && tok->tokAt(2)->function()->isConst))
432+
!(tok->tokAt(2)->function() && tok->tokAt(2)->function()->isConst()))
433433
break;
434434
if (Token::Match(tok->previous(), "[(,] %var% [,)]")) {
435435
// is variable unchanged? default is false..

lib/checkexceptionsafety.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ static const Token * functionThrowsRecursive(const Function * function, std::set
206206
} else if (tok->function()) {
207207
const Function * called = tok->function();
208208
// check if called function has an exception specification
209-
if (called->isThrow && called->throwArg) {
209+
if (called->isThrow() && called->throwArg) {
210210
return tok;
211-
} else if (called->isNoExcept && called->noexceptArg &&
211+
} else if (called->isNoExcept() && called->noexceptArg &&
212212
called->noexceptArg->str() != "true") {
213213
return tok;
214214
} else if (functionThrowsRecursive(called, recursive)) {
@@ -244,15 +244,15 @@ void CheckExceptionSafety::nothrowThrows()
244244
continue;
245245

246246
// check noexcept functions
247-
if (function->isNoExcept &&
247+
if (function->isNoExcept() &&
248248
(!function->noexceptArg || function->noexceptArg->str() == "true")) {
249249
const Token *throws = functionThrows(function);
250250
if (throws)
251251
noexceptThrowError(throws);
252252
}
253253

254254
// check throw() functions
255-
else if (function->isThrow && !function->throwArg) {
255+
else if (function->isThrow() && !function->throwArg) {
256256
const Token *throws = functionThrows(function);
257257
if (throws)
258258
nothrowThrowError(throws);
@@ -288,7 +288,7 @@ void CheckExceptionSafety::unhandledExceptionSpecification()
288288
for (std::size_t i = 0; i < functions; ++i) {
289289
const Scope * scope = symbolDatabase->functionScopes[i];
290290
// only check functions without exception epecification
291-
if (scope->function && !scope->function->isThrow &&
291+
if (scope->function && !scope->function->isThrow() &&
292292
scope->className != "main" && scope->className != "wmain" &&
293293
scope->className != "_tmain" && scope->className != "WinMain") {
294294
for (const Token *tok = scope->function->functionScope->classStart->next();
@@ -298,7 +298,7 @@ void CheckExceptionSafety::unhandledExceptionSpecification()
298298
} else if (tok->function()) {
299299
const Function * called = tok->function();
300300
// check if called function has an exception specification
301-
if (called->isThrow && called->throwArg) {
301+
if (called->isThrow() && called->throwArg) {
302302
unhandledExceptionSpecificationError(tok, called->tokenDef, scope->function->name());
303303
break;
304304
}

lib/checkmemoryleak.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void CheckMemoryLeak::mismatchAllocDealloc(const std::list<const Token *> &calls
397397

398398
CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* func, std::list<const Function*> *callstack) const
399399
{
400-
if (!func || !func->hasBody)
400+
if (!func || !func->hasBody())
401401
return No;
402402

403403
// Get return pointer..
@@ -597,7 +597,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
597597
// lock/unlock..
598598
if (varid == 0) {
599599
const Function* func = tok->function();
600-
if (!func || !func->hasBody)
600+
if (!func || !func->hasBody())
601601
return 0;
602602

603603
Token *ftok = getcode(func->functionScope->classStart->next(), callstack, 0, alloctype, dealloctype, false, 1);
@@ -2317,7 +2317,7 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
23172317
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
23182318
const bool constructor = func->isConstructor();
23192319
const bool destructor = func->isDestructor();
2320-
if (!func->hasBody) {
2320+
if (!func->hasBody()) {
23212321
if (destructor) { // implementation for destructor is not seen => assume it deallocates all variables properly
23222322
deallocInDestructor = true;
23232323
Dealloc = CheckMemoryLeak::Many;
@@ -2445,7 +2445,7 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Scope *scope, const Toke
24452445

24462446
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
24472447
if ((func->type == Function::eFunction || func->type == Function::eOperatorEqual) &&
2448-
func->access == Public && func->hasBody) {
2448+
func->access == Public && func->hasBody()) {
24492449
const Token *tok2 = func->token;
24502450
while (tok2->str() != "{")
24512451
tok2 = tok2->next();

0 commit comments

Comments
 (0)