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

Function isSameConstantValue

lib/astutils.cpp:1467–1495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1465}
1466
1467static inline bool isSameConstantValue(bool macro, const Token* tok1, const Token* tok2)
1468{
1469 if (tok1 == nullptr || tok2 == nullptr)
1470 return false;
1471
1472 auto adjustForCast = [](const Token* tok) {
1473 if (tok->astOperand2() && Token::Match(tok->previous(), "%type% (|{") && tok->previous()->isStandardType())
1474 return tok->astOperand2();
1475 return tok;
1476 };
1477
1478 tok1 = adjustForCast(tok1);
1479 if (!tok1->isNumber() && !tok1->enumerator())
1480 return false;
1481 tok2 = adjustForCast(tok2);
1482 if (!tok2->isNumber() && !tok2->enumerator())
1483 return false;
1484
1485 if (macro && (tok1->isExpandedMacro() || tok2->isExpandedMacro() || tok1->isTemplateArg() || tok2->isTemplateArg()))
1486 return false;
1487
1488 const ValueType * v1 = tok1->valueType();
1489 const ValueType * v2 = tok2->valueType();
1490
1491 if (!v1 || !v2 || v1->sign != v2->sign || v1->type != v2->type || v1->pointer != v2->pointer)
1492 return false;
1493
1494 return isEqualKnownValue(tok1, tok2);
1495}
1496
1497
1498static bool isForLoopCondition(const Token * const tok)

Callers 1

isSameExpressionFunction · 0.85

Calls 3

isEqualKnownValueFunction · 0.85
astOperand2Method · 0.80
isStandardTypeMethod · 0.45

Tested by

no test coverage detected