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

Function isVariableMutableInInitializer

lib/checkother.cpp:1642–1668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1640}
1641
1642static bool isVariableMutableInInitializer(const Token* start, const Token * end, nonneg int varid)
1643{
1644 if (!start)
1645 return false;
1646 if (!end)
1647 return false;
1648 for (const Token *tok = start; tok != end; tok = tok->next()) {
1649 if (tok->varId() != varid)
1650 continue;
1651 if (tok->astParent()) {
1652 const Token * memberTok = tok->astParent()->previous();
1653 if (Token::Match(memberTok, "%var% (") && memberTok->variable()) {
1654 const Variable * memberVar = memberTok->variable();
1655 if (memberVar->isClass())
1656 //TODO: check if the called constructor could live with a const variable
1657 // pending that, assume the worst (that it can't)
1658 return true;
1659 if (!memberVar->isReference())
1660 continue;
1661 if (memberVar->isConst())
1662 continue;
1663 }
1664 }
1665 return true;
1666 }
1667 return false;
1668}
1669
1670static bool isCastToVoid(const Variable* var)
1671{

Callers 1

checkConstVariableMethod · 0.85

Calls 5

nextMethod · 0.80
astParentMethod · 0.80
variableMethod · 0.80
isClassMethod · 0.80
isConstMethod · 0.80

Tested by

no test coverage detected