Fixed #7028 (False positive: opposite conditions (const method modifies variable))

This commit is contained in:
Daniel Marjamäki 2017-07-10 23:12:45 +02:00
parent fb7230ce05
commit 814d2ae2a4
2 changed files with 19 additions and 2 deletions

View File

@ -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;

View File

@ -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"