Skip to content

Commit 509e42a

Browse files
Fix #11034 FN duplicateCondition with struct member (#4074)
* Fix #11034 FN duplicateCondition with struct member * Update testcondition.cpp
1 parent d50823f commit 509e42a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,7 @@ static bool isExpressionChangedAt(const F& getExprTok,
23992399
if (depth < 0)
24002400
return true;
24012401
if (tok->exprId() != exprid) {
2402-
if (globalvar && Token::Match(tok, "%name% ("))
2402+
if (globalvar && !tok->isKeyword() && Token::Match(tok, "%name% ("))
24032403
// TODO: Is global variable really changed by function call?
24042404
return true;
24052405
const bool pointer = astIsPointer(tok);

test/testcondition.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4806,6 +4806,17 @@ class TestCondition : public TestFixture {
48064806
"}\n");
48074807
ASSERT_EQUALS("", errout.str());
48084808

4809+
check("struct S { int i; };\n"
4810+
"int f(const S& s) {\n"
4811+
" int a = 0, b = 0;\n"
4812+
" if (s.i == 0)\n"
4813+
" a = 1;\n"
4814+
" if (s.i == 0)\n"
4815+
" b = 1;\n"
4816+
" return a + b;\n"
4817+
"}\n");
4818+
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) The if condition is the same as the previous if condition\n", errout.str());
4819+
48094820
// do not crash
48104821
check("void assign(const MMA& other) {\n"
48114822
" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\n"

0 commit comments

Comments
 (0)