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

Function checkEvaluationOrderC

lib/checkother.cpp:3794–3815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3792}
3793
3794static bool checkEvaluationOrderC(const Token * tok, const Token * tok2, const Token * parent, const Settings & settings, bool & selfAssignmentError)
3795{
3796 // self assignment..
3797 if (tok2 == tok && tok->str() == "=" && parent->str() == "=" && isSameExpression(false, tok->astOperand1(), parent->astOperand1(), settings, true, false)) {
3798 if (settings.severity.isEnabled(Severity::warning) && isSameExpression(true, tok->astOperand1(), parent->astOperand1(), settings, true, false))
3799 selfAssignmentError = true;
3800 return false;
3801 }
3802 // Is expression used?
3803 bool foundError = false;
3804 visitAstNodes((parent->astOperand1() != tok2) ? parent->astOperand1() : parent->astOperand2(), [&](const Token *tok3) {
3805 if (tok3->str() == "&" && !tok3->astOperand2())
3806 return ChildrenToVisit::none; // don't handle address-of for now
3807 if (tok3->str() == "(" && Token::simpleMatch(tok3->previous(), "sizeof"))
3808 return ChildrenToVisit::none; // don't care about sizeof usage
3809 if (isSameExpression(false, tok->astOperand1(), tok3, settings, true, false))
3810 foundError = true;
3811 return foundError ? ChildrenToVisit::done : ChildrenToVisit::op1_and_op2;
3812 });
3813
3814 return foundError;
3815}
3816
3817static bool checkEvaluationOrderCpp11(const Token * tok, const Token * tok2, const Token * parent, const Settings & settings)
3818{

Callers 1

checkEvaluationOrderMethod · 0.85

Calls 7

isSameExpressionFunction · 0.85
visitAstNodesFunction · 0.85
astOperand1Method · 0.80
astOperand2Method · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45
isEnabledMethod · 0.45

Tested by

no test coverage detected