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

Function isUnreachableOperand

lib/astutils.cpp:3825–3859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3823}
3824
3825bool isUnreachableOperand(const Token *tok)
3826{
3827 for (;;)
3828 {
3829 const Token *parent = tok->astParent();
3830 if (!parent)
3831 break;
3832
3833 if (parent->isBinaryOp()) {
3834 const bool left = tok == parent->astOperand1();
3835 const Token *sibling = left ? parent->astOperand2() : parent->astOperand1();
3836
3837 // logical and
3838 if (Token::simpleMatch(parent, "&&") && !left && sibling->hasKnownIntValue()
3839 && !sibling->getKnownIntValue())
3840 return true;
3841
3842 // logical or
3843 if (Token::simpleMatch(parent, "||") && !left && sibling->hasKnownIntValue()
3844 && sibling->getKnownIntValue())
3845 return true;
3846
3847 // ternary
3848 if (Token::simpleMatch(parent, ":") && Token::simpleMatch(parent->astParent(), "?")) {
3849 const Token *condTok = parent->astParent()->astOperand1();
3850 if (condTok->hasKnownIntValue() && static_cast<bool>(condTok->getKnownIntValue()) != left)
3851 return true;
3852 }
3853 }
3854
3855 tok = parent;
3856 }
3857
3858 return false;
3859}
3860
3861static bool unknownLeafValuesAreTemplateArgs(const Token *tok)
3862{

Callers 2

pointerArithmeticMethod · 0.85

Calls 7

astParentMethod · 0.80
isBinaryOpMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
getKnownIntValueMethod · 0.80
simpleMatchFunction · 0.70
hasKnownIntValueMethod · 0.45

Tested by

no test coverage detected