MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isMemberVariableUsage

Method isMemberVariableUsage

lib/checkuninitvar.cpp:1511–1551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1509}
1510
1511bool CheckUninitVarImpl::isMemberVariableUsage(const Token *tok, bool isPointer, Alloc alloc, const std::string &membervar) const
1512{
1513 if (Token::Match(tok->previous(), "[(,] %name% . %name% [,)]") &&
1514 tok->strAt(2) == membervar) {
1515 const int use = isFunctionParUsage(tok, isPointer, alloc);
1516 if (use == 1)
1517 return true;
1518 }
1519
1520 if (isMemberVariableAssignment(tok, membervar))
1521 return false;
1522
1523 if (Token::Match(tok, "%name% . %name%") && tok->strAt(2) == membervar && !(tok->tokAt(-2)->variable() && tok->tokAt(-2)->variable()->isReference())) {
1524 const Token *parent = tok->next()->astParent();
1525 return !parent || !parent->isUnaryOp("&");
1526 }
1527 if (!isPointer && !Token::simpleMatch(tok->astParent(), ".") && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc))
1528 return true;
1529
1530 if (!isPointer && Token::Match(tok->previous(), "= %name% ;")) {
1531 const Token* lhs = tok->previous()->astOperand1();
1532 return !(lhs && lhs->variable() && lhs->variable()->isReference() && lhs == lhs->variable()->nameToken());
1533 }
1534
1535 // = *(&var);
1536 if (!isPointer &&
1537 Token::simpleMatch(tok->astParent(),"&") &&
1538 Token::simpleMatch(tok->astParent()->astParent(),"*") &&
1539 Token::Match(tok->astParent()->astParent()->astParent(), "= * (| &") &&
1540 tok->astParent()->astParent()->astParent()->astOperand2() == tok->astParent()->astParent())
1541 return true;
1542
1543 // TODO: this used to be experimental - enable or remove see #5586
1544 if ((false) && // NOLINT(readability-simplify-boolean-expr,readability-redundant-parentheses)
1545 !isPointer &&
1546 Token::Match(tok->tokAt(-2), "[(,] & %name% [,)]") &&
1547 isVariableUsage(tok, isPointer, alloc))
1548 return true;
1549
1550 return false;
1551}
1552
1553void CheckUninitVarImpl::uninitdataError(const Token *tok, const std::string &varname)
1554{

Callers

nothing calls this directly

Calls 10

isVariableUsageFunction · 0.85
variableMethod · 0.80
astParentMethod · 0.80
nextMethod · 0.80
isUnaryOpMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45
nameTokenMethod · 0.45

Tested by

no test coverage detected