diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 6e18f3aad..e06f9f495 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 63f1606e7..e685dd209 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -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"