Skip to content

Commit b7da13c

Browse files
committed
commutative operators
1 parent ca039ab commit b7da13c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,8 +1609,15 @@ namespace {
16091609
key.operand1 = op1 ? (i1 >= refs1.size() ? op1->exprId() : refs1[i1].token->exprId()) : 0;
16101610
key.operand2 = op2 ? (i2 >= refs2.size() ? op2->exprId() : refs2[i2].token->exprId()) : 0;
16111611

1612-
if (key.operand1 > key.operand2 && key.operand2 && key.parentOp == "+")
1613-
std::swap(key.operand1, key.operand2);
1612+
if (key.operand1 > key.operand2 && key.operand2 &&
1613+
Token::Match(tok->astParent(), "%or%|%oror%|+|*|&|&&|^|==|!=")) {
1614+
// In C++ the order of operands of + might matter
1615+
if (key.parentOp != "+" ||
1616+
!tok->astParent()->valueType() ||
1617+
tok->astParent()->valueType()->isIntegral() ||
1618+
tok->astParent()->valueType()->isFloat())
1619+
std::swap(key.operand1, key.operand2);
1620+
}
16141621

16151622
const auto it = exprIdMap.find(key);
16161623
if (it == exprIdMap.end()) {

0 commit comments

Comments
 (0)