Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Format
  • Loading branch information
pfultz2 committed Sep 26, 2020
1 parent 1fc0ba3 commit 58e86ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 18 additions & 2 deletions lib/checkother.cpp
Expand Up @@ -2040,9 +2040,25 @@ void CheckOther::checkDuplicateExpression()
if (!assignTok->astOperand2())
continue;

if (assignTok->astOperand1()->varId() != var1->varId() && assignTok->astOperand1()->varId() != var2->varId() && !isSameExpression(mTokenizer->isCPP(), true, tok->astOperand2(), assignTok->astOperand1(), mSettings->library, true, true))
if (assignTok->astOperand1()->varId() != var1->varId() &&
assignTok->astOperand1()->varId() != var2->varId() &&
!isSameExpression(mTokenizer->isCPP(),
true,
tok->astOperand2(),
assignTok->astOperand1(),
mSettings->library,
true,
true))
continue;
if (assignTok->astOperand2()->varId() != var1->varId() && assignTok->astOperand2()->varId() != var2->varId() && !isSameExpression(mTokenizer->isCPP(), true, tok->astOperand2(), assignTok->astOperand2(), mSettings->library, true, true))
if (assignTok->astOperand2()->varId() != var1->varId() &&
assignTok->astOperand2()->varId() != var2->varId() &&
!isSameExpression(mTokenizer->isCPP(),
true,
tok->astOperand2(),
assignTok->astOperand2(),
mSettings->library,
true,
true))
continue;
differentDomain = true;
break;
Expand Down
12 changes: 9 additions & 3 deletions test/testother.cpp
Expand Up @@ -5667,7 +5667,9 @@ class TestOther : public TestFixture {
" use(j);\n"
" if (i == j) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n",
errout.str());

check("struct A { int x; int y; };"
"void use(int);\n"
Expand All @@ -5677,7 +5679,9 @@ class TestOther : public TestFixture {
" use(j);\n"
" if (i == a.x) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n",
errout.str());

check("struct A { int x; int y; };"
"void use(int);\n"
Expand All @@ -5687,7 +5691,9 @@ class TestOther : public TestFixture {
" use(i);\n"
" if (j == a.x) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n", errout.str());
ASSERT_EQUALS(
"[test.cpp:4] -> [test.cpp:3]: (style, inconclusive) Same expression used in consecutive assignments of 'i' and 'j'.\n",
errout.str());

// Issue #8612
check("struct P\n"
Expand Down

0 comments on commit 58e86ba

Please sign in to comment.