Fixed #6935 (Wrong duplicate expression)
This commit is contained in:
parent
27f72d7ae0
commit
a574fda8a9
|
@ -267,6 +267,13 @@ bool isSameExpression(bool cpp, const Token *tok1, const Token *tok2, const std:
|
|||
commuative_equals = commuative_equals &&
|
||||
isSameExpression(cpp, tok1->astOperand1(), tok2->astOperand2(), constFunctions);
|
||||
|
||||
// in c++, "a"+b might be different to b+"a"
|
||||
if (cpp && commuative_equals && tok1->str() == "+" &&
|
||||
(tok1->astOperand1()->tokType() == Token::eString || tok1->astOperand2()->tokType() == Token::eString)) {
|
||||
const Token * const other = tok1->astOperand1()->tokType() != Token::eString ? tok1->astOperand1() : tok1->astOperand2();
|
||||
return other && astIsIntegral(other,false);
|
||||
}
|
||||
|
||||
return commuative_equals;
|
||||
}
|
||||
|
||||
|
|
|
@ -4194,6 +4194,11 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '|'.\n", errout.str());
|
||||
|
||||
check("void foo(std::string a, std::string b) {\n"
|
||||
" return a.find(b+\"&\") || a.find(\"&\"+b);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" if ((b > a) | (a > b)) {}\n" // > is not commutative
|
||||
"}");
|
||||
|
|
Loading…
Reference in New Issue