diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 498d15e4b..123fc0371 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -112,8 +112,6 @@ static bool isParameterChanged(const Token *partok) ftok = ftok ? ftok->previous() : nullptr; if (!(ftok && ftok->function())) return true; - if (ftok->function()->isConst()) - return false; const Variable *par = ftok->function()->getArgumentVar(argumentNumber); if (!par) return true; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 104baa6fb..4bf1c7e0a 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1403,6 +1403,16 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str()); + check("void foo(const int &i);\n" + "void bar(int i) {\n" + " if(i>5) {\n" + " foo(i);\n" + " if(i<5) {\n" + " }\n" + " }\n" + "}"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str()); + check("void foo(int i);\n" "void bar() {\n" " int i; i = func();\n" @@ -1414,6 +1424,15 @@ private: "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str()); + check("class C { void f(int &i) const; };\n" // #7028 - variable is changed by const method + "void foo(C c, int i) {\n" + " if (i==5) {\n" + " c.f(i);\n" + " if (i != 5) {}\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // see linux revision 1f80c0cc check("int generic_write_sync(int,int,int);\n" "\n"