Fix #11034 FN duplicateCondition with struct member (#4074)

* Fix #11034 FN duplicateCondition with struct member

* Update testcondition.cpp
This commit is contained in:
chrchr-github 2022-05-03 19:57:30 +02:00 committed by GitHub
parent d50823fd22
commit 509e42afd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -2399,7 +2399,7 @@ static bool isExpressionChangedAt(const F& getExprTok,
if (depth < 0)
return true;
if (tok->exprId() != exprid) {
if (globalvar && Token::Match(tok, "%name% ("))
if (globalvar && !tok->isKeyword() && Token::Match(tok, "%name% ("))
// TODO: Is global variable really changed by function call?
return true;
const bool pointer = astIsPointer(tok);

View File

@ -4806,6 +4806,17 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct S { int i; };\n"
"int f(const S& s) {\n"
" int a = 0, b = 0;\n"
" if (s.i == 0)\n"
" a = 1;\n"
" if (s.i == 0)\n"
" b = 1;\n"
" return a + b;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) The if condition is the same as the previous if condition\n", errout.str());
// do not crash
check("void assign(const MMA& other) {\n"
" if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\n"